/** * @see Sphpdox\Element.Element::__toString() */ public function __toString() { $name = $this->reflection->getName(); $title = str_replace('\\', '\\\\', $name); //$title = $name; $string = str_repeat('-', strlen($title)) . "\n"; $string .= $title . "\n"; $string .= str_repeat('-', strlen($title)) . "\n\n"; $string .= $this->getNamespaceElement(); if ($this->reflection->isInterface()) { $string .= '.. php:interface:: '; } elseif ($this->reflection->isTrait()) { $string .= '.. php:trait:: '; } else { $string .= '.. php:class:: '; } $string .= $this->reflection->getShortName(); $parser = $this->getParser(); if ($description = $parser->getDescription()) { $string .= "\n\n"; $string .= $this->indent($description, 4); } foreach ($this->getSubElements() as $element) { $e = $element->__toString(); if ($e) { $string .= "\n\n"; $string .= $this->indent($e, 4); } } $string .= "\n\n"; // Finally, fix some whitespace errors $string = preg_replace('/^\\s+$/m', '', $string); $string = preg_replace('/ +$/m', '', $string); return $string; }
protected function getMethods() { $methods = $this->reflection->getMethods(); $classname = $this->reflection->getName(); if ($this->skip_inherited_attr) { $methods = array_filter($methods, function ($prop) use($classname) { return $classname == $prop->getDeclaringClassName(); }); } return array_map(function ($v) { return new MethodElement($v); }, $methods); }
/** * Save AOP proxy to the separate file anr returns the php source code for inclusion * * @param ParsedClass $class Original class reflection * @param string|ClassProxy $child * * @return string */ private function saveProxyToCache($class, $child) { // Without cache we should rewrite original file if (empty($this->options['cacheDir'])) { return $child; } $cacheDirSuffix = '/_proxies/'; $cacheDir = $this->options['cacheDir'] . $cacheDirSuffix; $fileName = str_replace('\\', '/', $class->getName()) . '.php'; $proxyFileName = $cacheDir . $fileName; $dirname = dirname($proxyFileName); if (!file_exists($dirname)) { mkdir($dirname, 0770, true); } $body = '<?php' . PHP_EOL; $namespace = $class->getNamespaceName(); if ($namespace) { $body .= "namespace {$namespace};" . PHP_EOL . PHP_EOL; } foreach ($class->getNamespaceAliases() as $alias => $fqdn) { $body .= "use {$fqdn} as {$alias};" . PHP_EOL; } $body .= $child; file_put_contents($proxyFileName, $body); return 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL; }
/** * Checks the class for possible component and register it in the container if needed * * @param ReflectionClass $class Instance of class reflection * @param ContainerBuilder $container * * @return bool True if component is registered */ protected function checkAndRegisterComponent(ReflectionClass $class, ContainerBuilder $container) { $this->reader->setImports($class->getNamespaceAliases()); $serviceName = str_replace('\\', '.', $class->getName()); $annotation = $this->reader->getClassAnnotation($class, self::ANNOTATION_CLASS); if (!$annotation) { return false; } $definition = $container->register($serviceName, $class->getName()); $constructor = $class->getConstructor(); if ($constructor) { $this->bindConstructorArgs($constructor, $definition, $container); } if ((string) $annotation) { // Make an alias for annotation $container->setAlias($annotation, $serviceName); } return true; }
/** * Gets the annotations applied to a class. * * @param ParsedReflectionClass $class The ReflectionClass of the class from which * the class annotations should be read. * @return array An array of Annotations. */ public function getClassAnnotations(ParsedReflectionClass $class) { $this->parser->setTarget(Target::TARGET_CLASS); return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName()); }
function __construct(IReflectionClass $reflection) { parent::__construct($reflection); $reader = new AnnotationReader(); $this->doctrineAnnotations = $reader->getClassAnnotations(new \ReflectionClass($this->reflection->getName())); }