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


PHP ContainerBuilder::addDefinition方法代码示例

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


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

示例1: addWebLoader

 private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $config)
 {
     $filesServiceName = $this->prefix($name . 'Files');
     $files = $builder->addDefinition($filesServiceName)->setClass('WebLoader\\FileCollection')->setArguments(array($config['sourceDir']));
     foreach ($config['files'] as $file) {
         // finder support
         if (is_array($file) && isset($file['files']) && (isset($file['in']) || isset($file['from']))) {
             $finder = \Nette\Utils\Finder::findFiles($file['files']);
             unset($file['files']);
             foreach ($file as $method => $params) {
                 call_user_func_array(array($finder, $method), array($params));
             }
             foreach ($finder as $foundFile) {
                 $files->addSetup('addFile', array((string) $foundFile));
             }
         } else {
             $files->addSetup('addFile', array($file));
         }
     }
     $files->addSetup('addRemoteFiles', array($config['remoteFiles']));
     $compiler = $builder->addDefinition($this->prefix($name . 'Compiler'))->setClass('WebLoader\\Compiler')->setArguments(array('@' . $filesServiceName, $config['namingConvention'], $config['tempDir']));
     $compiler->addSetup('setJoinFiles', array($config['joinFiles']));
     foreach ($config['filters'] as $filter) {
         $compiler->addSetup('addFilter', array($filter));
     }
     foreach ($config['fileFilters'] as $filter) {
         $compiler->addSetup('addFileFilter', array($filter));
     }
     // todo css media
 }
开发者ID:norbe,项目名称:WebLoader,代码行数:30,代码来源:Extension.php

示例2: addWebLoader

 private function addWebLoader(ContainerBuilder $builder, $name, $config)
 {
     $filesServiceName = $this->prefix($name . 'Files');
     $files = $builder->addDefinition($filesServiceName)->setClass('WebLoader\\FileCollection')->setArguments(array($config['sourceDir']));
     foreach ($this->findFiles($config['files'], $config['sourceDir']) as $file) {
         $files->addSetup('addFile', array($file));
     }
     foreach ($this->findFiles($config['watchFiles'], $config['sourceDir']) as $file) {
         $files->addSetup('addWatchFile', array($file));
     }
     $files->addSetup('addRemoteFiles', array($config['remoteFiles']));
     $compiler = $builder->addDefinition($this->prefix($name . 'Compiler'))->setClass('WebLoader\\Compiler')->setArguments(array('@' . $filesServiceName, $config['namingConvention'], $config['tempDir']));
     $compiler->addSetup('setJoinFiles', array($config['joinFiles']));
     if ($builder->parameters['webloader']['debugger']) {
         $compiler->addSetup('@' . $this->prefix('tracyPanel') . '::addLoader', array($name, '@' . $this->prefix($name . 'Compiler')));
     }
     foreach ($config['filters'] as $filter) {
         $compiler->addSetup('addFilter', array($filter));
     }
     foreach ($config['fileFilters'] as $filter) {
         $compiler->addSetup('addFileFilter', array($filter));
     }
     if (isset($config['debug']) && $config['debug']) {
         $compiler->addSetup('enableDebugging');
     }
     $compiler->addSetup('setCheckLastModified', array($config['checkLastModified']));
     // todo css media
 }
开发者ID:janmarek,项目名称:webloader,代码行数:28,代码来源:Extension.php

示例3: loadRoutes

 /**
  * Routes definition
  *
  * @param ContainerBuilder $container Container
  * @param array            $config    Config
  *
  * @return void
  */
 protected function loadRoutes(ContainerBuilder $container, $config)
 {
     $container->addDefinition($this->prefix('storages'))->setClass('MouseOver\\Storage\\Application\\StorageList');
     $container->addDefinition($this->prefix('responder'))->setClass('MouseOver\\Storage\\Application\\StorageResponder');
     $container->addDefinition($this->prefix('linkResolver'))->setClass('MouseOver\\Storage\\Application\\StorageLinkResolver', [$config['module']]);
     $container->getDefinition('nette.latte')->addSetup('MouseOver\\Storage\\Application\\StorageMacros::install($service->getCompiler(), ?)', array($this->prefix('@linkResolver')));
     $routesList = $container->addDefinition($this->prefix('storageRoutes'))->setClass('Nette\\Application\\Routers\\RouteList')->setAutowired(false);
     $routesList->addSetup('$service[] = new Nette\\Application\\Routers\\Route(?, function ($presenter, $storage, $file) { return ?->handle($storage, $file, $presenter->request->getParameters()); })', array($config['module'] . '/<storage>/<file [a-zA-Z0-9\\-_.\\/]+>', $this->prefix('@responder')));
     $container->getDefinition('router')->addSetup('MouseOver\\Storage\\DI\\StorageExtension::prependTo($service, ?)', [$this->prefix('@storageRoutes')]);
 }
开发者ID:mouse-over,项目名称:storage,代码行数:18,代码来源:StorageExtension.php

示例4: setupTemplating

 /**
  * @param \Nette\DI\ContainerBuilder $container
  * @param array $config
  */
 private function setupTemplating(ContainerBuilder $container, array $config)
 {
     $def = $container->addDefinition($this->prefix('templateFilesFormatter'))->setClass('Lohini\\Templating\\TemplateFilesFormatter')->addSetup('$skin', [$config['skin']]);
     foreach ($config['dirs'] as $dir => $priority) {
         $def->addSetup('addDir', Validators::isNumericInt($dir) ? [$priority] : [$container->expand($dir), $priority]);
     }
 }
开发者ID:lohini,项目名称:framework,代码行数:11,代码来源:LohiniExtension.php

示例5: processAuthenticators

 /**
  * @param ContainerBuilder $container
  * @param array $config
  */
 private function processAuthenticators(ContainerBuilder $container, array $config)
 {
     $authentication = $container->addDefinition($this->prefix('authentication'))->setClass('Flame\\Rest\\Security\\Authentication');
     if (!$container->parameters['debugMode'] && count($config['ips'])) {
         $ipAuthenticator = $container->addDefinition($this->prefix('ipAuthenticator'))->setClass('Flame\\Rest\\Security\\Authenticators\\IpAuthenticator')->setArguments(array($config['ips']));
         $authentication->addSetup('addAuthenticator', array($ipAuthenticator));
     }
     if (!$container->parameters['debugMode'] && count($config['referers'])) {
         $refererAuthenticator = $container->addDefinition($this->prefix('refererAuthenticator'))->setClass('Flame\\Rest\\Security\\Authenticators\\RefererAuthenticator')->setArguments(array($config['referers']));
         $authentication->addSetup('addAuthenticator', array($refererAuthenticator));
     }
     foreach ($config['authenticators'] as $k => $authenticatorConfig) {
         $authenticator = $container->addDefinition($this->prefix('authenticator' . $k))->setClass($authenticatorConfig);
         $authentication->addSetup('addAuthenticator', array($authenticator));
     }
 }
开发者ID:Budry,项目名称:TinyREST,代码行数:20,代码来源:RestExtension.php

示例6: setupCompileTemplatesCommand

 private function setupCompileTemplatesCommand(ContainerBuilder $builder, array $config)
 {
     $config = $this->validateConfig($this->compileTemplatesDefaults, $config, 'compileTemplates');
     Validators::assertField($config, 'source', 'string|array');
     $builder->addDefinition($this->prefix('compileTemplates'))->setClass(CompileTemplatesCommand::class, [array_map(function ($directory) use($builder) {
         Validators::assert($directory, 'string');
         return Helpers::expand($directory, $builder->parameters);
     }, (array) $config['source'])])->addTag(ConsoleExtension::TAG_COMMAND)->setAutowired(false);
 }
开发者ID:lookyman,项目名称:commands,代码行数:9,代码来源:CommandsExtension.php

示例7: configMapper

 /**
  * Adds mapper service into container
  * @return ServiceDefinition
  */
 protected function configMapper(ContainerBuilder $builder, array $config)
 {
     if ($config['defaultEntityNamespace'] !== NULL && !is_string($config['defaultEntityNamespace'])) {
         throw new \RuntimeException('DefaultEntityNamespace must be NULL or string, ' . gettype($config['defaultEntityNamespace']) . ' given');
     }
     $mapper = $builder->addDefinition($this->prefix('mapper'))->setClass($config['mapper'], array($config['defaultEntityNamespace']));
     $this->processEntityProviders($mapper, $config);
     $this->processUserEntities($mapper, $config);
     return $mapper;
 }
开发者ID:janpecha,项目名称:leanmapper-extension,代码行数:14,代码来源:LeanMapperExtension.php

示例8: createEagerProxy

 /**
  * @param string $serviceName
  * @param string $cacheDirectory
  */
 private function createEagerProxy($serviceName, $cacheDirectory)
 {
     $definition = $this->builder->getDefinition($serviceName);
     $this->builder->removeDefinition($serviceName);
     $hiddenServiceName = $this->prefix($serviceName);
     $proxyClassName = $definition->getClass() . md5(serialize($definition));
     $this->builder->addDefinition($serviceName)->setClass($proxyClassName)->setFactory('@' . $this->prefix('eagerServiceFactory') . '::create', array($hiddenServiceName, $proxyClassName));
     $this->builder->addDefinition($hiddenServiceName, $definition)->setAutowired(false);
     if (!class_exists($proxyClassName)) {
         $classGenerator = new ClassGenerator();
         $this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $classGenerator);
         $classGenerator->setName($proxyClassName);
         $code = '<?php' . ClassGenerator::LINE_FEED . $classGenerator->generate();
         $tempPath = $cacheDirectory . uniqid() . ".php";
         $backslashPos = strrpos($proxyClassName, '\\');
         $newPath = $cacheDirectory . substr($proxyClassName, $backslashPos ? $backslashPos + 1 : 0) . ".php";
         file_put_contents($tempPath, $code, LOCK_EX);
         rename($tempPath, $newPath);
         require_once $newPath;
     }
 }
开发者ID:radekdvorak,项目名称:nette-proxy-service,代码行数:25,代码来源:ProxyServiceExtension.php

示例9: setupDatabase

 private function setupDatabase(ContainerBuilder $container, array $config)
 {
     if (isset($config['dsn'])) {
         $config = array('default' => $config);
     }
     $autowired = true;
     foreach ((array) $config as $name => $info) {
         if (!is_array($info)) {
             continue;
         }
         $this->validate($info, $this->databaseDefaults, 'flunorette');
         $info += array('autowired' => $autowired) + $this->databaseDefaults;
         $autowired = false;
         foreach (array('transactionCounter', 'delimiteMode', 'lazy', 'driverClass') as $option) {
             if (isset($info[$option])) {
                 $info['options'][$option] = $info[$option];
             }
         }
         foreach ((array) $info['options'] as $key => $value) {
             if (preg_match('#^PDO::\\w+\\z#', $key)) {
                 unset($info['options'][$key]);
                 $info['options'][constant($key)] = $value;
             }
         }
         if (!$info['reflection']) {
             $reflection = null;
         } elseif (is_string($info['reflection'])) {
             $reflection = new Statement(preg_match('#^[a-z]+\\z#', $info['reflection']) ? 'Flunorette\\Reflections\\' . ucfirst($info['reflection']) . 'Reflection' : $info['reflection'], strtolower($info['reflection']) === 'discovered' ? array('@self') : array());
         } else {
             $tmp = Compiler::filterArguments(array($info['reflection']));
             $reflection = reset($tmp);
         }
         $connection = $container->addDefinition($this->prefix($name))->setClass('Flunorette\\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))->setAutowired($info['autowired'])->addSetup('setCacheStorage')->addSetup('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?)', array('Flunorette\\Bridges\\Nette\\Diagnostics\\ConnectionPanel::renderException'));
         if ($container->parameters['debugMode'] && $info['debugger']) {
             $connection->addSetup('Flunorette\\Helpers::createDebugPanel', array($connection, !empty($info['explain']), $name));
         }
     }
 }
开发者ID:icaine,项目名称:flunorette,代码行数:38,代码来源:FlunoretteExtension.php

示例10: parseServices

 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     $all = array_merge($services, $factories);
     uasort($all, function ($a, $b) {
         return strcmp(Config\Helpers::isInheriting($a), Config\Helpers::isInheriting($b));
     });
     if (!empty($config['factories'])) {
         trigger_error("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.", E_USER_DEPRECATED);
     }
     foreach ($all as $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $name = count($builder->getDefinitions()) . preg_replace('#\\W+#', '_', $def instanceof \stdClass ? ".{$def->value}" : (is_scalar($def) ? ".{$def}" : ''));
         } elseif (array_key_exists($origName, $services) && array_key_exists($origName, $factories)) {
             throw new ServiceCreationException("It is not allowed to use services and factories with the same name: '{$origName}'.");
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         $params = $builder->parameters;
         if (is_array($def) && isset($def['parameters'])) {
             foreach ((array) $def['parameters'] as $k => $v) {
                 $v = explode(' ', is_int($k) ? $v : $k);
                 $params[end($v)] = $builder::literal('$' . end($v));
             }
         }
         $def = Helpers::expand($def, $params);
         if (($parent = Config\Helpers::takeParent($def)) && $parent !== $name) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
         if (array_key_exists($origName, $factories)) {
             $definition->setAutowired(FALSE);
         }
         if ($definition->class === 'self') {
             $definition->class = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
         if ($definition->factory && $definition->factory->entity === 'self') {
             $definition->factory->entity = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
     }
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:57,代码来源:Compiler.php

示例11: loadDefinitions

 private function loadDefinitions(ContainerBuilder $builder)
 {
     $classes = $this->robotLoader->getIndexedClasses();
     $markerInterface = new ClassType(IServiceMarker::class);
     foreach ($classes as $key => $val) {
         if (Strings::endsWith($key, 'Service')) {
             $reflection = new ClassType($key);
             $serviceName = '_auto.' . str_replace("\\", "_", $key);
             if (!$reflection->isAbstract() && $reflection->isSubclassOf($markerInterface)) {
                 $builder->addDefinition($serviceName)->setClass($key);
             }
         }
     }
 }
开发者ID:dtforce,项目名称:nette-inject,代码行数:14,代码来源:InjectionCompilerExtension.php

示例12: parseServices

 /**
  * Parses section 'services' from configuration file.
  *
  * @return void
  */
 public static function parseServices(Nette\DI\ContainerBuilder $container, array $config, $namespace = null)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     if ($tmp = array_intersect_key($services, $factories)) {
         $tmp = implode("', '", array_keys($tmp));
         throw new Nette\DI\ServiceCreationException("It is not allowed to use services and factories with the same names: '{$tmp}'.");
     }
     $all = $services + $factories;
     uasort($all, function ($a, $b) {
         return strcmp(Helpers::isInheriting($a), Helpers::isInheriting($b));
     });
     foreach ($all as $name => $def) {
         $shared = array_key_exists($name, $services);
         $name = ($namespace ? $namespace . '.' : '') . $name;
         if (($parent = Helpers::takeParent($def)) && $parent !== $name) {
             $container->removeDefinition($name);
             $definition = $container->addDefinition($name);
             if ($parent !== Helpers::OVERWRITE) {
                 foreach ($container->getDefinition($parent) as $k => $v) {
                     $definition->{$k} = unserialize(serialize($v));
                     // deep clone
                 }
             }
         } elseif ($container->hasDefinition($name)) {
             $definition = $container->getDefinition($name);
             if ($definition->shared !== $shared) {
                 throw new Nette\DI\ServiceCreationException("It is not allowed to use service and factory with the same name '{$name}'.");
             }
         } else {
             $definition = $container->addDefinition($name);
         }
         try {
             static::parseService($definition, $def, $shared);
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException("Service '{$name}': " . $e->getMessage(), null, $e);
         }
     }
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:44,代码来源:Compiler.php

示例13: createTimestampStorage

 /**
  * @param ContainerBuilder $containerBuilder
  *
  * @return \Nette\DI\ServiceDefinition
  */
 protected function createTimestampStorage(ContainerBuilder $containerBuilder)
 {
     return $containerBuilder->addDefinition($this->prefix('timestampStorage'))->setAutowired(FALSE)->setInject(FALSE);
 }
开发者ID:stekycz,项目名称:cronner,代码行数:9,代码来源:CronnerExtension.php

示例14: setupDatabase

 private function setupDatabase(ContainerBuilder $container, array $config)
 {
     if (isset($config['dsn'])) {
         $config = array('default' => $config);
     }
     $autowired = TRUE;
     foreach ((array) $config as $name => $info) {
         if (!is_array($info)) {
             continue;
         }
         $info += $this->databaseDefaults + array('autowired' => $autowired);
         $autowired = FALSE;
         foreach ((array) $info['options'] as $key => $value) {
             if (preg_match('#^PDO::\\w+\\z#', $key)) {
                 unset($info['options'][$key]);
                 $info['options'][constant($key)] = $value;
             }
         }
         if (!$info['reflection']) {
             $reflection = NULL;
         } elseif (is_string($info['reflection'])) {
             $reflection = new Nette\DI\Statement(preg_match('#^[a-z]+\\z#', $info['reflection']) ? 'Nette\\Database\\Reflection\\' . ucfirst($info['reflection']) . 'Reflection' : $info['reflection'], strtolower($info['reflection']) === 'discovered' ? array('@self') : array());
         } else {
             $tmp = Nette\DI\Compiler::filterArguments(array($info['reflection']));
             $reflection = reset($tmp);
         }
         $connection = $container->addDefinition($this->prefix("database.{$name}"))->setClass('Nette\\Database\\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))->setAutowired($info['autowired'])->addSetup('setContext', array(new Nette\DI\Statement('Nette\\Database\\Context', array('@self', $reflection))))->addSetup('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?)', array('Nette\\Database\\Diagnostics\\ConnectionPanel::renderException'));
         $container->addDefinition($this->prefix("database.{$name}.context"))->setClass('Nette\\Database\\Context')->setFactory(array($connection, 'getContext'))->setAutowired($info['autowired']);
         if ($container->parameters['debugMode'] && $info['debugger']) {
             $connection->addSetup('Nette\\Database\\Helpers::createDebugPanel', array($connection, !empty($info['explain']), $name));
         }
     }
 }
开发者ID:jurasm2,项目名称:nette,代码行数:33,代码来源:NetteExtension.php

示例15: addDefinition

 /**
  * 
  * @param string $class_name
  * @param Nette\DI\CompilerExtension $builder
  * @return string
  */
 public function addDefinition($class_name, Nette\DI\ContainerBuilder $builder)
 {
     $name = str_replace('\\', '_', $class_name);
     $builder->addDefinition($this->prefix(str_replace('\\', '_', $name)))->setClass($class_name)->setInject(true);
     return $name;
 }
开发者ID:dipcom,项目名称:annevents,代码行数:12,代码来源:AnnEventsExtension.php


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