/** * @param Method $initialize * @param $config * @param $method * @param $defaults */ private function registerSelectBox(Method $initialize, $config, $method, $defaults) { $codes = count($config['codes']) == 0 ? $defaults : (array) $config['codes']; $list = array(); foreach ($codes as $code) { $lowercase = strtolower($code); $list[$lowercase] = $config['prefix'] . $lowercase; } $initialize->addBody(GenericSelectBox::class . '::register(?,?);', array($method, $list)); }
/** * @param \ReflectionClass|string * @return self */ public static function from($from) { $from = $from instanceof \ReflectionClass ? $from : new \ReflectionClass($from); if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) { $class = new static('anonymous'); } else { $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName())); } $class->type = $from->isInterface() ? 'interface' : ($from->isTrait() ? 'trait' : 'class'); $class->final = $from->isFinal() && $class->type === 'class'; $class->abstract = $from->isAbstract() && $class->type === 'class'; $class->implements = $from->getInterfaceNames(); $class->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL; if ($from->getParentClass()) { $class->extends = $from->getParentClass()->getName(); $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames()); } foreach ($from->getProperties() as $prop) { if ($prop->isDefault() && $prop->getDeclaringClass()->getName() === $from->getName()) { $class->properties[$prop->getName()] = Property::from($prop); } } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass()->getName() === $from->getName()) { $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace); } } return $class; }
/** * @param string * @return Method */ public function addMethod($name) { $method = new Method($name); if ($this->type === 'interface') { $method->setVisibility(NULL)->setBody(FALSE); } else { $method->setVisibility('public'); } return $this->methods[$name] = $method->setNamespace($this->namespace); }
private function addCollapsePathsToTracy(Method $init) { $blueScreen = 'Tracy\\Debugger::getBlueScreen()'; $commonDirname = dirname(Nette\Reflection\ClassType::from('Doctrine\\Common\\Version')->getFileName()); $init->addBody($blueScreen . '->collapsePaths[] = ?;', array(dirname(Nette\Reflection\ClassType::from('Kdyby\\Doctrine\\Exception')->getFileName()))); $init->addBody($blueScreen . '->collapsePaths[] = ?;', array(dirname(dirname(dirname(dirname($commonDirname)))))); // this should be vendor/doctrine foreach ($this->proxyAutoloaders as $dir) { $init->addBody($blueScreen . '->collapsePaths[] = ?;', array($dir)); } }
/** * @param \ReflectionMethod $from * @param Code\Method $method * @throws \ReflectionException * @return Code\Method */ public static function expandTypeHints(\ReflectionMethod $from, Code\Method $method) { $parameters = $method->getParameters(); /** @var Code\Parameter[] $parameters */ foreach ($from->getParameters() as $paramRefl) { try { $parameters[$paramRefl->getName()]->setTypeHint($paramRefl->isArray() ? 'array' : ($paramRefl->getClass() ? '\\' . $paramRefl->getClass()->getName() : '')); } catch (\ReflectionException $e) { if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) { $parameters[$paramRefl->getName()]->setTypeHint('\\' . $m[1]); } else { throw $e; } } } $method->setParameters($parameters); if (!$method->getVisibility()) { $method->setVisibility('public'); } return $method; }
private function generateExceptionBody(PhpGenerator\Method $method, $destination, \Exception $exception) { $method->addBody("Assert::exception(function () {\n" . "\t\$this->checkAction(?);\n" . '}, ?);', [$destination, get_class($exception)]); if ($exception instanceof \Nette\Application\BadRequestException) { $method->addBody("Assert::same(?, \$this->getReturnCode());", [$exception->getCode()]); } return $method; }
/** * @return Code\Method */ public function getCode() { return PointcutMethod::expandTypeHints($this->method, Code\Method::from($this->method)); }
private function setupCustom(Method $initialize) { $config = $this->getConfig(); if (isset($config['custom']['parameters'])) { if (!is_array($config['custom']['parameters'])) { throw new \RuntimeException('Invalid custom parameters structure'); } foreach ($config['custom']['parameters'] as $name => $value) { $initialize->addBody('\\VrtakCZ\\NewRelic\\Tracy\\Custom\\Parameters::addParameter(?, ?);', [$name, $value]); } } if (isset($config['custom']['tracers'])) { if (!is_array($config['custom']['tracers'])) { throw new \RuntimeException('Invalid custom tracers structure'); } foreach ($config['custom']['tracers'] as $function) { $initialize->addBody('\\VrtakCZ\\NewRelic\\Tracy\\Custom\\Tracers::addTracer(?);', [$function]); } } }