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


PHP Container::factory方法代码示例

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


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

示例1: boot

 /**
  * @param Application|Container $app
  *
  */
 public function boot($app)
 {
     // only if enabled
     if ($app['config']['view.blade.enabled']) {
         // default blade context to simplify creating a new Blade|BladeView object.
         $app['blade.context'] = function ($app) {
             return new BladeConfigurationSet(['engine' => $app['blade.engine'], 'events' => $app['illuminate.events'], 'factory' => $app['blade.factory'], 'finder' => $app['view.finder'], 'global' => $app['global.scope'], 'paths' => $app['paths'], 'settings' => $app['blade.settings']]);
         };
         $this->container->add([BladeConfigurationSet::class, BladeViewConfigurationInterface::class], function () use($app) {
             return $app['blade.context'];
         });
         $this->container->add([BladeView::class, 'BladeView'], function () use($app) {
             return new BladeView($this->app['blade.context']);
         });
         // for dependency injection. ie: DI::make(BladeView::class)
         $app[BladeViewConfigurationInterface::class] = function ($app) {
             return $app['blade.context'];
         };
         $app['blade'] = $app->factory(function () {
             return new Blade($this->app['blade.context']);
         });
         $app['blade.view'] = $app->factory(function () {
             return new BladeView($this->app['blade.context']);
         });
     }
 }
开发者ID:formula9,项目名称:framework,代码行数:30,代码来源:BladeViewServiceProvider.php

示例2: registerModules

 /**
  * Registers all modules
  * @return void
  */
 public function registerModules()
 {
     $container = $this;
     $this->container['twig_loader'] = function ($c) use($container) {
         return $container->registerTwigLoader($c);
     };
     $this->container['twig'] = function ($c) use($container) {
         return $container->registerTwigEnviroment($c);
     };
     $this->container['admin_router'] = function ($c) use($container) {
         return $container->registerAdminRouter($c);
     };
     $this->container['router'] = function ($c) use($container) {
         return $container->registerPublicRouter($c);
     };
     $this->container['list_table'] = $this->container->factory(function ($c) use($container) {
         return $container->registerListTable($c);
     });
     $this->container['ajax'] = $this->container->factory(function ($c) use($container) {
         return $container->registerAjax($c);
     });
     $this->container['post_type'] = $this->container->factory(function ($c) use($container) {
         return $container->registerPostType($c);
     });
     $this->container['request'] = $this->container->factory(function ($c) use($container) {
         return $container->registerRequest($c);
     });
 }
开发者ID:Anunatak,项目名称:framework,代码行数:32,代码来源:Container.php

示例3: register

 public function register(Container $app)
 {
     $app['ramlToSilex.initializer'] = $app->protect(function () use($app) {
         if (!is_readable($ramlFile = $app['ramlToSilex.raml_file'])) {
             throw new \RuntimeException("API config file is not readable");
         }
         $configFile = json_decode(file_get_contents($app['ramlToSilex.config_file']));
         $app['ramlToSilex.apiDefinition'] = (new Parser())->parse($ramlFile, false);
         $app['ramlToSilex.routes'] = $app['ramlToSilex.apiDefinition']->getResourcesAsUri()->getRoutes();
         if (property_exists($configFile, 'routeAccess')) {
             $app['ramlToSilex.routeAccess'] = $configFile->routeAccess;
         }
         if (property_exists($configFile, 'controllers')) {
             $app['ramlToSilex.customControllerMapping'] = $configFile->controllers;
         }
         $app['ramlToSilex.restController'] = $app->factory(function () use($app) {
             return new RestController($app);
         });
         $app['ramlToSilex.routeBuilder'] = $app->factory(function () {
             return new RouteBuilder();
         });
     });
     $app['ramlToSilex.builder'] = function () use($app) {
         $app['ramlToSilex.initializer']();
         $controllers = $app['ramlToSilex.routeBuilder']->build($app, 'ramlToSilex.restController');
         $app['controllers']->mount('', $controllers);
     };
 }
开发者ID:damack,项目名称:ramltosilex,代码行数:28,代码来源:RamlToSilexServiceProvider.php

示例4: register

 public function register(Container $app)
 {
     $app['di.container'] = function () use($app) {
         return new ContainerBuilder(new ParameterBag($app['di.parameters']));
     };
     $app['di.loader.yml'] = $app->factory(function (Container $app) {
         return new YamlFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.xml'] = $app->factory(function (Container $app) {
         return new XmlFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.ini'] = $app->factory(function (Container $app) {
         return new IniFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app['di.container'], new FileLocator());
     });
     $app['di.resolver'] = function () use($app) {
         return new LoaderResolver([$app['di.loader.yml'], $app['di.loader.xml'], $app['di.loader.php'], $app['di.loader.ini'], $app['di.loader.directory']]);
     };
     $app['di.loader'] = function () use($app) {
         return new DelegatingLoader($app['di.resolver']);
     };
     $app['di.parameters'] = [];
 }
开发者ID:sergiors,项目名称:dependency-injection-service-provider,代码行数:28,代码来源:DependencyInjectionServiceProvider.php

示例5: addServiceToContainer

 private function addServiceToContainer(ServiceDefinition $definition)
 {
     $factory = $this->createFactory($definition);
     if (!$definition->isSingleton()) {
         $factory = $this->container->factory($factory);
     }
     $this->container[$definition->getName()] = $factory;
 }
开发者ID:tomphp,项目名称:config-service-provider,代码行数:8,代码来源:PimpleContainerAdapter.php

示例6: register

 /**
  * Register providers
  *
  * @access public
  * @param  \Pimple\Container $container
  * @return \Pimple\Container
  */
 public function register(Container $container)
 {
     $container['commentEventJob'] = $container->factory(function ($c) {
         return new CommentEventJob($c);
     });
     $container['subtaskEventJob'] = $container->factory(function ($c) {
         return new SubtaskEventJob($c);
     });
     $container['taskEventJob'] = $container->factory(function ($c) {
         return new TaskEventJob($c);
     });
     $container['taskFileEventJob'] = $container->factory(function ($c) {
         return new TaskFileEventJob($c);
     });
     $container['taskLinkEventJob'] = $container->factory(function ($c) {
         return new TaskLinkEventJob($c);
     });
     $container['projectFileEventJob'] = $container->factory(function ($c) {
         return new ProjectFileEventJob($c);
     });
     $container['notificationJob'] = $container->factory(function ($c) {
         return new NotificationJob($c);
     });
     $container['projectMetricJob'] = $container->factory(function ($c) {
         return new ProjectMetricJob($c);
     });
     $container['userMentionJob'] = $container->factory(function ($c) {
         return new UserMentionJob($c);
     });
     return $container;
 }
开发者ID:phecho,项目名称:kanboard,代码行数:38,代码来源:JobProvider.php

示例7: register

 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app['uploader.controller_class'] = 'Pulsar\\Uploader\\Controller\\UploaderController';
     $app['uploader.options'] = [];
     $app['uploader.default_options'] = ['storage' => 'filesystem', 'route_prefix' => '', 'namer' => 'uniqid'];
     $app['uploader.storage.filesystem'] = $app->factory(function () {
         return new FilesystemStorage();
     });
     $app['uploader.namer.uniqid'] = $app->factory(function () {
         return new UniqidNamer();
     });
 }
开发者ID:sfblaauw,项目名称:pulsar-uploader,代码行数:15,代码来源:UploaderServiceProvider.php

示例8: set

 /**
  * @param string $key
  * @param mixed $val
  * @param string $type (optional)
  */
 static function set($key, $val, $type = null)
 {
     if (!static::$pimple) {
         throw new \LogicException('\\Pimple\\Container not set, call init() or setPimple() before using set().');
     }
     if ('factory' == $type) {
         static::$pimple[$key] = static::$pimple->factory($val);
     } elseif ('protect' == $type) {
         static::$pimple[$key] = static::$pimple->protect($val);
     } else {
         static::$pimple[$key] = $val;
     }
 }
开发者ID:cumi,项目名称:pressbooks,代码行数:18,代码来源:class-pb-container.php

示例9: register

 /**
  * @param Container $app
  */
 public function register(Container $app)
 {
     $app['config.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         $filenames = (array) $app['config.filenames'];
         foreach ($filenames as $path) {
             $path = $app['config.replacements.resolver']($path);
             $app['config.loader']->load($path);
         }
     });
     $app['config.replacements.resolver'] = $app->protect(function ($value) use($app) {
         $replacements = $app['config.replacements'];
         if ([] === $replacements) {
             return $value;
         }
         if (is_array($value)) {
             return array_map(function ($value) use($app) {
                 return $app['config.replacements.resolver']($value);
             }, $value);
         }
         if (!is_string($value)) {
             return $value;
         }
         return $this->resolveString($value, $replacements);
     });
     $app['config.locator'] = function () {
         return new FileLocator();
     };
     $app['config.loader.yml'] = $app->factory(function (Container $app) {
         return new YamlFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app, $app['config.locator']);
     });
     $app['config.loader.resolver'] = function (Container $app) {
         return new LoaderResolver([$app['config.loader.yml'], $app['config.loader.directory'], $app['config.loader.php']]);
     };
     $app['config.loader'] = function (Container $app) {
         return new DelegatingLoader($app['config.loader.resolver']);
     };
     $app['config.filenames'] = [];
     $app['config.replacements'] = [];
 }
开发者ID:sergiors,项目名称:config-service-provider,代码行数:53,代码来源:ConfigServiceProvider.php

示例10: register

 /**
  * Register provider
  *
  * Register the PHP Template Loader as the tempalte loader to the DIC.
  *
  * @param \Pimple\Container $container DIC
  * @return void
  */
 public function register(Container $container)
 {
     if ($container["config.service"]["view.loader"] !== "Twig") {
         return;
     }
     $container["tplLoader.service"] = function (Container $container) {
         return new \SlaxWeb\ViewTwig\Loader\Twig($container["response.service"], $container["logger.service"](), $container["twig.service"]);
     };
     $container["twig.service"] = $container->factory(function (Container $cont) {
         return new \Twig_Environment($cont["twigFilesystemLoader.service"], ["cache" => $cont["config.service"]["twig.cacheDir"]]);
     });
     $container["twigFilesystemLoader.service"] = $container->factory(function (Container $cont) {
         return new \Twig_Loader_Filesystem($cont["config.service"]["twig.templateDir"]);
     });
 }
开发者ID:slaxweb,项目名称:view-twig,代码行数:23,代码来源:Provider.php

示例11: setUp

 protected function setUp()
 {
     $this->app = $app = new Container();
     $db_config = ['driver' => 'pdo_sqlite', 'dbname' => 'sqlite:///:memory:'];
     $models = ['post.model' => function () use($app) {
         return new Post($app);
     }, 'comment.model' => 'Comment'];
     $app['db'] = function () use($db_config) {
         $db = \Doctrine\DBAL\DriverManager::getConnection($db_config);
         $sql = file_get_contents(codecept_data_dir() . '/dump.sql');
         $db->exec($sql);
         return $db;
     };
     foreach ($models as $name => $class) {
         if (is_callable($class)) {
             $callable = $class;
         } else {
             $callable = function () use($class, $app) {
                 return new $class($app);
             };
         }
         $app[$name] = $app->factory($callable);
     }
     $this->loadFixtures();
 }
开发者ID:arduanov,项目名称:pimple-active-record,代码行数:25,代码来源:RecordTest.php

示例12: register

 /**
  * @param Container $container A pimple container instance.
  * @return void
  */
 public function register(Container $container)
 {
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\Email\EmailConfig
      */
     $container['email/config'] = function (Container $container) {
         $appConfig = $container['config'];
         $emailConfig = new EmailConfig($appConfig['email']);
         return $emailConfig;
     };
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\View\ViewInterface
      */
     $container['email/view'] = function (Container $container) {
         return $container['view'];
     };
     /**
      * @return \Charcoal\Factory\FactoryInterface
      */
     $container['email/factory'] = function (Container $container) {
         return new GenericFactory(['map' => ['email' => Email::class], 'base_class' => EmailInterface::class, 'default_class' => Email::class, 'arguments' => [['logger' => $container['logger'], 'config' => $container['email/config'], 'view' => $container['email/view'], 'template_factory' => $container['template/factory'], 'queue_item_factory' => $container['model/factory'], 'log_factory' => $container['model/factory']]]]);
     };
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\Email\EmailInterface
      */
     $container['email'] = $container->factory(function (Container $container) {
         return $container['email/factory']->create('email');
     });
 }
开发者ID:locomotivemtl,项目名称:charcoal-email,代码行数:36,代码来源:EmailServiceProvider.php

示例13: register

 /**
  * Settings section will be added once
  * any configuration is required.
  *
  * @inheritDoc
  */
 public function register(Container $container)
 {
     $container['security.encoder'] = function ($container) {
         return new MessageDigestPasswordEncoder();
     };
     $container['security.role_hierarchy'] = ['ROLE_SUPER_ADMIN' => array('ROLE_ADMIN', 'ROLE_USER')];
     $container['security.manager'] = function ($container) {
         return new SecurityManager($container);
     };
     $container['security.token_storage'] = function ($container) {
         return new TokenStorage();
     };
     $container['security.user_checker'] = function ($container) {
         return new UserChecker();
     };
     $container['member'] = $container->factory(function ($app) {
         if (null === ($token = $app['security.token_storage']->getToken())) {
             return null;
         }
         if (!is_object($user = $token->getUser())) {
             return null;
         }
         return $user;
     });
 }
开发者ID:myovchev,项目名称:zaralab-api,代码行数:31,代码来源:SecurityProvider.php

示例14: register

 public function register(Container $app)
 {
     $app['mailer'] = function () {
         $mailer = new \PHPMailer();
         $mailer->CharSet = 'UTF-8';
         return $mailer;
     };
     $app['email'] = $app->factory(function ($c) {
         $mailConfig = $c['config']['mail'];
         $email = $c['mailer'];
         $email->From = $mailConfig['from'];
         if (is_array($mailConfig['to'])) {
             foreach ($mailConfig['to'] as $addr) {
                 $email->addAddress($addr);
             }
         } else {
             $email->addAddress($mailConfig['to']);
         }
         $email->isHTML(true);
         return $email;
     });
     $app['email:send'] = $app->protect(function ($subject, $body) use($app) {
         $email = $app['email'];
         if ($subject and $body) {
             $email->Subject = $subject;
             $email->Body = $body;
         }
         return $email->send();
     });
 }
开发者ID:jh9aea,项目名称:promotion_container,代码行数:30,代码来源:MailerProvider.php

示例15: register

 public function register(Container $container)
 {
     $cid = $this->cid;
     $container[$cid] = $container->factory(function () use($cid, $container) {
         $get = function ($key, $default = null) use($container, $cid) {
             $key = $cid . '.' . $key;
             return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
         };
         $adapterName = $get('adapter');
         switch ($adapterName) {
             case 'redis':
                 $adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]);
                 break;
             case 'file':
                 $adapter = new AdapterFile($get('dir'));
                 break;
             default:
                 $adapter = new AdapternotCache();
                 break;
         }
         foreach ($get('options', []) as $k => $v) {
             $adapter->setOption($k, $v);
         }
         return new Cache($adapter);
     });
 }
开发者ID:okbro,项目名称:slim-cache-service,代码行数:26,代码来源:Provider.php


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