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


PHP DI\Compiler类代码示例

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


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

示例1: fixCompile

 /**
  * @param \Nette\DI\Compiler $compiler
  * @return string
  */
 protected function fixCompile(\Nette\DI\Compiler $compiler)
 {
     $code = $this->compiler->compile();
     if (!is_array($code)) {
         return $code;
     }
     return implode("\n\n\n", $code);
 }
开发者ID:webchemistry,项目名称:forms-multiplier,代码行数:12,代码来源:ExtensionTest.php

示例2: generate

 /**
  * @return array of (code, file[])
  */
 protected function generate($class, $generator)
 {
     $compiler = new Compiler();
     $compiler->getContainerBuilder()->setClassName($class);
     $code = call_user_func_array($generator, [&$compiler]);
     $code = $code ?: implode("\n\n\n", $compiler->compile());
     $files = $compiler->getDependencies();
     $files = call_user_func($this->filter, $files);
     $files = array_combine($files, $files);
     return array("<?php\n{$code}", serialize(@array_map('filemtime', $files)));
 }
开发者ID:arachne,项目名称:bootstrap,代码行数:14,代码来源:ContainerLoader.php

示例3: registerAdditionalExtension

 /**
  * Register extension if not registered by user.
  */
 private static function registerAdditionalExtension(\Nette\DI\Compiler $compiler, $name, $newExtension)
 {
     $extensions = [];
     foreach (isset($compiler->config['extensions']) ? $compiler->config['extensions'] : [] as $extension) {
         if (is_string($extension)) {
             $extensions[] = $extension;
         } elseif ($extension instanceof \Nette\DI\Statement) {
             $extensions[] = $extension->getEntity();
         }
     }
     if ($extensions && !in_array(get_class($newExtension), $extensions)) {
         $compiler->addExtension($name, $newExtension);
     }
 }
开发者ID:jakubskrz,项目名称:testbench,代码行数:17,代码来源:ContainerFactory.php

示例4: loadConfiguration

 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $helperClasses = array('Symfony\\Component\\Console\\Helper\\FormatterHelper', 'Symfony\\Component\\Console\\Helper\\QuestionHelper', 'Kdyby\\Console\\Helpers\\PresenterHelper');
     $helperClasses = array_map(function ($class) {
         return new Nette\DI\Statement($class);
     }, $helperClasses);
     if (class_exists('Symfony\\Component\\Console\\Helper\\ProgressHelper')) {
         $helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper', array(false));
     }
     if (class_exists('Symfony\\Component\\Console\\Helper\\DialogHelper')) {
         $helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper', array(false));
     }
     $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array($helperClasses))->setInject(FALSE);
     $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->addSetup('injectServiceLocator')->setInject(FALSE);
     $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::TAG_HELPER, 'dic');
     if ($config['disabled']) {
         return;
     }
     $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE);
     Nette\Utils\Validators::assert($config, 'array');
     foreach ($config['commands'] as $command) {
         $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command))));
         list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command));
         if (class_exists($def->factory->entity)) {
             $def->class = $def->factory->entity;
         }
         $def->setAutowired(FALSE);
         $def->setInject(FALSE);
         $def->addTag(self::TAG_COMMAND);
     }
 }
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:33,代码来源:ConsoleExtension.php

示例5: load

 public function load(Nette\DI\Compiler $compiler, Nette\DI\ContainerBuilder $containerBuilder)
 {
     $aspects = [];
     foreach ($this->aspectsList as $def) {
         if (!is_array($def)) {
             if (!is_string($def) && (!$def instanceof \stdClass || empty($def->value)) && !$def instanceof Nette\DI\Statement) {
                 $serialised = Nette\Utils\Json::encode($def);
                 throw new Kdyby\Aop\UnexpectedValueException("The service definition {$serialised} is expected to be an array or Neon entity.");
             }
             $def = ['factory' => $def];
         }
         $def['tags'][] = AspectsExtension::ASPECT_TAG;
         $aspects[] = $def;
     }
     $compiler->parseServices($containerBuilder, ['services' => $aspects], $this->prefix ? substr($this->extension->prefix('self'), 0, -5) : NULL);
 }
开发者ID:kdyby,项目名称:aop,代码行数:16,代码来源:AspectsConfig.php

示例6: loadConfiguration

 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array(array(new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\FormatterHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper'), new Nette\DI\Statement('Kdyby\\Console\\Helpers\\PresenterHelper'))))->setInject(FALSE);
     $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->setInject(FALSE);
     $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE);
     $builder->getDefinition('router')->addSetup('Kdyby\\Console\\CliRouter::prependTo($service, ?)', array($this->prefix('@router')));
     $builder->getDefinition('nette.presenterFactory')->addSetup('if (method_exists($service, ?)) { $service->setMapping(array(? => ?)); } ' . 'elseif (property_exists($service, ?)) { $service->mapping[?] = ?; }', array('setMapping', 'Kdyby', 'KdybyModule\\*\\*Presenter', 'mapping', 'Kdyby', 'KdybyModule\\*\\*Presenter'));
     if (!empty($config['url'])) {
         if (!preg_match('~^https?://[^/]+\\.[a-z]+(/.*)?$~', $config['url'])) {
             throw new Nette\Utils\AssertionException("The url '{$config['url']}' is not valid, please use this format: 'http://domain.tld/path'.");
         }
         $builder->getDefinition('nette.httpRequestFactory')->setClass('Kdyby\\Console\\HttpRequestFactory')->addSetup('setFakeRequestUrl', array($config['url']));
     }
     $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::HELPER_TAG, 'dic');
     Nette\Utils\Validators::assert($config, 'array');
     foreach ($config['commands'] as $command) {
         $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command))));
         list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command));
         if (class_exists($def->factory->entity)) {
             $def->class = $def->factory->entity;
         }
         $def->setAutowired(FALSE);
         $def->setInject(FALSE);
         $def->addTag(self::COMMAND_TAG);
     }
 }
开发者ID:pixuin,项目名称:console,代码行数:28,代码来源:ConsoleExtension.php

示例7: afterCompile

 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $builder = $this->getContainerBuilder();
     $options = $this->config;
     unset($options['bar'], $options['blueScreen']);
     if (isset($options['logSeverity'])) {
         $res = 0;
         foreach ((array) $options['logSeverity'] as $level) {
             $res |= is_int($level) ? $level : constant($level);
         }
         $options['logSeverity'] = $res;
     }
     foreach ($options as $key => $value) {
         if ($value !== NULL) {
             $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
             $initialize->addBody($builder->formatPhp('Tracy\\Debugger::' . $key . ' = ?;', Nette\DI\Compiler::filterArguments([$value])));
         }
     }
     $logger = $builder->getDefinition($this->prefix('logger'));
     if ($logger->getFactory()->getEntity() !== 'Tracy\\Debugger::getLogger') {
         $initialize->addBody($builder->formatPhp('Tracy\\Debugger::setLogger(?);', [$logger]));
     }
     if ($this->debugMode) {
         foreach ((array) $this->config['bar'] as $item) {
             $initialize->addBody($builder->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments([$this->prefix('bar'), is_string($item) ? new Nette\DI\Statement($item) : $item])));
         }
         if (!$this->cliMode) {
             $initialize->addBody('if ($tmp = $this->getByType("Nette\\Http\\Session", FALSE)) { $tmp->start(); Tracy\\Debugger::dispatch(); };');
         }
     }
     foreach ((array) $this->config['blueScreen'] as $item) {
         $initialize->addBody($builder->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments([$this->prefix('blueScreen'), $item])));
     }
 }
开发者ID:manGoweb,项目名称:mnamGo,代码行数:35,代码来源:TracyExtension.php

示例8: afterCompile

 /**
  * @param Code\ClassType $class
  */
 public function afterCompile(Code\ClassType $class)
 {
     $container = $this->getContainerBuilder();
     $init = $class->methods['initialize'];
     /** @var Code\Method $init */
     $blueScreen = 'Nette\\Diagnostics\\Debugger::' . (method_exists('Nette\\Diagnostics\\Debugger', 'getBlueScreen') ? 'getBlueScreen()' : '$blueScreen');
     $init->addBody($container->formatPhp($blueScreen . '->addPanel(?);', Nette\DI\Compiler::filterArguments(array('Kdyby\\PayPalExpress\\Diagnostics\\Panel::renderException'))));
 }
开发者ID:Hajneej,项目名称:PayPalExpress,代码行数:11,代码来源:PayPalExtension.php

示例9: setupMetadataParserFactory

 /**
  * @param string|array $config
  */
 protected function setupMetadataParserFactory($config)
 {
     $builder = $this->getContainerBuilder();
     if (is_array($config) && empty($config['class'])) {
         $config['class'] = $this->defaults['metadataParserFactory'];
     }
     Compiler::parseService($builder->addDefinition($this->prefix('metadataParserFactory')), $config);
 }
开发者ID:sw2eu,项目名称:dynamic-model,代码行数:11,代码来源:DynamicOrmExtension.php

示例10: getDbalFactory

 private function getDbalFactory($dbal)
 {
     if ($dbal instanceof Nette\DI\Statement) {
         return Nette\DI\Compiler::filterArguments([$dbal])[0];
     } elseif (is_string($dbal) && isset($this->dbals[$dbal])) {
         return $this->dbals[$dbal];
     } else {
         return NULL;
     }
 }
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:10,代码来源:MigrationsExtension.php

示例11: configureBuilder

 /**
  * @param array
  */
 protected function configureBuilder($config)
 {
     $builder = $this->getContainerBuilder();
     $builder->addDefinition($this->prefix('formBuilderFactory'))->setClass('Librette\\Doctrine\\Forms\\Builder\\FormBuilderFactory');
     $chain = $builder->addDefinition($this->prefix('builderChainHandler'))->setClass('Librette\\Doctrine\\Forms\\Builder\\Handlers\\ChainHandler');
     foreach (array_merge($config['handlers'], $this->defaultBuilderHandlers) as $i => $handler) {
         Compiler::parseService($def = $builder->addDefinition($this->prefix("builderHandler{$i}")), $handler);
         $def->setAutowired(FALSE);
         $chain->addSetup('add', [$def, FALSE]);
     }
     $builder->addDefinition($this->prefix('builderConfiguration'))->setClass('Librette\\Doctrine\\Forms\\Builder\\Configuration');
 }
开发者ID:librette,项目名称:doctrine-forms,代码行数:15,代码来源:DoctrineFormsExtension.php

示例12: setCompiler

 public function setCompiler(Nette\DI\Compiler $compiler, $name) : self
 {
     $application = current($compiler->getExtensions(Nette\Bridges\ApplicationDI\ApplicationExtension::class));
     if ($application instanceof Nette\Bridges\ApplicationDI\ApplicationExtension) {
         $application->defaults['errorPresenter'] = FALSE;
         $application->defaults['scanDirs'] = FALSE;
         $application->defaults['mapping'] = ['*' => 'Ytnuk\\*\\*'];
     }
     $session = current($compiler->getExtensions(Nette\Bridges\HttpDI\SessionExtension::class));
     if ($session instanceof Nette\Bridges\HttpDI\SessionExtension) {
         $session->defaults['debugger'] = $this->debugMode;
     }
     $http = current($compiler->getExtensions(Nette\Bridges\HttpDI\HttpExtension::class));
     if ($http instanceof Nette\Bridges\HttpDI\HttpExtension) {
         $http->defaults['headers']['X-Powered-By'] = __NAMESPACE__;
         $contentSecurityPolicy = ['default-src' => '\'self\'', 'form-action' => '\'self\'', 'img-src' => '\'self\' data:'];
         if ($this->debugMode) {
             $contentSecurityPolicy += ['script-src' => '\'self\' \'unsafe-inline\' \'unsafe-eval\'', 'style-src' => '\'self\' \'unsafe-inline\''];
         }
         $http->defaults['headers']['Content-Security-Policy'] = implode(';', array_map(function (string $key, string $value) {
             return implode(' ', [$key, $value]);
         }, array_keys($contentSecurityPolicy), array_values($contentSecurityPolicy)));
     }
     $di = current($compiler->getExtensions(Nette\DI\Extensions\DIExtension::class));
     if ($di instanceof Nette\DI\Extensions\DIExtension) {
         $di->defaults['debugger'] = $this->debugMode;
     }
     return parent::setCompiler($compiler, $name);
 }
开发者ID:ytnuk,项目名称:application,代码行数:29,代码来源:Extension.php

示例13: buildDefinition

 /**
  * @param string $value
  * @return ServiceDefinition|NULL
  */
 protected function buildDefinition($value)
 {
     if ($value === NULL) {
         return NULL;
     }
     $builder = $this->getContainerBuilder();
     $definition = $builder->addDefinition($this->prefix(md5($value)));
     list($definition->factory) = Compiler::filterArguments(array(is_string($value) ? new Statement($value) : $value));
     list($resolverClass) = (array) $builder->normalizeEntity($definition->getFactory()->getEntity());
     if (class_exists($resolverClass)) {
         $definition->setClass($resolverClass);
     }
     return $definition;
 }
开发者ID:darkphoenixff4,项目名称:DoctrineBehaviors,代码行数:18,代码来源:BehaviorExtension.php

示例14: loadJobs

 protected function loadJobs()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     foreach ($config['jobs'] as $subscriber) {
         $def = $builder->addDefinition($this->prefix('job.' . md5(Json::encode($subscriber))));
         list($def->factory) = Compiler::filterArguments(array(is_string($subscriber) ? new Statement($subscriber) : $subscriber));
         list($subscriberClass) = (array) $builder->normalizeEntity($def->factory->entity);
         if (class_exists($subscriberClass)) {
             $def->class = $subscriberClass;
         }
         $def->setAutowired(false);
         $def->addTag($config['cronJobTag']);
     }
 }
开发者ID:foowie,项目名称:cron,代码行数:15,代码来源:CronExtension.php

示例15: loadConfiguration

 public function loadConfiguration()
 {
     $container = $this->getContainerBuilder();
     $config = $this->compiler->getConfig();
     if (isset($config['nette']['database'])) {
         // back compatibility
         $config = $config['nette']['database'];
         $prefix = 'nette.';
     } else {
         $config = isset($config[$this->name]) ? $config[$this->name] : array();
         $prefix = '';
     }
     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, 'database');
         $info += array('autowired' => $autowired) + $this->databaseDefaults;
         $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;
             }
         }
         $connection = $container->addDefinition($prefix . $this->prefix($name))->setClass('Nette\\Database\\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))->setAutowired($info['autowired'])->addSetup('Tracy\\Debugger::getBlueScreen()->addPanel(?)', array('Nette\\Bridges\\DatabaseTracy\\ConnectionPanel::renderException'));
         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($connection) : array());
         } else {
             $tmp = Nette\DI\Compiler::filterArguments(array($info['reflection']));
             $reflection = reset($tmp);
         }
         $container->addDefinition($prefix . $this->prefix("{$name}.context"))->setClass('Nette\\Database\\Context', array($connection, $reflection))->setAutowired($info['autowired']);
         if ($container->parameters['debugMode'] && $info['debugger']) {
             $connection->addSetup('Nette\\Database\\Helpers::createDebugPanel', array($connection, !empty($info['explain']), $name));
         }
     }
 }
开发者ID:prcharom,项目名称:w-pps-reality,代码行数:44,代码来源:DatabaseExtension.php


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