/** * Registers services on the given app. * * @param Application $app An Application instance */ public function register(Application $app) { if (!isset($app['descriptor.builder'])) { throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing'); } if (!isset($app['serializer'])) { throw new Exception\MissingDependencyException('The serializer object that is used to read the template configuration with is missing'); } $templateDir = __DIR__ . '/../../../data/templates'; // vendored installation if (file_exists(__DIR__ . '/../../../../templates')) { $templateDir = __DIR__ . '/../../../../templates'; } // parameters $app['transformer.template.location'] = $templateDir; $app['linker.substitutions'] = array('phpDocumentor\\Descriptor\\ProjectDescriptor' => array('files'), 'phpDocumentor\\Descriptor\\FileDescriptor' => array('tags', 'classes', 'interfaces', 'traits'), 'phpDocumentor\\Descriptor\\ClassDescriptor' => array('tags', 'parent', 'interfaces', 'constants', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\InterfaceDescriptor' => array('tags', 'parent', 'constants', 'methods'), 'phpDocumentor\\Descriptor\\TraitDescriptor' => array('tags', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\MethodDescriptor' => array('tags', 'arguments'), 'phpDocumentor\\Descriptor\\ArgumentDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\PropertyDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\ConstantDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\Tag\\ParamDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\ReturnDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\SeeDescriptor' => array('reference')); // services $app['compiler'] = $app->share(function ($container) { $compiler = new Compiler(); $compiler->insert(new ElementsIndexBuilder(), ElementsIndexBuilder::COMPILER_PRIORITY); $compiler->insert(new PackageTreeBuilder(), PackageTreeBuilder::COMPILER_PRIORITY); $compiler->insert(new NamespaceTreeBuilder(), NamespaceTreeBuilder::COMPILER_PRIORITY); $compiler->insert($container['linker'], Linker::COMPILER_PRIORITY); $compiler->insert($container['transformer'], Transformer::COMPILER_PRIORITY); $compiler->insert(new Debug($container['monolog'], $container['descriptor.analyzer']), Debug::COMPILER_PRIORITY); return $compiler; }); $app['linker'] = $app->share(function ($app) { return new Linker($app['linker.substitutions']); }); $app['transformer.behaviour.collection'] = $app->share(function () { return new Behaviour\Collection(); }); $app['transformer.routing.queue'] = $app->share(function () { $queue = new Router\Queue(); // TODO: load from app configuration instead of hardcoded $queue->insert(new Router\StandardRouter(), 10000); return $queue; }); $app['transformer.writer.collection'] = $app->share(function ($container) { return new Writer\Collection($container['transformer.routing.queue']); }); $app['transformer.template.collection'] = $app->share(function ($container) { return new Template\Collection($container['transformer.template.location'], $container['serializer']); }); $app['transformer'] = $app->share(function ($container) { $transformer = new Transformer($container['transformer.template.collection'], $container['transformer.writer.collection']); $transformer->setBehaviours($container['transformer.behaviour.collection']); return $transformer; }); $app->command(new TransformCommand($app['descriptor.builder'], $app['transformer'], $app['compiler'])); $app->command(new ListCommand()); }
/** * Tests whether the generateFilename method returns a file according to * the right format. * * @covers phpDocumentor\Transformer\Transformer::generateFilename * * @return void */ public function testGenerateFilename() { // separate the directories with the DIRECTORY_SEPARATOR constant to // prevent failing tests on windows $filename = 'directory' . DIRECTORY_SEPARATOR . 'directory2' . DIRECTORY_SEPARATOR . 'file.php'; $this->assertEquals('directory.directory2.file.html', $this->fixture->generateFilename($filename)); }
/** * Append received transformations. * * @param Transformer $transformer * @param array $received * * @return void */ protected function appendReceivedTransformations(Transformer $transformer, $received) { if (!empty($received)) { $template = new Template('__'); foreach ($received as $transformation) { $template[] = $transformation; } $transformer->getTemplates()->append($template); } }
protected function buildFile(\DOMElement $parent, FileDescriptor $file, Transformer $transformer) { $child = new \DOMElement('file'); $parent->appendChild($child); $path = ltrim($file->getPath(), './'); $child->setAttribute('path', $path); $child->setAttribute('generated-path', $transformer->generateFilename($path)); $child->setAttribute('hash', $file->getHash()); $this->buildDocBlock($child, $file); // add namespace aliases foreach ($file->getNamespaceAliases() as $alias => $namespace) { $alias_obj = new \DOMElement('namespace-alias', $namespace); $child->appendChild($alias_obj); $alias_obj->setAttribute('name', $alias); } /** @var ConstantDescriptor $constant */ foreach ($file->getConstants() as $constant) { $this->buildConstant($child, $constant); } /** @var FunctionDescriptor $function */ foreach ($file->getFunctions() as $function) { $this->buildFunction($child, $function); } /** @var InterfaceDescriptor $interface */ foreach ($file->getInterfaces() as $interface) { $this->buildInterface($child, $interface); } /** @var ClassDescriptor $class */ foreach ($file->getClasses() as $class) { $this->buildClass($child, $class); } // add markers if (count($file->getMarkers()) > 0) { $markers = new \DOMElement('markers'); $child->appendChild($markers); foreach ($file->getMarkers() as $marker) { $marker_obj = new \DOMElement(strtolower($marker['type'])); $markers->appendChild($marker_obj); $marker_obj->appendChild(new \DOMText(trim($marker['message']))); $marker_obj->setAttribute('line', $marker['line']); } } if (count($file->getErrors()) > 0) { $parse_errors = new \DOMElement('parse_markers'); $child->appendChild($parse_errors); /** @var Error $error */ foreach ($file->getAllErrors() as $error) { $this->createErrorEntry($error, $parse_errors); } } // if we want to include the source for each file; append a new // element 'source' which contains a compressed, encoded version // of the source if ($file->getSource()) { $child->appendChild(new \DOMElement('source', base64_encode(gzcompress($file->getSource())))); } }
/** * Load custom defined transformations. * * @param Transformer $transformer * * @todo this is an ugly implementation done for speed of development, should be refactored * * @return void */ public function loadTransformations(Transformer $transformer) { $received = array(); $transformations = $this->getConfigValueFromPath('transformations/transformation'); if (is_array($transformations)) { if (isset($transformations['writer'])) { $received[] = new Transformation(isset($transformations['query']) ? $transformations['query'] : '', $transformations['writer'], isset($transformations['source']) ? $transformations['source'] : '', isset($transformations['artifact']) ? $transformations['artifact'] : ''); } else { foreach ($transformations as $transformation) { if (is_array($transformation)) { $received[] = new Transformation(isset($transformations['query']) ? $transformations['query'] : '', $transformations['writer'], isset($transformations['source']) ? $transformations['source'] : '', isset($transformations['artifact']) ? $transformations['artifact'] : ''); } } } } if (!empty($received)) { $template = new Template('__'); foreach ($received as $transformation) { $template[] = $transformation; } $transformer->getTemplates()->append($template); } }
/** * @covers phpDocumentor\Transformer\Transformer::getDescription */ public function testGetDescription() { $description = $this->fixture->getDescription(); $this->assertNotNull($description); $this->assertLessThanOrEqual(static::$MAX_DESCRIPTION_LENGTH, strlen($description)); }
/** * Registers services on the given app. * * @param Application $app An Application instance. * * @throws Exception\MissingDependencyException if the application does not have a descriptor.builder service. * @throws Exception\MissingDependencyException if the application does not have a serializer service. */ public function register(Application $app) { if (!isset($app['descriptor.builder'])) { throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing'); } if (!isset($app['serializer'])) { throw new Exception\MissingDependencyException('The serializer object that is used to read the template configuration with is missing'); } // parameters $app['linker.substitutions'] = array('phpDocumentor\\Descriptor\\ProjectDescriptor' => array('files'), 'phpDocumentor\\Descriptor\\FileDescriptor' => array('tags', 'classes', 'interfaces', 'traits', 'functions', 'constants'), 'phpDocumentor\\Descriptor\\ClassDescriptor' => array('tags', 'parent', 'interfaces', 'constants', 'properties', 'methods', 'usedTraits'), 'phpDocumentor\\Descriptor\\InterfaceDescriptor' => array('tags', 'parent', 'constants', 'methods'), 'phpDocumentor\\Descriptor\\TraitDescriptor' => array('tags', 'properties', 'methods', 'usedTraits'), 'phpDocumentor\\Descriptor\\FunctionDescriptor' => array('tags', 'arguments'), 'phpDocumentor\\Descriptor\\MethodDescriptor' => array('tags', 'arguments'), 'phpDocumentor\\Descriptor\\ArgumentDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\PropertyDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\ConstantDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\Tag\\ParamDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\ReturnDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\SeeDescriptor' => array('reference'), 'phpDocumentor\\Descriptor\\Type\\CollectionDescriptor' => array('baseType', 'types', 'keyTypes')); // services $app['compiler'] = $app->share(function ($container) { $compiler = new Compiler(); $compiler->insert(new ElementsIndexBuilder(), ElementsIndexBuilder::COMPILER_PRIORITY); $compiler->insert(new MarkerFromTagsExtractor(), MarkerFromTagsExtractor::COMPILER_PRIORITY); $compiler->insert(new ExampleTagsEnricher($container['parser.example.finder']), ExampleTagsEnricher::COMPILER_PRIORITY); $compiler->insert(new PackageTreeBuilder(), PackageTreeBuilder::COMPILER_PRIORITY); $compiler->insert(new NamespaceTreeBuilder(), NamespaceTreeBuilder::COMPILER_PRIORITY); $compiler->insert(new ResolveInlineLinkAndSeeTags($container['transformer.routing.queue']), ResolveInlineLinkAndSeeTags::COMPILER_PRIORITY); $compiler->insert($container['linker'], Linker::COMPILER_PRIORITY); $compiler->insert($container['transformer'], Transformer::COMPILER_PRIORITY); $compiler->insert(new Debug($container['monolog'], $container['descriptor.analyzer']), Debug::COMPILER_PRIORITY); return $compiler; }); $app['linker'] = $app->share(function ($app) { return new Linker($app['linker.substitutions']); }); $app['transformer.behaviour.collection'] = $app->share(function () { return new Behaviour\Collection(); }); $app['transformer.routing.standard'] = $app->share(function ($container) { /** @var ProjectDescriptorBuilder $projectDescriptorBuilder */ $projectDescriptorBuilder = $container['descriptor.builder']; return new Router\StandardRouter($projectDescriptorBuilder); }); $app['transformer.routing.external'] = $app->share(function ($container) { return new Router\ExternalRouter($container['config']); }); $app['transformer.routing.queue'] = $app->share(function ($container) { $queue = new Router\Queue(); // TODO: load from app configuration instead of hardcoded $queue->insert($container['transformer.routing.external'], 10500); $queue->insert($container['transformer.routing.standard'], 10000); return $queue; }); $app['transformer.writer.collection'] = $app->share(function ($container) { return new Writer\Collection($container['transformer.routing.queue']); }); $this->provideTemplatingSystem($app); $app['transformer'] = $app->share(function ($container) { $transformer = new Transformer($container['transformer.template.collection'], $container['transformer.writer.collection']); $transformer->setBehaviours($container['transformer.behaviour.collection']); return $transformer; }); $app->command(new TransformCommand($app['descriptor.builder'], $app['transformer'], $app['compiler'])); $app->command(new ListCommand($app['transformer.template.factory'])); }