本文整理汇总了PHP中Nette\DI\Container::getByType方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::getByType方法的具体用法?PHP Container::getByType怎么用?PHP Container::getByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Container
的用法示例。
在下文中一共展示了Container::getByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* @return \Nette\Security\User
*/
private function getUser()
{
if (!$this->user) {
$this->user = $this->container->getByType(User::class);
}
return $this->user;
}
示例2: createEntity
/** @inheritdoc */
public function createEntity($entityClass, $arg = null)
{
if ($factory = $this->container->getByType($this->resolveEntityFactory($entityClass), false)) {
return $factory->create($arg);
}
return new $entityClass($arg);
}
示例3: run
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
$httpRequest = $this->context->getByType('Nette\\Http\\IRequest');
if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $httpRequest->getUrl();
$url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['callback'])) {
throw new Application\BadRequestException("Parameter callback is missing.");
}
$params['presenter'] = $this;
$callback = new Nette\Callback($params['callback']);
$response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params));
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
if ($response[0] instanceof \SplFileInfo) {
$response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]);
} else {
$response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]);
}
}
if ($response instanceof Nette\Templating\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
示例4: doRequest
/**
* @param Request $request
* @return Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();
$_SERVER['REQUEST_METHOD'] = $method = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uri = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
if ($method === 'HEAD' || $method === 'GET') {
$_GET = $request->getParameters();
$_POST = [];
} else {
$_POST = $request->getParameters();
$_GET = [];
}
$httpRequest = $this->container->getByType(IRequest::class);
$httpResponse = $this->container->getByType(IResponse::class);
if (!$httpRequest instanceof HttpRequest || !$httpResponse instanceof HttpResponse) {
throw new Exception('Arachne\\Codeception\\DI\\CodeceptionExtension is not used or conflicts with another extension.');
}
$httpRequest->reset();
$httpResponse->reset();
try {
ob_start();
$this->container->getByType(Application::class)->run();
$content = ob_get_clean();
} catch (Exception $e) {
ob_end_clean();
throw $e;
}
$code = $httpResponse->getCode();
$headers = $httpResponse->getHeaders();
return new Response($content, $code, $headers);
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$login = $input->getArgument('login');
$password = $input->getArgument('password');
$this->container->getByType('App\\Model\\UserManager')->add($login, $password);
$output->writeln("User {$login} was added.");
}
示例6: createNew
public function createNew($arguments = array())
{
/** @var BaseFileEntity $entity */
$entity = parent::createNew($arguments);
$entity->setUser($this->container->getByType('Nette\\Security\\User'));
return $entity;
}
示例7: configure
public function configure(Template $template)
{
// translator
if (($translator = $this->container->getByType('Nette\\Localization\\ITranslator', FALSE)) !== NULL) {
$template->setTranslator($translator);
}
$template->registerHelperLoader(array($this->container->venne->helpers, "loader"));
}
示例8: __construct
/**
* BasePresenterTester constructor.
* @param string $presenterName - etc. 'Front:GoodsChange:Goods'
*/
public function __construct($presenterName)
{
$this->presenterName = $presenterName;
$this->container = (require __DIR__ . '/../../../../app/bootstrap.php');
$this->linkGenerator = $this->container->getByType('Nette\\Application\\LinkGenerator');
$this->presenterFactory = $this->container->getByType('Nette\\Application\\IPresenterFactory');
$this->authenticator = new Authenticator();
}
示例9: createFromContainer
public static function createFromContainer(Container $context)
{
/** @var EntityManager $em */
$em = $context->getByType(EntityManager::class);
/** @var Configuration $conf */
$conf = $context->getByType(Configuration::class);
return new self($em, $conf, $context->getParameters()['tempDir']);
}
示例10: create
public function create() : Broker
{
$tagToService = function (array $tags) {
return array_map(function (string $serviceName) {
return $this->container->getService($serviceName);
}, array_keys($tags));
};
$phpClassReflectionExtension = $this->container->getByType(PhpClassReflectionExtension::class);
return new Broker(array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::PROPERTIES_CLASS_REFLECTION_EXTENSION_TAG))), array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::METHODS_CLASS_REFLECTION_EXTENSION_TAG))), $tagToService($this->container->findByTag(self::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG)), $this->container->getByType(FunctionReflectionFactory::class));
}
示例11: getServices
/**
* @return array
*/
public function getServices()
{
if ($this->services) {
return $this->services;
}
$services = [];
foreach ($this->emails as $email) {
$services[$email] = $this->container->getByType($email);
}
return $this->services = $services;
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$db = $this->container->getByType('Nette\\Database\\Connection');
try {
$db->query(self::USERS_TABLE_DDL);
$db->query(self::PACKAGES_TABLE_DDL);
$output->writeln('App installed');
} catch (\PDOException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
示例13: getPanel
public function getPanel()
{
$app = $this->container->getByType('Nette\\Application\\Application');
$presenter = $app->getPresenter();
$link = '/sallyx-bridges-stream-wrappers-nette-presenters/redis';
if ($presenter !== NULL) {
$link = $presenter->link(':SallyxBridgesStreamWrappersNettePresenters:Redis:');
}
$jsScript = file_get_contents(__DIR__ . '/assets/main.js');
$jsScript = str_replace(array('%redisPresenterLink%', '%scheme%'), array($link, $this->scheme), $jsScript);
return '<h1>Redis stream wrapper ' . $this->scheme . '://</h1>' . '<div class="nette-inner tracy-inner">' . '<style type="text/css">' . file_get_contents(__DIR__ . '/assets/style.css') . '</style>' . '<div class="sallyx-streamWrappers-fileBrowser ' . $this->scheme . '"></div>' . '<script type="text/javascript">' . $jsScript . '</script>' . '</div>';
}
示例14: addUrlGenerators
/**
* @param Builder $hateoasBuilder
*/
private function addUrlGenerators(Builder &$hateoasBuilder)
{
if (!empty($this->config['urlGenerators'])) {
$hasDefault = false;
foreach ($this->config['urlGenerators'] as $name => $generator) {
if (is_numeric($name) && !$hasDefault) {
$name = null;
$hasDefault = true;
}
$hateoasBuilder->setUrlGenerator($name, $this->container->getByType($generator));
}
}
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('building package.json...');
$packages = explode(' ', $input->getArgument('packages'));
$builder = $this->container->getByType('App\\Model\\Builder');
$builder->build($packages, function ($type, $buffer) use($output) {
if ($type === Process::ERR) {
$output->writeln(sprintf('<error>%s</error>', $buffer));
} else {
$output->writeln(sprintf('<info>%s</info>', $buffer));
}
});
$output->writeln('built package.json');
}