突变是同步的,这严重阻碍了我......有没有办法捕捉突变的完成?
Paul Wall's questions
我正在学习TS,我在vuex中遇到过这样的构造-ActionObject<S, R>
我是否正确理解 S 和 R 只是泛型类型?文档严格使用非常令人困惑<T>
。或者我可以在这种情况下使用任何大写字母吗?
他们到处都写说存储库不应该返回 DTO ...那该怎么办?返回对象还是数组?但是你可以在任何地方添加任何东西。如果我更改接收到的数据,那么存储库会立即将其提供给他们,我什至不会注意到它。实际上,DTO 保证我会以单一的形式接收对象,并且在将来我会看到我接受什么以及我给予什么。
如果我突然决定替换它们,我将存储库纯粹用于 CRUD 操作,以便为雄辩的模型提供一层。
告诉我在我的情况下最好的做法是什么?
有这个控制器:
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
class AuthController extends Controller
{
/**
* Handle the incoming request.
*
* @return Response
*/
public function __invoke(Request $request): Response
{
return response(auth()->user());
}
}
这就是它所拥有的一切。解释为什么这样做,为什么它比调用同一用户的单独函数更好?为什么根本需要调用?它是如何使用的?
在 wordpress 的 off-config docker 中有这个项目:
RUN set -ex; \
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
tar -xzf wordpress.tar.gz -C /usr/src/; \
rm wordpress.tar.gz; \
chown -R www-data:www-data /usr/src/wordpress
有人可以向我解释为什么他将 wordpress 下载到该文件夹吗?它是干什么用的?
该策略具有以下代码:
public function view(User $user, User $model): bool
{
return ($user->id == $model->id || in_array('read_users', $user->access));
}
第一个模型是登录用户,第二个模型是查看用户。没有任何效果,因为第二种模式不会进入政治领域。
一切从路由开始:
Route::get('/{id}', [UserController::class, 'show'])->name('users.show')->middleware('can:view,' . User::class);
控制器中不使用模型绑定,因为使用数据库的逻辑放置在存储库中。
在 Windows 上,我正在尝试处理 k8s。有一个启用了 K8s 的 Docker 桌面。但是所有的教程都使用ghost minikube...
据我了解,Minikube 是一个带有仪表板 + 分别为 kubeadm、kubectl 等的 docker 镜像。
但是我已经有 Docker Desktop 的 kubectl 了……我只是一头雾水,解释一下我是否需要 minikube,它到底是做什么的(据我了解,这只是 k8s 的工作环境),它有什么不同来自docker桌面中的k8s?
我正在尝试学习如何应用设计模式,但到目前为止一切都非常糟糕,我写了一小段代码 - https://github.com/sergeevpasha/patterntest 告诉我在我没有推理的地方要解决什么正确地
在这里写所有代码很多,但部分写是没有意义的。请不要删除帖子。
试图遵循设计模式并在中途陷入困境。任务是这样的,有 3 种发送消息的方式(邮件、短信、电报),邮件中还有 3 个选项(因为程序中有 3 个不同的工作模块,然后是信件的传入数据类型是不同的,就像字母模板本身一样)。
我设法用这样的工厂方法完成了第一部分:
信使界面
<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Email\Interfaces;
interface MessengerInterface
{
public function send();
}
邮件信使
<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Email;
use App\Http\Controllers\Email\Interfaces\MessengerInterface;
class MailMessenger implements MessengerInterface
{
public function __construct(
String $fromAddress,
String $toAddress,
Boolean $inbox,
String $messageText,
String $messageHtml,
)
{
}
public function send()
{
return '';
}
}
信使工厂
<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Email\Interfaces;
interface MessengerFactory
{
public function createMessenger() : MessengerInterface;
}
信使工厂
<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Email;
use App\Http\Controllers\Email\MailMessenger;
use App\Http\Controllers\Email\Interfaces\MessengerFactory;
class MailMessengerFactory implements MessengerFactory
{
public function createMessenger() : MessengerInterface
{
return new MailMessenger;
}
}
但是如何通过邮件本身内部的模板来分割 - xs. 更准确地说,xs 如何使用设计模式来做到这一点。鉴于我仍然不明白为什么这么简单的事情,使用模板,我需要多达 2 个类,尽管对我来说,1 就足够了
一切似乎都在工作。告诉我如何修复代码,在哪里重构?
<?php
declare(strict_types = 1);
namespace Dummy;
use Illuminate\Database\Seeder;
use Database\Seeds\SequenceTrait;
use App\Models\ColdModule\ColdCustomer;
use App\Models\Tag;
class TagSeeder extends Seeder
{
use SequenceTrait;
protected $taggable = [];
/**
* Prepare all taggable classes
*
* @return void
*/
public function __construct()
{
$this->taggable = [
new ColdCustomer,
];
}
/**
* Auto generated seed file.
*
* @return void
*/
public function run(): void
{
$table = new Tag;
$tableName = $table->getTable();
\DB::table($tableName)->delete();
for ($i = 0; $i < 50; $i++) {
factory(Tag::class)->create($this->getTaggable());
}
$this->setSequence($tableName);
}
/**
* Return a randomized Model taggables.
*
* @return array
*/
protected function getTaggable(): array
{
$rand = array_rand($this->taggable);
$model = $this->taggable[$rand];
$ids = $model->pluck('id')->toArray();
$type = get_class($model);
return [
'taggable_id' => array_rand($ids),
'taggable_type' => $type,
];
}
}
有两种略有不同的配置。Dockerfile 中的第一个具有 COPY 复制整个项目文件夹,然后在 docker-compose 中执行以下操作:
services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
- .:/app:cached
- home-dir:/home/user:cached
ports:
- '4001:8080'
depends_on:
- postgres
networks:
- app-network
也就是说,您可以看到 :ro 和 :cached。这与我们不复制 dockerfile 并且只在 docker-compose 中写入路径(例如 - home-dir:/home/user)有什么不同?
我读了一本书,慢慢地尝试应用知识。我在视图迁移中创建了一个表,以便稍后引用它,而不是使用 join/groupBy/OrderBy 进行一堆查询。
这是正常的做法吗?我可以根据正常创建的字段对这个虚拟表进行排序吗?我可以执行任何更新/删除操作吗?
我看到有人做双RK,但我不明白为什么。与平庸的 id 创建相比有什么优势,这样更容易使用。
这种做法一般有多普遍,有什么好处?
有一个没有框架的空项目,但是有一个下载的symfony/router
. 这是路由本身:
<?php
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
$routes = new RouteCollection();
$routes->add('contacts_all', new Route('/api/v1/contacts', ['_controller' => 'Controllers\ContactController::index']));
$routes->add('contact_show', new Route('/api/v1/contacts/{contact}', ['_controller' => 'Controllers\ContactController::show']));
$routes->add('contact_delete', new Route('/api/v1/contacts/{contact}', ['_controller' => 'Controllers\ContactController::delete'], [], [], '', ['DELETE']));
$routes->add('api_v1', new Route('/api/{any}', ['_controller' => 'Controllers\AppController::errorApi'], ['any' => '.*']));
$routes->add('index', new Route('/', ['_controller' => 'Controllers\AppController::index']));
$routes->add('any', new Route('/{any}', ['_controller' => 'Controllers\AppController::index'], ['any' => '.*']));
return $routes;
DELETE 方法不起作用,可能是什么问题?
PS:总的来说,我有一个解决方案,但我不喜欢它:
<?php
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
$routes = new RouteCollection();
switch($_SERVER['REQUEST_METHOD'])
{
case 'GET':
$routes->add('contacts_all', new Route('/api/v1/contacts', ['_controller' => 'Controllers\ContactController::index']));
$routes->add('contact_show', new Route('/api/v1/contacts/{contact}', ['_controller' => 'Controllers\ContactController::show']));
$routes->add('api_v1', new Route('/api/{any}', ['_controller' => 'Controllers\AppController::errorApi'], ['any' => '.*']));
$routes->add('index', new Route('/', ['_controller' => 'Controllers\AppController::index']));
$routes->add('any', new Route('/{any}', ['_controller' => 'Controllers\AppController::index'], ['any' => '.*']));
break;
case 'DELETE':
$routes->add('contact_delete', new Route('/api/v1/contacts/{contact}', ['_controller' => 'Controllers\ContactController::delete']));
break;
}
return $routes;
我想用纯 php 做路由,但后来魔鬼拉我安装 symfony/router,现在我觉得自己像个白痴。我在连接课程时遇到问题,我按照说明进行操作并得到:
Fatal error: Uncaught Error: Class 'AppController' not found in /home/vagrant/html/phb/vendor/symfony/http-kernel/Controller/ControllerResolver.php on line 151
这是他喝的:
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpKernel;
use App\Http\Controller\AppController;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/../.env');
$request = Request::createFromGlobals();
$routes = new RouteCollection();
$routes->add('main', new Route('/',
array(
'_controller' => 'AppController::index',
)
)
);
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($routes, $context);
$resolver = new HttpKernel\Controller\ControllerResolver();
try {
$request->attributes->add($matcher->match($request->getPathInfo()));
$controller = $resolver->getController($request);
$arguments = $resolver->getArguments($request, $controller);
$response = call_user_func_array($controller, $arguments);
} catch (ResourceNotFoundException $e) {
$response = new Response('Not found', 404);
} catch (Exception $e) {
$response = new Response('Error occurred', 500);
}
$response->send();
我做的愚蠢在哪里?
我注册了一个域,一旦我设置了它,我就会在日志中看到每分钟来自不同 IP 的不同引荐,他们都会在网站上敲击某种脚本。以下是日志中的错误示例:
2019/04/25 11:54:52 [error] 18771#18771: *968 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 83.97.110.197, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=1b10b02d377e8c936434a509e7747005&r=&h=www.google.com&rand=1556193290958&_=1556193290480 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://www.google.com/"
2019/04/25 11:54:59 [error] 18771#18771: *968 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 83.97.110.197, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=1b10b02d377e8c936434a509e7747005&r=https%3A%2F%2Fwww.google.com%2F&h=www.youtube.com&rand=1556193298293&_=1556193295292 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://www.youtube.com/"
2019/04/25 11:55:51 [error] 18771#18771: *975 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 78.85.175.231, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=687b15e9a15b91aa8e54d6bc0d982283&r=&h=e.mail.ru&rand=1556193355156&_=1556193343577 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://e.mail.ru/thread/0:15559335500000000132:500000/"
2019/04/25 11:56:17 [error] 18771#18771: *977 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 188.235.10.69, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=b75f3a00d7c3ac8ba10820b87473fe92&r=&h=yandex.ru&rand=1556189834748&_=1556189832912 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://yandex.ru/"
2019/04/25 11:56:18 [error] 18771#18771: *977 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 188.235.10.69, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=b75f3a00d7c3ac8ba10820b87473fe92&r=https%3A%2F%2Fyandex.ru%2F&h=mail.yandex.ru&rand=1556189836082&_=1556189835338 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://mail.yandex.ru/"
2019/04/25 11:56:42 [error] 18771#18771: *981 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 78.85.175.231, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=687b15e9a15b91aa8e54d6bc0d982283&r=https%3A%2F%2Fe.mail.ru%2Fthread%2F0%3A15559335500000000132%3A500000%2F&h=e.mail.ru&rand=1556193406272&_=1556193393206 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://e.mail.ru/thread/0:15559335500000000132:500000/"
2019/04/25 11:56:52 [error] 18771#18771: *983 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 78.85.175.231, server: xerxes.ru, request: "GET /getscripts2?&b=c98aecda097f2a52964c89167f60f61d&publisher_id=81c675d4733cd5376ff43d2bc7005e0a&uid=687b15e9a15b91aa8e54d6bc0d982283&r=https%3A%2F%2Fe.mail.ru%2Fthread%2F0%3A15559335500000000132%3A500000%2F&h=e.mail.ru&rand=1556193416634&_=1556193410996 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "xerxes.ru", referrer: "https://e.mail.ru/thread/0:15559335500000000132:500000/"
它是什么以及如何处理它,我第一次看到这个。
UPD:过去 3 天的 40mb 日志...
c认证不适caching_sha2_password
用于php 7.3
mysql8。他们在互联网上写道,这个版本没有这样的问题。但它是,以及做什么 - 目前尚不清楚。我不想押注每个人都提供的旧身份验证方法。帮助找到解决方案。错误代码本身:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
我在Win10上安装了docker和docker-compose,用nginx、php、mysql做了三个容器。一切正常,但尚不清楚如何。
比如我通过docker exec -it
c的nginx容器,其实我那里有ubuntu,我可以放任何我想要的东西……它是从哪里来的,为什么下载的时候没有。它是如何发生的
同一个域上有很多站点。目前,一切都是手工编写的——每个站点都在其配置中。是否可以根据/var/www/html/sitename
. 如果可能的话,是否有任何示例或说明,因为我在任何地方都找不到
我正在尝试使用data.ru的vue-suggestions插件,一切都已定位,插入,但我无法弄清楚如何将值从那里分配给测试变量。如果 this.test 插入到 onSelect() 方法中,那么它不明白它是什么。箭头功能在那里不起作用。如何将接收到的值分配给测试变量?
export default {
data() {
return {
test: {},
city: '',
coordinates: {
latitude: '',
longitude: ''
},
suggestionOptions: {
// @see https://confluence.hflabs.ru/pages/viewpage.action?pageId=207454318
token: 'rtjsrtjsrj54u4j',
type: "ADDRESS",
scrollOnFocus: false,
triggerSelectOnBlur: false,
triggerSelectOnEnter: true,
addon: 'none',
// @see https://confluence.hflabs.ru/pages/viewpage.action?pageId=207454320
onSelect(suggestion) {
console.log(suggestion);
}
},
}
}
}