当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::createInstance方法代码示例

本文整理汇总了PHP中Nette\DI\Container::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::createInstance方法的具体用法?PHP Container::createInstance怎么用?PHP Container::createInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\DI\Container的用法示例。


在下文中一共展示了Container::createInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createPresenter

 /**
  * Creates new presenter instance.
  *
  * @param  string presenter class name
  * @return Application\IPresenter
  */
 public function createPresenter($class)
 {
     $callInjects = $this->alwaysCallInjects;
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (count($services)) {
         $presenter = $this->container->createService($services[0]);
         $callInjects = FALSE;
     } elseif (count($services = $this->container->findByType($class)) === 1) {
         $presenter = $this->container->createService($services[0]);
     } else {
         $presenter = $this->container->createInstance($class);
         $callInjects = TRUE;
     }
     if (!$presenter instanceof Application\IPresenter) {
         throw new UnexpectedValueException("Unable to create create presenter, returned value is not Nette\\Application\\IPresenter type.");
     }
     if ($callInjects) {
         $this->container->callInjects($presenter);
     }
     if ($presenter instanceof Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->invalidLinkMode;
     }
     return $presenter;
 }
开发者ID:librette,项目名称:presenter-factory,代码行数:32,代码来源:PresenterObjectFactory.php

示例2: __construct

 public function __construct(Container $context)
 {
     parent::__construct();
     $secured = NULL;
     if ($context->getParameters()['tls']) {
         Route::$defaultFlags |= Route::SECURED;
         $secured = Route::SECURED;
     }
     $this[] = new StaticRouter(['Homepage:default' => 'index.php'], StaticRouter::ONE_WAY | $secured);
     $this[] = new StaticRouter(['Homepage:default' => '', 'Homepage:marathon' => 'maraton', 'Homepage:preklad' => 'preklad', 'Profile:default' => 'profil', 'Auth:in' => 'prihlaseni', 'Auth:out' => 'odhlaseni', 'Auth:registration' => 'registrace', 'Auth:resetPassword' => 'heslo', 'Text:about' => 'o-skole', 'Text:team' => 'o-skole/tym', 'Subjects:default' => 'predmety', 'File:opensearch' => 'opensearch.xml', 'File:robots' => 'robots.txt', 'Sitemap:default' => 'sitemap.xml', 'Text:tos' => 'podminky', 'Text:privacy' => 'soukromi'], $secured);
     $this[] = new Route('vyhledavani/?hledat=<query>', 'Search:results');
     $this[] = new Route('vyhledavani/cviceni', 'Search:blueprints');
     $this[] = new Route('schema/[<action \\D+>/]<schemaId \\d+>[-<slug>]', 'Schema:default');
     $this[] = new Route('blok/[<action \\D+>/][<schemaId \\d+>/]<blockId \\d+>[-<slug>]', 'Block:default');
     $this[] = new Route('video/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<videoId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Video:default');
     $this[] = new Route('cviceni/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blueprintId \\d+>[-<slug>]', 'Blueprint:default');
     $this[] = new Route('tabule/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blackboardId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Blackboard:default');
     // old links
     $this[] = new Route('video/<youtubeId>', 'Video:youtube');
     $this[] = new Redirect('dobrovolnici', 'https://wiki.khanovaskola.cz/doku.php?id=dobrovolnici');
     $this[] = new Redirect('dobrovolnici/preklad', 'https://wiki.khanovaskola.cz/doku.php?id=jaknato');
     $this[] = new Redirect('dobrovolnici/pravidla-prekladu', 'https://wiki.khanovaskola.cz/doku.php?id=pravidla');
     $this[] = new Redirect('o-skole/projekty', 'https://wiki.khanovaskola.cz/doku.php?id=start');
     $this[] = new Redirect('kontakt', 'https://wiki.khanovaskola.cz/doku.php?id=tym');
     $this[] = $context->createInstance(Routers\OldVideo::class);
     $this[] = $context->createInstance(Routers\OldCategory::class);
     $this[] = $context->createInstance(Routers\OldBlog::class);
     $this[] = new Route('<presenter>/<action \\D+>[/<id>]', 'Homepage:default');
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:29,代码来源:Router.php

示例3: createPresenter

 /**
  * Create new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $presenter = $this->container->createInstance($this->getPresenterClass($name));
     $this->container->callInjects($presenter);
     if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
     }
     return $presenter;
 }
开发者ID:radeksimko,项目名称:nette,代码行数:14,代码来源:PresenterFactory.php

示例4: createPresenter

 /**
  * Create new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $presenter = $this->container->createInstance($this->getPresenterClass($name));
     foreach (array_reverse(get_class_methods($presenter)) as $method) {
         if (substr($method, 0, 6) === 'inject') {
             $this->container->callMethod(array($presenter, $method));
         }
     }
     if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
     }
     return $presenter;
 }
开发者ID:JanVoracek,项目名称:nette,代码行数:18,代码来源:PresenterFactory.php

示例5: createPresenter

 /**
  * Creates new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $class = $this->getPresenterClass($name);
     if (count($services = $this->container->findByType($class)) === 1) {
         $presenter = $this->container->createService($services[0]);
     } else {
         $presenter = $this->container->createInstance($class);
     }
     $this->container->callInjects($presenter);
     if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
     }
     return $presenter;
 }
开发者ID:pdostal,项目名称:nette-blog,代码行数:19,代码来源:PresenterFactory.php

示例6: uninstall

 /**
  * Uninstallation of package.
  *
  * @param \Venne\Packages\IPackage $package
  */
 public function uninstall(IPackage $package)
 {
     if ($this->getStatus($package) === self::STATUS_UNINSTALLED) {
         throw new InvalidArgumentException(sprintf('Package \'%s\' is already uninstalled', $package->getName()));
     }
     $dependencyResolver = $this->createSolver();
     $dependencyResolver->testUninstall($package);
     foreach ($package->getInstallers() as $class) {
         try {
             $installer = $this->context->createInstance($class);
             $installer->uninstall($package);
         } catch (Exception $e) {
             foreach ($package->getInstallers() as $class2) {
                 if ($class === $class2) {
                     break;
                 }
                 $installer = $this->context->createInstance($class2);
                 $installer->install($package);
             }
             throw new InvalidStateException($e->getMessage());
         }
     }
     $this->setStatus($package, self::STATUS_UNINSTALLED);
     $this->reloadInfo();
     $this->onUninstall($this, $package);
 }
开发者ID:venne,项目名称:packages,代码行数:31,代码来源:PackageManager.php

示例7: __invoke

 /**
  * @return Nette\Application\IPresenter
  */
 public function __invoke($class)
 {
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Nette\Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->touchToRefresh) {
             touch($this->touchToRefresh);
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         if ($presenter instanceof Nette\Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
             $presenter->invalidLinkMode = $this->invalidLinkMode;
         }
         return $presenter;
     }
     return $this->container->createService($services[0]);
 }
开发者ID:Richmond77,项目名称:learning-nette,代码行数:21,代码来源:PresenterFactoryCallback.php

示例8: indexEntities

 public function indexEntities(ClassMetadata $searchMeta)
 {
     foreach ($this->searchManager->getMetadataFactory()->getAllMetadata() as $otherMeta) {
         if ($searchMeta->className === $otherMeta->className) {
             continue;
         }
         if (is_subclass_of($searchMeta->className, $otherMeta->className)) {
             $this->onChildSkipped($this, $searchMeta, $otherMeta);
             return;
         }
     }
     if ($searchMeta->riverImplementation) {
         $river = $this->serviceLocator->getByType($searchMeta->riverImplementation);
     } else {
         /** @var River\DefaultEntityRiver $river */
         $river = $this->serviceLocator->createInstance('Kdyby\\DoctrineSearch\\River\\DefaultEntityRiver');
     }
     if (!$river instanceof EntityRiver) {
         throw new UnexpectedValueException('The river must implement Doctrine\\Search\\EntityRiver.');
     }
     if (property_exists($river, 'onIndexStart')) {
         $river->onIndexStart[] = function (EntityRiver $river, $paginator, ORMMetadata $class) {
             $this->onIndexStart($this, $paginator, $river, $class);
         };
     }
     if (property_exists($river, 'onItemsIndexed')) {
         $river->onItemsIndexed[] = function ($self, $entities) {
             $this->onItemsIndexed($this, $entities);
         };
     }
     if (property_exists($river, 'onIndexStats')) {
         $river->onIndexStats[] = function ($self, ORMMetadata $class, $timeToIndex, $timeToRead) {
             $this->onIndexStats($this, $class, $timeToIndex, $timeToRead);
         };
     }
     // disable logger
     $config = $this->entityManager->getConfiguration();
     $oldLogger = $config->getSQLLogger();
     $config->setSQLLogger(NULL);
     $river->transfuse($searchMeta);
     $config->setSQLLogger($oldLogger);
 }
开发者ID:rohlikcz,项目名称:DoctrineSearch,代码行数:42,代码来源:EntityPiper.php

示例9: createRow

 /**
  * @param ActiveRow $activeRow
  * @param $tableName
  * @throws InvalidStateException
  * @return HyperRow
  */
 public function createRow(ActiveRow $activeRow, $tableName)
 {
     $className = Helpers::substituteClassWildcard($this->rowMapping, $tableName);
     $baseClass = HyperRow::class;
     if (!class_exists($className) || !is_subclass_of($className, $baseClass)) {
         throw new InvalidStateException("HyperRow class {$className} does not exist or does not extend {$baseClass}.");
     }
     $names = $this->container->findByType($className);
     if (count($names) > 1) {
         throw new InvalidStateException("Multiple services of type {$className} found: " . implode(', ', $names) . '.');
     } elseif (count($names) == 0) {
         $inst = $this->container->createInstance($className);
     } else {
         $name = array_shift($names);
         $inst = $this->container->createService($name);
     }
     /** @var HyperRow $inst */
     $inst->setFactory($this);
     $inst->setActiveRow($activeRow);
     return $inst;
 }
开发者ID:filsedla,项目名称:hyperrow,代码行数:27,代码来源:Factory.php

示例10: createPresenter

 /**
  * Creates new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $class = $this->getPresenterClass($name);
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->autoRebuild) {
             $rc = new \ReflectionClass($this->container);
             @unlink($rc->getFileName());
             // @ file may not exists
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
             $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
         }
         return $presenter;
     }
     return $this->container->createService($services[0]);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:26,代码来源:PresenterFactory.php

示例11: invoke

 public function invoke(Container $container, Generator $faker, RepositoryContainer $orm)
 {
     $this->faker = $faker;
     $container->addService('subtitles', $container->createInstance(FakeSubtitles::class));
     $users = $this->create(50, User::class, $orm->users, [$this, 'fillUser']);
     $videos = $this->create(20, Video::class, $orm->contents, [$this, 'fillVideo']);
     $this->createComments(10, $videos, $users, $orm->contents);
     $subjects = $this->create(7, Subject::class, $orm->subjects, [$this, 'fillSubject']);
     $this->createSchemasAndBlocks($orm, $subjects, $videos);
     $this->out->writeln('flushing');
     $orm->flush();
     $this->out->writeln('<info>done</info>');
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:13,代码来源:Fake.php

示例12: upgrade

 /**
  * Upgrade module.
  *
  * @param IModule $module
  * @param bool $withDependencies
  */
 public function upgrade(IModule $module, $force = FALSE)
 {
     if ($this->getStatus($module) !== self::STATUS_INSTALLED) {
         throw new InvalidArgumentException("Module '{$module->getName()}' must be installed");
     }
     $modules = $this->loadModuleConfig();
     if ($module->getVersion() === $modules['modules'][$module->getName()][self::MODULE_VERSION]) {
         throw new InvalidArgumentException("Module '{$module->getName()}' is current");
     }
     if (!$force) {
         $dependencyResolver = $this->createSolver();
         $dependencyResolver->testUpgrade($module);
     }
     foreach ($module->getInstallers() as $class) {
         try {
             /** @var $installer IInstaller */
             $installer = $this->context->createInstance($class);
             $installer->upgrade($module, $this->modules[$module->getName()][self::MODULE_VERSION], $module->getVersion());
         } catch (Exception $e) {
             foreach ($module->getInstallers() as $class2) {
                 if ($class === $class2) {
                     break;
                 }
                 $installer = $this->context->createInstance($class2);
                 $installer->downgrade($module, $module->getVersion(), $this->modules[$module->getName()][self::MODULE_VERSION]);
             }
             throw $e;
         }
     }
     $modules['modules'][$module->getName()] = array(self::MODULE_STATUS => self::STATUS_INSTALLED, self::MODULE_ACTION => self::ACTION_NONE, self::MODULE_CLASS => $module->getClassName(), self::MODULE_VERSION => $module->getVersion(), self::MODULE_PATH => $this->getFormattedPath($module->getPath()), self::MODULE_AUTOLOAD => $this->getFormattedPath($module->getAutoload()), self::MODULE_REQUIRE => $module->getRequire());
     $this->saveModuleConfig($modules);
     $this->reloadInfo();
     $this->reloadSystemContainer();
     $this->cacheManager->clean();
     $this->onUpgrade($this, $module);
 }
开发者ID:svobodni,项目名称:web,代码行数:42,代码来源:ModuleManager.php

示例13: createEntity

 /**
  * @param string $entityClass
  * @param Row|null $arg
  * @return Entity
  */
 public function createEntity($entityClass, $arg = null)
 {
     return $this->container->createInstance($entityClass, !is_array($arg) ? array($arg) : $arg);
 }
开发者ID:echo511,项目名称:graphadmin,代码行数:9,代码来源:EntityFactory.php

示例14: create

 /** Vytvoření komponenty
  * 
  * @param string $class
  * @param array $args
  * @return new instance of given class
  */
 public function create($class, array $args = array())
 {
     return $this->container->createInstance($class, $args);
 }
开发者ID:vipercz,项目名称:sandbox,代码行数:10,代码来源:ComponentFactory.php


注:本文中的Nette\DI\Container::createInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。