getMethod() public method

public getMethod ( $name ) : Method
return Method
Ejemplo n.º 1
0
 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])));
     }
 }
Ejemplo n.º 2
0
 public function afterCompile(ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $initialize->addBody('$moduleManager = $this->getService(?);', [$this->getContainerBuilder()->getByType(ModuleManager::class)]);
     $initialize->addBody('foreach ($this->findByType(\'' . IModule::class . '\') as $module) {' . "\n" . '   $moduleManager->registerModule($this->getService($module));' . "\n" . '}');
     $initialize->addBody('$moduleManager->prepareModules();');
 }
Ejemplo n.º 3
0
 public function afterCompile(ClassType $class)
 {
     if (!$this->enabled) {
         return;
     }
     $config = $this->getConfig($this->defaults);
     $initialize = $class->getMethod('initialize');
     // AppName and license
     if (isset($config['appName']) && !is_array($config['appName'])) {
         $initialize->addBody('\\VrtakCZ\\NewRelic\\Tracy\\Bootstrap::setup(?, ?);', [$config['appName'], isset($config['license']) ? $config['license'] : NULL]);
     } elseif (isset($config['appName']) && is_array($config['appName'])) {
         if (!isset($config['appName']['*'])) {
             throw new \RuntimeException('Missing default app name as "*"');
         }
         $initialize->addBody('\\VrtakCZ\\NewRelic\\Tracy\\Bootstrap::setup(?, ?);', [$config['appName']['*'], isset($config['license']) ? $config['license'] : NULL]);
     }
     // Logger
     $initialize->addBody('\\Tracy\\Debugger::setLogger(new \\VrtakCZ\\NewRelic\\Tracy\\Logger(?));', [array_unique($config['logLevel'])]);
     $this->setupCustom($initialize);
     // Options
     if ($config['rum']['enabled'] !== 'auto') {
         $initialize->addBody('newrelic_disable_autorum();');
     }
     $initialize->addBody("ini_set('newrelic.transaction_tracer.enabled', ?);", [(string) $config['transactionTracer']['enabled']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.detail', ?);", [(string) $config['transactionTracer']['detail']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.record_sql', ?);", [(string) $config['transactionTracer']['recordSql']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.slow_sql', ?);", [(string) $config['transactionTracer']['slowSql']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.threshold', ?);", [(string) $config['transactionTracer']['threshold']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.stack_trace_thresholdshow', ?);", [(string) $config['transactionTracer']['stackTraceThreshold']]);
     $initialize->addBody("ini_set('newrelic.transaction_tracer.explain_threshold', ?);", [(string) $config['transactionTracer']['explainThreshold']]);
     $initialize->addBody("ini_set('newrelic.error_collector.enabled', ?);", [(string) $config['errorCollector']['enabled']]);
     $initialize->addBody("ini_set('newrelic.error_collector.record_database_errors', ?);", [(string) $config['errorCollector']['recordDatabaseErrors']]);
     $initialize->addBody('newrelic_capture_params(?);', [$config['parameters']['capture']]);
     $initialize->addBody("ini_set('newrelic.ignored_params', ?);", [implode(',', $config['parameters']['ignored'])]);
 }
Ejemplo n.º 4
0
 public function afterCompile(ClassType $class)
 {
     if ($this->isCli()) {
         return;
     }
     $class->getMethod('initialize')->addBody('header(?);', ['X-Clacks-Overhead: GNU Terry Pratchett']);
 }
Ejemplo n.º 5
0
 public function afterCompile(Code\ClassType $class)
 {
     $init = $class->getMethod('initialize');
     $originalInitialize = $init->getBody();
     $init->setBody('Doctrine\\Common\\Annotations\\AnnotationRegistry::registerLoader("class_exists");' . "\n");
     $init->addBody($originalInitialize);
 }
Ejemplo n.º 6
0
 public function afterCompile(ClassType $class)
 {
     $builder = $this->getContainerBuilder();
     $init = $class->getMethod('initialize');
     if ($builder->hasDefinition($this->prefix('bar'))) {
         $init->addBody('$this->getByType(?)->addPanel($this->getService(?));', array('Tracy\\Bar', $this->prefix('bar')));
     }
 }
 /**
  * @param ClassType $class
  */
 public function afterCompile(ClassType $class)
 {
     $config = $this->validateConfig($this->defaults);
     if ($config['auto'] === TRUE) {
         $method = $class->getMethod('initialize');
         $method->addBody('?::bind($this->getService(?));', [new PhpLiteral(FormBinder::class), $this->prefix('providerFactory')]);
     }
 }
 public function afterCompile(ClassType $class)
 {
     $config = $this->getConfig($this->defaults);
     if ($config['enabled']) {
         $init = $class->getMethod('initialize');
         $init->addBody(Debugger::class . '::setLogger(new ' . SlackLogger::class . '(?, $this->getService(?), ?));', [$config['slackUrl'], $this->prefix('messageFactory'), $config['timeout']]);
     }
 }
Ejemplo n.º 9
0
 /**
  * Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
  *
  * @param Nette\PhpGenerator\ClassType $class
  */
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $builder = $this->getContainerBuilder();
     if ($builder->parameters['debugMode'] && $builder->hasDefinition(self::TRACY_PANEL)) {
         $initialize->addBody($builder->formatPhp('?;', [new Nette\DI\Statement('@Tracy\\Bar::addPanel', ['@' . self::TRACY_PANEL, self::TRACY_PANEL])]));
     }
 }
Ejemplo n.º 10
0
 /**
  * Register UUID type into doctrine.
  * @param ClassType  $container
  */
 public function afterCompile(ClassType $container)
 {
     $initialize = $container->getMethod('initialize');
     $builder = $this->getContainerBuilder();
     $initialize->addBody('?::addType(?, ?);', [Type::class, 'uuid', UuidType::class]);
     foreach ($builder->findByType(Connection::class) as $name => $connection) {
         $initialize->addBody('$this->getService(?)->getDatabasePlatform()->registerDoctrineTypeMapping(?, ?);', [$name, 'uuid', 'uuid']);
     }
 }
Ejemplo n.º 11
0
 /**
  * @param ClassType $class
  * @return void
  */
 public function afterCompile(ClassType $class)
 {
     $config = $this->validateConfig($this->defaults);
     if ($config['siteKey'] != NULL) {
         $method = $class->getMethod('initialize');
         $method->addBody(sprintf('%s::bind(?);', ReCaptchaBinding::class), [$config['siteKey']]);
         $method->addBody(sprintf('%s::factory(?);', ReCaptchaHolder::class), [$config['siteKey']]);
     }
 }
Ejemplo n.º 12
0
 public function afterCompile(PhpGenerator\ClassType $class)
 {
     $config = $this->getConfig(self::$configDefaults);
     $initialize = $class->getMethod('initialize');
     // response syntax highlighting in debug mode
     if ($config['debugMode'] == TRUE) {
         $initialize->addBody('$this->getService(?)->onResponse[] = [new Tripomatic\\NetteApi\\Application\\ResponseProcessors\\ResponseDecorator, "process"];', ['application.application']);
     }
 }
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     if ($this->getConfig()['registerDefaultUrl']) {
         $url = $this->getConfig($this->defaults)['url'];
         $initializeMethod = $class->getMethod('initialize');
         $initializeMethod->addBody('Kdyby\\TranslationControl\\DI\\TranslationControlExtension::registerRoute(
             $this->getService("router"), "' . $url . '"
         );');
     }
 }
Ejemplo n.º 14
0
 public function afterCompile(ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $initialize->addBody('$this->getService("tracy.bar")->addPanel($this->getService("l10n_nette_translator.panel"));');
     $initialize->addBody('$response = $this->getService("l10n_nette_translator.processor")->run();');
     $initialize->addBody('if($response instanceof Nette\\Application\\IResponse) {');
     $initialize->addBody(' $response->send($this->getByType("Nette\\Http\\IRequest"), $this->getByType("Nette\\Http\\IResponse"));');
     $initialize->addBody(' exit();');
     $initialize->addBody('}');
 }
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $config = $this->getConfig();
     $name = $this->prefix('session');
     if ($config['autoStart'] === 'smart') {
         $initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', array($name, $name));
     } elseif ($config['autoStart']) {
         $initialize->addBody('$this->getService(?)->start();', array($name));
     }
 }
 public function afterCompile(ClassType $class)
 {
     $config = $this->getConfig($this->defaults);
     Validators::assertField($config, 'enabled', 'boolean');
     if ($config['enabled']) {
         Validators::assertField($config, 'slackUrl', 'string');
         Validators::assertField($config, 'logUrl', 'string');
         $init = $class->getMethod('initialize');
         $init->addBody(Debugger::class . '::setLogger(new ' . SlackLogger::class . '(?, ?));', [$config['slackUrl'], $config['logUrl']]);
     }
 }
Ejemplo n.º 17
0
 public function afterCompile(ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $config = $this->getConfig($this->defaults);
     Validators::assert($config['messages'], 'array');
     foreach ($config['messages'] as $key => $message) {
         if (!($name = constant($key))) {
             throw new \InvalidArgumentException("Forms message key '{$key}' constant not defined");
         }
         $initialize->addBody('\\Joseki\\Forms\\Messages::$messages[?] = ?;', array($name, $message));
     }
 }
Ejemplo n.º 18
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     if (!empty($this->config['cache'])) {
         $method = $class->getMethod(Nette\DI\Container::getMethodName($this->prefix('router')));
         try {
             $router = serialize(eval($method->getBody()));
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException('Unable to cache router due to error: ' . $e->getMessage(), 0, $e);
         }
         $method->setBody('return unserialize(?);', [$router]);
     }
 }
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $config = $this->getConfig($this->defaults);
     $initialize = $class->getMethod('initialize');
     if ($config['enable'] !== TRUE) {
         return;
     }
     if (in_array($config['method'], [self::REGISTER_ADD, self::REGISTER_ADD_REPLACE], TRUE)) {
         $initialize->addBody('Grifart\\NetteDoctrineDateTimeImmutableTypes\\TypeRegistrar::addImmutableTypes();');
     }
     if (in_array($config['method'], [self::REGISTER_REPLACE, self::REGISTER_ADD_REPLACE], TRUE)) {
         $initialize->addBody('Grifart\\NetteDoctrineDateTimeImmutableTypes\\TypeRegistrar::replaceImmutableTypes();');
     }
 }
Ejemplo n.º 20
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $config = $this->validateConfig($this->defaults);
     foreach ((array) $config['messages'] as $name => $text) {
         if (defined('Nette\\Forms\\Form::' . $name)) {
             $initialize->addBody('Nette\\Forms\\Validator::$messages[Nette\\Forms\\Form::?] = ?;', [$name, $text]);
         } elseif (defined($name)) {
             $initialize->addBody('Nette\\Forms\\Validator::$messages[' . $name . '] = ?;', [$text]);
         } else {
             throw new Nette\InvalidArgumentException('Constant Nette\\Forms\\Form::' . $name . ' or constant ' . $name . ' does not exist.');
         }
     }
 }
 public function afterCompile(ClassType $class)
 {
     $config = $this->getConfig($this->defaults);
     Validators::assertField($config, 'enabled', 'boolean');
     if ($config['enabled']) {
         Validators::assertField($config, 'slackUrl', 'string');
         Validators::assertField($config, 'logUrl', 'string|null');
         Validators::assertField($config, 'channel', 'string|null');
         Validators::assertField($config, 'username', 'string|null');
         Validators::assertField($config, 'icon', 'string|null');
         Validators::assertField($config, 'pretext', 'string|null');
         $init = $class->getMethod('initialize');
         $init->addBody('?::setLogger(new ?(?, ?, ?, ?, ?, ?));', [new PhpLiteral(Debugger::class), new PhpLiteral(SlackLogger::class), $config['slackUrl'], $config['logUrl'], $config['channel'], $config['username'], $config['icon'], $config['pretext']]);
     }
 }
Ejemplo n.º 22
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     if ($this->config['parentClass']) {
         $class->setExtends($this->config['parentClass']);
     }
     $initialize = $class->getMethod('initialize');
     $builder = $this->getContainerBuilder();
     if ($this->debugMode && $this->config['debugger']) {
         Nette\Bridges\DITracy\ContainerPanel::$compilationTime = $this->time;
         $initialize->addBody($builder->formatPhp('?;', [new Nette\DI\Statement('@Tracy\\Bar::addPanel', [new Nette\DI\Statement(Nette\Bridges\DITracy\ContainerPanel::class)])]));
     }
     foreach (array_filter($builder->findByTag('run')) as $name => $on) {
         $initialize->addBody('$this->getService(?);', [$name]);
     }
 }
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     if (!empty($this->config['cache'])) {
         $method = $class->getMethod(Nette\DI\Container::getMethodName($this->prefix('router')));
         try {
             $router = eval($method->getBody());
             if ($router instanceof Nette\Application\Routers\RouteList) {
                 $router->warmupCache();
             }
             $s = serialize($router);
         } catch (\Throwable $e) {
             throw new Nette\DI\ServiceCreationException('Unable to cache router due to error: ' . $e->getMessage(), 0, $e);
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException('Unable to cache router due to error: ' . $e->getMessage(), 0, $e);
         }
         $method->setBody('return unserialize(?);', array($s));
     }
 }
Ejemplo n.º 24
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $config = $this->getConfig();
     if (isset($config['frames']) && $config['frames'] !== TRUE) {
         $frames = $config['frames'];
         if ($frames === FALSE) {
             $frames = 'DENY';
         } elseif (preg_match('#^https?:#', $frames)) {
             $frames = "ALLOW-FROM {$frames}";
         }
         $initialize->addBody('header(?);', array("X-Frame-Options: {$frames}"));
     }
     foreach ($config['headers'] as $key => $value) {
         if ($value != NULL) {
             // intentionally ==
             $initialize->addBody('header(?);', array("{$key}: {$value}"));
         }
     }
 }
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $container = $this->getContainerBuilder();
     $options = $this->config;
     unset($options['bar'], $options['blueScreen']);
     foreach ($options as $key => $value) {
         if ($value !== NULL) {
             $initialize->addBody('Tracy\\Debugger::$? = ?;', array($key, $value));
         }
     }
     if ($this->debugMode) {
         foreach ((array) $this->config['bar'] as $item) {
             $initialize->addBody($container->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments(array($this->prefix('bar'), is_string($item) ? new Nette\DI\Statement($item) : $item))));
         }
     }
     foreach ((array) $this->config['blueScreen'] as $item) {
         $initialize->addBody($container->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments(array($this->prefix('blueScreen'), $item))));
     }
 }
Ejemplo n.º 26
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $container = $this->getContainerBuilder();
     if ($this->debugMode && $this->config['debugger']) {
         $initialize->addBody($container->formatPhp('?;', array(new Nette\DI\Statement('@Tracy\\Bar::addPanel', array(new Nette\DI\Statement('Nette\\Bridges\\DITracy\\ContainerPanel'))))));
     }
     foreach (array_filter($container->findByTag('run')) as $name => $on) {
         $initialize->addBody('$this->getService(?);', array($name));
     }
     if (!empty($this->config['accessors'])) {
         $definitions = $container->getDefinitions();
         ksort($definitions);
         foreach ($definitions as $name => $def) {
             if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
                 $type = $def->getImplement() ?: $def->getClass();
                 $class->addDocument("@property {$type} \${$name}");
             }
         }
     }
 }
Ejemplo n.º 27
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     foreach ($this->getConfig() as $name => $value) {
         if (!is_scalar($value)) {
             throw new Nette\InvalidStateException("Configuration value for directive '{$name}' is not scalar.");
         } elseif ($name === 'include_path') {
             $initialize->addBody('set_include_path(?);', array(str_replace(';', PATH_SEPARATOR, $value)));
         } elseif ($name === 'ignore_user_abort') {
             $initialize->addBody('ignore_user_abort(?);', array($value));
         } elseif ($name === 'max_execution_time') {
             $initialize->addBody('set_time_limit(?);', array($value));
         } elseif ($name === 'date.timezone') {
             $initialize->addBody('date_default_timezone_set(?);', array($value));
         } elseif (function_exists('ini_set')) {
             $initialize->addBody('ini_set(?, ?);', array($name, $value));
         } elseif (ini_get($name) != $value) {
             // intentionally ==
             throw new Nette\NotSupportedException('Required function ini_set() is disabled.');
         }
     }
 }
Ejemplo n.º 28
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     if (!$this->checkTempDir($this->tempDir . '/cache')) {
         $class->getMethod('initialize')->addBody('Nette\\Caching\\Storages\\FileStorage::$useDirectories = FALSE;');
     }
 }
Ejemplo n.º 29
0
 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $class->getMethod('initialize')->addBody('Nette\\Reflection\\AnnotationsParser::setCacheStorage($this->getByType("Nette\\Caching\\IStorage"));')->addBody('Nette\\Reflection\\AnnotationsParser::$autoRefresh = ?;', array($this->debugMode));
 }
Ejemplo n.º 30
0
 /**
  * @param Nette\PhpGenerator\ClassType $classType
  */
 public function afterCompile(Nette\PhpGenerator\ClassType $classType)
 {
     $config = $this->getConfig($this->config);
     $initialize = $classType->getMethod('initialize');
     $initialize->addBody('Vojtys\\Forms\\Typeahead\\TypeaheadExtension::bind(?);', [$config]);
 }