• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP DI\Helpers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: loadConfiguration

 /**
  * Processes configuration data. Intended to be overridden by descendant.
  *
  * @throws \Exception
  */
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $values = Nette\DI\Config\Helpers::merge($this->getConfig(), $this->defaults);
     $config = Nette\DI\Helpers::expand($values['paramsSettings'], $builder->parameters);
     unset($values['paramsSettings']);
     $db = NULL;
     if ($config['database'] !== FALSE) {
         $databaseClass = strpos($config['database'], '\\') ? $config['database'] : 'WebChemistry\\Parameters\\Database\\' . $config['database'];
         if (!class_exists($databaseClass)) {
             throw new \Exception("Class '{$databaseClass}' does not exist.");
         }
         $db = $builder->addDefinition($this->prefix('database'))->setClass('WebChemistry\\Parameters\\IDatabase')->setFactory($databaseClass);
         if ($config['database'] === 'Doctrine') {
             $implements = class_implements($config['entity']);
             if (array_search('WebChemistry\\Parameters\\IEntity', $implements) === FALSE) {
                 throw new ConfigurationException("Class '{$config['entity']}' must implements WebChemistry\\Parameters\\IEntity.");
             }
             $db->addSetup('setEntity', [$config['entity']]);
         }
     }
     $builder->addDefinition($this->prefix('provider'))->setClass('WebChemistry\\Parameters\\Provider', [$values, $config['cache'], $db]);
     if ($config['bar'] && class_exists('Tracy\\Debugger')) {
         $builder->addDefinition($this->prefix('bar'))->setClass('WebChemistry\\Parameters\\Bar\\Debug', [(bool) $db]);
     }
 }
开发者ID:webchemistry,项目名称:parameters,代码行数:31,代码来源:ParametersExtension.php


示例2: _getConfig

 private function _getConfig()
 {
     $config = $this->validateConfig($this->defaults, $this->config);
     $config['log_directory'] = Nette\DI\Helpers::expand($config['log_directory'], $this->getContainerBuilder()->parameters);
     $config['mail_images_base_path'] = Nette\DI\Helpers::expand($config['mail_images_base_path'], $this->getContainerBuilder()->parameters);
     return $config;
 }
开发者ID:JakubKontra,项目名称:mailing,代码行数:7,代码来源:MailingExtension.php


示例3: 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


示例4: beforeCompile

 public function beforeCompile()
 {
     $builder = $this->getContainerBuilder();
     $this->validateConfig($this->defaults);
     $config = $this->getConfig($this->defaults);
     foreach ($builder->findByType('Nette\\Mail\\IMailer') as $name => $def) {
         $builder->removeDefinition($name);
     }
     $builder->addDefinition('fileMailer')->setClass(FileMailer::class, [$config])->addSetup('$tempDir', [Helpers::expand($config['tempDir'], $builder->parameters)]);
 }
开发者ID:Ryby,项目名称:Mail,代码行数:10,代码来源:FileMailerExtension.php


示例5: __construct

 /**
  * @param Container $container
  * @param ManagerRegistry $registry
  */
 public function __construct(Container $container, ManagerRegistry $registry)
 {
     parent::__construct('dwarfSearch:import');
     $this->entityManager = $registry->getManager();
     $this->seasonsRepository = $registry->getRepository(Season::class);
     $this->episodesRepository = $registry->getRepository(Episode::class);
     $this->languagesRepository = $registry->getRepository(Language::class);
     $this->charactersRepository = $registry->getRepository(Character::class);
     $this->scenariosDir = Helpers::expand('%appDir%/../scenarios', $container->getParameters());
 }
开发者ID:legendik,项目名称:DwarfSearch,代码行数:14,代码来源:ScreenplayImportCommand.php


示例6: loadConfiguration

 public function loadConfiguration()
 {
     // Cause we don't want merge arrays (annotations, interfaces, etc..)
     $config = $this->getCustomConfig($this->defaults);
     // Validate config
     Validators::assertField($config, 'dirs', 'array');
     Validators::assertField($config, 'annotations', 'array|null');
     Validators::assertField($config, 'interfaces', 'array|null');
     Validators::assertField($config, 'decorator', 'array');
     // Expand config (cause %appDir% etc..)
     $this->config = Helpers::expand($config, $this->getContainerBuilder()->parameters);
 }
开发者ID:minetro,项目名称:service-autoloader,代码行数:12,代码来源:ServiceAutoloadExtension.php


示例7: beforeCompile

 public function beforeCompile()
 {
     foreach ($this->getConfig() as $class => $info) {
         $info = $this->validateConfig($this->defaults, $info, $this->prefix($class));
         if ($info['inject'] !== NULL) {
             $info['tags'][InjectExtension::TAG_INJECT] = $info['inject'];
         }
         $info = Nette\DI\Helpers::filterArguments($info);
         $this->addSetups($class, (array) $info['setup']);
         $this->addTags($class, (array) $info['tags']);
     }
 }
开发者ID:sallyx,项目名称:di,代码行数:12,代码来源:DecoratorExtension.php


示例8: getSettings

 /**
  * @return array
  */
 public function getSettings()
 {
     if (method_exists($this, 'validateConfig')) {
         $config = $this->validateConfig($this->defaults, $this->config);
         $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
         $config['appDir'] = Nette\DI\Helpers::expand($config['appDir'], $this->getContainerBuilder()->parameters);
     } else {
         $config = $this->getConfig($this->defaults);
         // deprecated
     }
     return $config;
 }
开发者ID:vojtabiberle,项目名称:MediaStorage,代码行数:15,代码来源:Extension.php


示例9: beforeCompile

 /**
  * Method setings extension.
  */
 public function beforeCompile()
 {
     $builder = $this->getContainerBuilder();
     $this->validateConfig($this->defaults);
     $config = $this->getConfig($this->defaults);
     foreach ($builder->findByType('Nette\\Mail\\IMailer') as $name => $def) {
         $builder->removeDefinition($name);
     }
     if ($config['debugger'] && interface_exists('Tracy\\IBarPanel')) {
         $builder->addDefinition($this->prefix('panel'))->setClass('RM\\MailPanel')->addSetup('$newMessageTime', [$config['newMessageTime']])->addSetup('$show', [array_unique($config['show'])])->addSetup('$autoremove', [$config['autoremove']])->addSetup('$hideEmpty', [$config['hideEmpty']]);
     }
     $builder->addDefinition($this->prefix('mailer'))->setClass('RM\\FileMailer', [Helpers::expand($config['tempDir'], $builder->parameters)])->addSetup('@RM\\MailPanel::setFileMailer', ['@self'])->addSetup('@Tracy\\Bar::addPanel', [$this->prefix('@panel')]);
 }
开发者ID:newPOPE,项目名称:FileMailer,代码行数:16,代码来源:MailPanelExtension.php


示例10: run

	/**
	 * @return Nette\Application\IResponse
	 */
	public function run(Application\Request $request)
	{
		$this->request = $request;

		if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
			$refUrl = clone $this->httpRequest->getUrl();
			$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
			if ($url !== NULL && !$this->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 = $params['callback'];
		$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
		$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);

		if ($this->context) {
			foreach ($reflection->getParameters() as $param) {
				if ($param->getClassName()) {
					unset($params[$param->getPosition()]);
				}
			}

			$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
			$params['presenter'] = $this;
		}

		$response = call_user_func_array($callback, $params);

		if (is_string($response)) {
			$response = array($response, array());
		}
		if (is_array($response)) {
			list($templateSource, $templateParams) = $response;
			$response = $this->createTemplate()->setParameters($templateParams);
			if (!$templateSource instanceof \SplFileInfo) {
				$response->getLatte()->setLoader(new Latte\Loaders\StringLoader);
			}
			$response->setFile($templateSource);
		}
		if ($response instanceof Application\UI\ITemplate) {
			return new Responses\TextResponse($response);
		} else {
			return $response;
		}
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:54,代码来源:MicroPresenter.php


示例11: loadConfiguration

 /**
  * @inheritDoc
  */
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = Helpers::expand($this->getConfig() + $this->defaults, $builder->parameters);
     $this->setupConfigByExtensions($config);
     $this->assertConfig($config);
     $builder->parameters[$this->prefix('debug')] = !empty($config['debug']);
     $this->createMetadataDriver();
     $this->createConfigurationService($config);
     $this->createEventManager($config);
     $this->createConnection($config);
     $this->createEntityManager($config);
     $this->registerMetadata($config['metadata']);
     $this->registerEventSubscribers($config['eventSubscribers']);
 }
开发者ID:pt24,项目名称:doctrine,代码行数:18,代码来源:CompilerExtension.php


示例12: injectByProperties

 private function injectByProperties(Presenter $presenter)
 {
     if (class_exists(InjectExtension::class)) {
         /** @noinspection PhpInternalEntityUsedInspection */
         $properties = InjectExtension::getInjectProperties(get_class($presenter));
         // Nette 2.3+
     } else {
         $properties = Helpers::getInjectProperties(new ClassType($presenter));
         // Nette 2.2
     }
     foreach ($properties as $property => $type) {
         if (isset($this->dependencies['@' . $property])) {
             $presenter->{$property} = $this->dependencies['@' . $property];
         } elseif (isset($this->dependencies[$property])) {
             $presenter->{$property} = $this->dependencies[$property];
         }
     }
 }
开发者ID:instante,项目名称:php-test-suite,代码行数:18,代码来源:DependencyContainer.php


示例13: loadConfiguration

 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->validateConfig($this->defaults);
     // Add themes
     $params = [];
     $neon = new NeonAdapter();
     foreach (Finder::findFiles('theme.neon')->limitDepth(2)->from($config['themes']) as $file => $splfile) {
         // Parse config
         $expandConfig = ['themeDir' => dirname($splfile->getRealPath())];
         $themeConfig = Helpers::expand($neon->load($file), $expandConfig, TRUE);
         // Validate theme configs
         $this->validateConfig($this->themeDefaults, $themeConfig, 'themes');
         $this->validateConfig($this->themeDefaults['theme'], $themeConfig['theme'], 'theme');
         // Parse theme name
         $themeName = strtolower($themeConfig['theme']['name']);
         // Check duplicity
         if (array_key_exists($themeName, $params)) {
             throw new InvalidStateException('Theme "' . $themeName . '" is already defined.');
         }
         // Add to array
         $params[$themeName] = $themeConfig;
     }
     // Check if selected template is not null
     Validators::assertField($params, $config['theme'], NULL, 'template "%s"');
     $theme = $params[$config['theme']];
     // Add parameters to global parameters
     $builder->parameters['themes'] = [];
     $builder->parameters['themes']['theme'] = $theme['theme'];
     $builder->parameters['themes']['vars'] = $config['template'];
     $builder->parameters['themes']['output'] = $config['output'];
     // Add template model to container
     Compiler::parseServices($builder, ['services' => $theme['model']], $this->prefix('model'));
     // Add command manager (fake presenter)
     $builder->addDefinition($this->prefix('ui.manager'))->setClass('Generator\\UI\\CommandManager');
     // Add template factory
     $builder->addDefinition($this->prefix('latte.templateFactory'))->setClass('Generator\\Latte\\TemplateFactory')->setAutowired();
     // Add commands
     $builder->addDefinition($this->prefix('commands.info'))->setClass('Generator\\Commands\\InfoCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.generate'))->setClass('Generator\\Commands\\GenerateCommand', [$builder->parameters['themes']])->setInject();
     $builder->addDefinition($this->prefix('commands.deploy'))->setClass('Generator\\Commands\\DeployCommand')->setInject();
     $builder->addDefinition($this->prefix('commands.error'))->setClass('Generator\\Commands\\ErrorCommand')->setInject();
 }
开发者ID:minetro,项目名称:ghpage,代码行数:43,代码来源:Extension.php


示例14: getSettings

 /**
  * @throws ImageStorageException
  * @return array
  */
 public function getSettings()
 {
     if (!$this->settings) {
         $config = $this->validateConfig($this->defaults);
         $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
         // Validation
         $quality = $config['quality'];
         if (!is_int($quality) || !Validators::isInRange($quality, [0, 100])) {
             throw new ImageStorageException('Quality must be an integer from 0 to 100.');
         }
         foreach ($config['events'] as $name => &$array) {
             Validators::assert($array, 'array');
         }
         foreach ($config['helpers'] as $name => $class) {
             if (!class_exists($class) || $class instanceof IHelper) {
                 throw new ImageStorageException("Helper {$name} must be instance of " . IHelper::class);
             }
         }
         $this->settings = $config;
     }
     return $this->settings;
 }
开发者ID:webchemistry,项目名称:images,代码行数:26,代码来源:ImagesExtension.php


示例15: createComponent

 /**
  * @param $name
  * @return Nette\ComponentModel\IComponent
  * @throws Nette\UnexpectedValueException
  */
 public function createComponent($name)
 {
     $sl = $this->getServiceLocatorForFactories();
     $ucname = ucfirst($name);
     $method = 'createComponent' . $ucname;
     if ($ucname !== $name && method_exists($this, $method)) {
         $reflection = $this->getReflection()->getMethod($method);
         if ($reflection->getName() !== $method) {
             return;
         }
         $parameters = $reflection->parameters;
         $args = array();
         if (($first = reset($parameters)) && !$first->className) {
             $args[] = $name;
         }
         $args = Nette\DI\Helpers::autowireArguments($reflection, $args, $sl);
         $component = call_user_func_array(array($this, $method), $args);
         if (!$component instanceof Nette\ComponentModel\IComponent && !isset($this->components[$name])) {
             throw new Nette\UnexpectedValueException("Method {$reflection} did not return or create the desired component.");
         }
         return $component;
     }
 }
开发者ID:matej21,项目名称:nette-autowire-component-factories,代码行数:28,代码来源:AutowireComponentFactories.php


示例16: parsePosts

 /**
  * @param array $files
  * @throws InvalidStateException
  * @return array
  */
 protected function parsePosts($files)
 {
     $posts = [];
     $postsIds = [];
     $decoder = new NeonAdapter();
     foreach ($files as $file) {
         // Decode file
         $config = $decoder->load($file);
         // Merge
         $post = Config\Helpers::merge($config, $this->scheme);
         // Check unique post id
         if (in_array($post['id'], $postsIds)) {
             throw new InvalidStateException('Duplicate post.id "' . $post['id'] . '"');
         }
         // Expand post scheme
         $post = Helpers::expand($post, ['file' => dirname($file)], TRUE);
         // Unify
         $post['post'] = realpath($post['post']);
         $posts[] = $post;
         $postsIds[] = $post['id'];
     }
     return $posts;
 }
开发者ID:minetro,项目名称:simple-blogger,代码行数:28,代码来源:StaticCollector.php


示例17: updateDefinition

 private function updateDefinition($def)
 {
     $injects = array();
     $properties = DI\Helpers::getInjectProperties(new \ReflectionClass($def->getClass()), $this->getContainerBuilder());
     foreach ($properties as $property => $type) {
         $injects[] = new DI\Statement('$' . $property, array('@\\' . ltrim($type, '\\')));
     }
     foreach (get_class_methods($def->getClass()) as $method) {
         if (substr($method, 0, 6) === 'inject') {
             $injects[] = new DI\Statement($method);
         }
     }
     $setups = $def->getSetup();
     foreach ($injects as $inject) {
         foreach ($setups as $key => $setup) {
             if ($setup->getEntity() === $inject->getEntity()) {
                 $inject = $setup;
                 unset($setups[$key]);
             }
         }
         array_unshift($setups, $inject);
     }
     $def->setSetup($setups);
 }
开发者ID:vladimirslevercz,项目名称:alena,代码行数:24,代码来源:InjectExtension.php


示例18: parseServices

 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     if (!empty($config['factories'])) {
         throw new Nette\DeprecatedException("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.");
     }
     $services = isset($config['services']) ? $config['services'] : array();
     $depths = array();
     foreach ($services as $name => $def) {
         $path = array();
         while (Config\Helpers::isInheriting($def)) {
             $path[] = $def;
             $def = isset($services[$def[Config\Helpers::EXTENDS_KEY]]) ? $services[$def[Config\Helpers::EXTENDS_KEY]] : array();
             if (in_array($def, $path, TRUE)) {
                 throw new ServiceCreationException("Circular reference detected for service '{$name}'.");
             }
         }
         $depths[$name] = count($path);
     }
     array_multisort($depths, $services);
     foreach ($services as $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $postfix = $def instanceof Statement && is_string($def->getEntity()) ? '.' . $def->getEntity() : (is_scalar($def) ? ".{$def}" : '');
             $name = count($builder->getDefinitions()) + 1 . preg_replace('#\\W+#', '_', $postfix);
         } 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 ($definition->getClass() === 'self' || $definition->getFactory() && $definition->getFactory()->getEntity() === 'self') {
             throw new Nette\DeprecatedException("Replace service definition '{$origName}: self' with '- {$origName}'.");
         }
     }
 }
开发者ID:DIPcom,项目名称:Sandmin,代码行数:56,代码来源:Compiler.php


示例19: generateContainer

 /**
  * @return string
  * @internal
  */
 public function generateContainer(DI\Compiler $compiler)
 {
     $loader = $this->createLoader();
     $compiler->addConfig(['parameters' => $this->parameters]);
     $fileInfo = [];
     foreach ($this->files as $info) {
         if (is_scalar($info[0])) {
             $fileInfo[] = "// source: {$info['0']} {$info['1']}";
             $info[0] = $loader->load($info[0], $info[1]);
         }
         $compiler->addConfig($this->fixCompatibility($info[0]));
     }
     $compiler->addDependencies($loader->getDependencies());
     $builder = $compiler->getContainerBuilder();
     $builder->addExcludedClasses($this->autowireExcludedClasses);
     foreach ($this->defaultExtensions as $name => $extension) {
         list($class, $args) = is_string($extension) ? [$extension, []] : $extension;
         if (class_exists($class)) {
             $args = DI\Helpers::expand($args, $this->parameters, TRUE);
             $compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args));
         }
     }
     $this->onCompile($this, $compiler);
     $classes = $compiler->compile();
     if (!empty($builder->parameters['container']['parent'])) {
         $classes[0]->setExtends($builder->parameters['container']['parent']);
     }
     return implode("\n", $fileInfo) . "\n\n" . implode("\n\n\n", $classes) . (($tmp = $builder->parameters['container']['class']) ? "\nclass {$tmp} extends {$builder->getClassName()} {}\n" : '');
 }
开发者ID:pt24,项目名称:bootstrap,代码行数:33,代码来源:Configurator.php


示例20: autowireArguments

 /**
  * Creates a list of arguments using autowiring.
  * @return array
  * @internal
  */
 public function autowireArguments($class, $method, array $arguments)
 {
     $rc = new ReflectionClass($class);
     if (!$rc->hasMethod($method)) {
         if (!Nette\Utils\Arrays::isList($arguments)) {
             throw new ServiceCreationException("Unable to pass specified arguments to {$class}::{$method}().");
         }
         return $arguments;
     }
     $rm = $rc->getMethod($method);
     if (!$rm->isPublic()) {
         throw new ServiceCreationException("{$class}::{$method}() is not callable.");
     }
     $this->addDependency($rm);
     return Helpers::autowireArguments($rm, $arguments, $this);
 }
开发者ID:nette,项目名称:di,代码行数:21,代码来源:ContainerBuilder.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Config\Helpers类代码示例发布时间:2022-05-23
下一篇:
PHP DI\ContainerBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap