src/AppBundle/Command/BaseCommand.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Command;
use Biz\Role\Util\PermissionBuilder;
use Topxia\Service\Common\ServiceKernel;
use Biz\User\CurrentUser;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
abstract class BaseCommand extends ContainerAwareCommand
{
protected function getServiceKernel()
{
return ServiceKernel::instance();
}
protected function initServiceKernel()
{
$_SERVER['HTTP_HOST'] = '127.0.0.1';
$serviceKernel = ServiceKernel::create('dev', false);
$serviceKernel->setParameterBag($this->getContainer()->getParameterBag());
$serviceKernel->setBiz($this->getBiz());
$currentUser = new CurrentUser();
$systemUser = $this->getUserService()->getUserByType('system');
$systemUser['currentIp'] = '127.0.0.1';
$currentUser->fromArray($systemUser);
$currentUser->setPermissions(PermissionBuilder::instance()->getPermissionsByRoles($currentUser->getRoles()));
$serviceKernel->setCurrentUser($currentUser);
}
protected function getBiz()
{
return $this->getContainer()->get('biz');
}
/**
* @return \Biz\User\Service\UserService
*/
protected function getUserService()
{
return $this->createService('User:UserService');
}
protected function createService($alias)
{
$biz = $this->getBiz();
return $biz->service($alias);
}
protected function trans($message, $arguments = array(), $domain = null, $locale = null)
{
$translator = $this->getContainer()->get('translator');
return $translator->trans($message, $arguments, $domain, $locale); // works fine! :)
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。