pax_global_header00006660000000000000000000000064126266557620014533gustar00rootroot0000000000000052 comment=3365433ea3433b0e5c8f763608f8e63cbedb2a3a ApiGen-4.1.2/000077500000000000000000000000001262665576200127025ustar00rootroot00000000000000ApiGen-4.1.2/LICENSE000066400000000000000000000025321262665576200137110ustar00rootroot00000000000000The MIT License - Copyright (c) 2014 [Tomáš Votruba](http://tomasvotruba.cz) - Copyright (c) 2012 [Olivier Laviale](https://github.com/olvlvl) - Copyright (c) 2011 [Ondřej Nešpor](https://github.com/Andrewsville) - Copyright (c) 2011 [Jaroslav Hanslík](https://github.com/kukulich) - Copyright (c) 2010 [David Grudl](http://davidgrudl.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ApiGen-4.1.2/UPGRADE-4.0.md000066400000000000000000000054531262665576200146210ustar00rootroot00000000000000# Upgrade from 2.x to 4.0 ## Version - Version 3.0 was skipped, because master branch had 3.0-dev alias with code base similar to 2.8. Since then there were many BC breaks, there for naming it 4.0. ## PHP version - Min PHP version was raised: Before: 5.3 After: **5.4** ## Distribution - PEAR support was dropped. **Use PHAR file instead**. Latest stable version can be always found at [apigen.org](http://apigen.org) - New [Release process](wiki/Release-Process) was established. Releasing minor version **every 2 months**. ## Cli commands - [Symfony\Console](https://github.com/symfony/Console) replaced custom CLI solution, thus composer-like approach is used. In particular, you need to call specific command name in first argument. Before: `apigen -s source -d destination` After: `apigen generate -s source -d destination` - New command `self-update` added, to upgrade `.phar` file: Before: *manual update* After: `apigen self-update` ## Cli options - Bool options are off when absent, on when present. Before: `... --tree yes # tree => true` `... --tree no # tree => false` After: `... --tree # tree => true` `... # tree => false` - Options with values now accept multiple formats: Before: `... --access-levels public --access-levels protected` After: `... --access-levels public,protected` or `... --access-levels="public,protected"` or `... --access-levels public --access-levels protected` - Some options were dropped. To see what the available ones are, just run `apigen generate --help`. - `--skip-doc-prefix` was dropped, use `--skip-doc-path` instead - `--allowed-html` was dropped - `--autocomplete` was dropped; autocomplete now works for classes, constants and functions by default - `--report`; use [Php_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for any custom checkstyle - `--wipeout`; now wipes out everytime - `--progressbar`; now always present - `--colors`; now always colors - `--update-check`; now always colors - Some options were renamed and reversed. - `--source-code` was off by default, now it on by default; to turn it off, add `--no-source-code` ## Markup - Docblock markup was changed from Texy to [Markdown Markup](https://github.com/michelf/php-markdown) ## Coding standard - [Zenify\CodingStandard](https://github.com/Zenify/CodingStandard) was introduces. It's based on [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) - Part of continuous integration testing by [Travis CI](http://travis-ci.org). ## Tests - From no tests to unit testing with [PHPUnit](https://github.com/sebastianbergmann/phpunit). With decent coverage of ~80 %. - Part of continuous integration testing by [Travis CI](http://travis-ci.org). ApiGen-4.1.2/bin/000077500000000000000000000000001262665576200134525ustar00rootroot00000000000000ApiGen-4.1.2/bin/apigen000077500000000000000000000022351262665576200146450ustar00rootroot00000000000000#!/usr/bin/env php setDebugMode( ! Tracy\Debugger::$productionMode); $configurator->setTempDirectory($tempDir); $configurator->addConfig(__DIR__ . '/../src/DI/config.neon'); $configurator->addParameters(['rootDir' => __DIR__ . '/..']); $container = $configurator->createContainer(); /** @var ApiGen\Console\Application $application */ $application = $container->getByType('ApiGen\Console\Application'); $application->run(); // Remove temp data ApiGen\FileSystem\FileSystem::deleteDir($tempDir); ApiGen-4.1.2/bin/bootstrap.php000066400000000000000000000005771262665576200162110ustar00rootroot00000000000000=5.4", "nette/application": "~2.2", "nette/bootstrap": "~2.2", "nette/di": "~2.2", "nette/neon": "~2.2", "nette/mail": "~2.2", "nette/robot-loader": "~2.2", "nette/safe-stream": "~2.2", "latte/latte": ">=2.2.0,<2.3.5", "tracy/tracy": "~2.2", "kukulich/fshl": "~2.1", "andrewsville/php-token-reflection": "~1.4", "michelf/php-markdown": "~1.4", "kdyby/events": "~2.0", "symfony/options-resolver": "~2.6.1", "symfony/console": "~2.6", "symfony/yaml": "~2.6", "herrera-io/phar-update": "~2.0", "apigen/theme-default": "~1.0.1", "apigen/theme-bootstrap": "~1.1.2" }, "require-dev": { "mockery/mockery": "~0.9", "herrera-io/box": "~1.6" }, "autoload": { "psr-4": { "ApiGen\\": "src" } }, "autoload-dev": { "psr-4": { "ApiGen\\Tests\\": "tests" } }, "bin": [ "bin/apigen" ], "extra": { "branch-alias": { "dev-master": "4.1.0-dev" } } } ApiGen-4.1.2/generate-api.sh000077500000000000000000000010561262665576200156040ustar00rootroot00000000000000#!/usr/bin/env bash # Build settings REPOSITORY=${REPOSITORY:-"https://${GH_TOKEN}@github.com/ApiGen/api.git"} BRANCH=${BRANCH:-"gh-pages"} BUILD_DIR=${BUILD_DIR:-"/tmp/generate-api"} # Git identity GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME:-"Travis"} GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL:-"travis@travis-ci.org"} # Generate API git clone "${REPOSITORY}" "${BUILD_DIR}" --branch "${BRANCH}" --depth 1 yes | bin/apigen generate -s src -d "${BUILD_DIR}" # Commit & push cd "${BUILD_DIR}" || exit 1 git add . git commit -m "Generate API" git push origin "${BRANCH}" ApiGen-4.1.2/src/000077500000000000000000000000001262665576200134715ustar00rootroot00000000000000ApiGen-4.1.2/src/ApiGen.php000066400000000000000000000004151262665576200153450ustar00rootroot00000000000000charsetDetector = $charsetDetector; } /** * @param string $filePath * @return string */ public function convertFileToUtf($filePath) { $fileEncoding = $this->charsetDetector->detectForFilePath($filePath); $content = file_get_contents($filePath); if ($fileEncoding === Encoding::UTF_8) { return $content; } else { return $this->convertContentToUtf($content, $fileEncoding); } } /** * @param string $content * @param string $fileEncoding * @return string */ private function convertContentToUtf($content, $fileEncoding) { return @iconv($fileEncoding, self::ICONV_UTF_CHARSET, $content); } } ApiGen-4.1.2/src/Charset/CharsetDetector.php000066400000000000000000000036001262665576200206550ustar00rootroot00000000000000 fileEncoding } */ private $detectedFileEncodings = []; /** * @var CharsetOptionsResolver */ private $charsetOptionsResolver; public function __construct(CharsetOptionsResolver $charsetOptionsResolver) { $this->charsetOptionsResolver = $charsetOptionsResolver; $this->charsets = [Encoding::UTF_8]; } public function setCharsets(array $charsets) { $this->charsets = $this->charsetOptionsResolver->resolve($charsets); } /** * @param string $filePath * @return string */ public function detectForFilePath($filePath) { if (isset($this->detectedFileEncodings[$filePath])) { return $this->detectedFileEncodings[$filePath]; } $detectedEncoding = $this->detectForContent(file_get_contents($filePath)); $this->detectedFileEncodings[$filePath] = $detectedEncoding; return $detectedEncoding; } /** * @param string $fileContent * @return string */ private function detectForContent($fileContent) { $fileEncoding = mb_detect_encoding($fileContent, $this->charsets); // mb_detect_encoding can not handle WINDOWS-1250 and returns ISO-8859-1 instead if ($this->isWindows1250($fileEncoding, $fileContent)) { return Encoding::WIN_1250; } return $fileEncoding; } /** * @param string $fileEncoding * @param string $fileContent * @return bool */ private function isWindows1250($fileEncoding, $fileContent) { if ($fileEncoding === Encoding::ISO_8859_1 && preg_match('~[\x7F-\x9F\xBC]~', $fileContent)) { return TRUE; } return FALSE; } } ApiGen-4.1.2/src/Charset/Configuration/000077500000000000000000000000001262665576200176715ustar00rootroot00000000000000ApiGen-4.1.2/src/Charset/Configuration/CharsetOptionsResolver.php000066400000000000000000000053101262665576200250700ustar00rootroot00000000000000optionsResolverFactory = $optionsResolverFactory; } /** * @return string[] */ public function getDefaults() { return [self::CHARSETS => [Encoding::UTF_8]]; } /** * @param string[] $options * @return string[] */ public function resolve(array $options = []) { $this->resolver = $this->optionsResolverFactory->create(); $this->setDefaults(); $this->setNormalizers(); $options = $this->normalizeInput($options); $options = $this->resolver->resolve($options); return $this->normalizeOutput($options); } private function setDefaults() { $this->resolver->setDefaults($this->getDefaults()); } private function setNormalizers() { $this->resolver->setNormalizers([ self::CHARSETS => function (Options $options, $value) { $value = array_map('strtoupper', $value); $value = $this->replaceWin1250WithIso($value); $value = $this->filterSupportedCharsets($value); $value = $this->moveUtfFirst($value); return $value; } ]); } /** * @return array */ private function replaceWin1250WithIso(array $charsets) { if (($key = array_search(Encoding::WIN_1250, $charsets)) !== FALSE) { $charsets[$key] = Encoding::ISO_8859_1; } return $charsets; } /** * @return array */ private function filterSupportedCharsets(array $charsets) { $supportedEncodingList = array_map('strtoupper', mb_list_encodings()); return array_intersect($charsets, $supportedEncodingList); } /** * @return array */ private function moveUtfFirst(array $charsets) { if (($key = array_search(Encoding::UTF_8, $charsets)) !== FALSE) { unset($charsets[$key]); } array_unshift($charsets, Encoding::UTF_8); return $charsets; } /** * @return array */ private function normalizeInput(array $options) { if (isset($options[self::CHARSETS])) { return $options; } return [self::CHARSETS => $options]; } /** * @return string[] */ private function normalizeOutput(array $options) { return $options[self::CHARSETS]; } } ApiGen-4.1.2/src/Charset/Encoding.php000066400000000000000000000005311262665576200173200ustar00rootroot00000000000000dashFormat($name); return parent::addOption($name, $shortcut, $mode, $description, $default); } /** * @param string $name * @return string */ private function dashFormat($name) { return preg_replace_callback('~([A-Z])~', function ($matches) { return '-' . strtolower($matches[1]); }, $name); } } ApiGen-4.1.2/src/Command/GenerateCommand.php000066400000000000000000000200461262665576200206130ustar00rootroot00000000000000configuration = $configuration; $this->scanner = $scanner; $this->parser = $parser; $this->parserResult = $parserResult; $this->generatorQueue = $generatorQueue; $this->fileSystem = $fileSystem; $this->themeResources = $themeResources; $this->io = $io; } protected function configure() { $this->setName('generate') ->setDescription('Generate API documentation') ->addOption(CO::SOURCE, 's', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Dirs or files documentation is generated for.') ->addOption(CO::DESTINATION, 'd', InputOption::VALUE_REQUIRED, 'Target dir for documentation.') ->addOption(CO::ACCESS_LEVELS, NULL, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Access levels of included method and properties.', [COR::AL_PUBLIC, COR::AL_PROTECTED]) ->addOption(CO::ANNOTATION_GROUPS, NULL, InputOption::VALUE_REQUIRED, 'Generate page with elements with specific annotation.') ->addOption(CO::BASE_URL, NULL, InputOption::VALUE_REQUIRED, 'Base url used for sitemap (useful for public doc).') ->addOption(CO::CONFIG, NULL, InputOption::VALUE_REQUIRED, 'Custom path to apigen.neon config file.', getcwd() . '/apigen.neon') ->addOption(CO::GOOGLE_CSE_ID, NULL, InputOption::VALUE_REQUIRED, 'Custom google search engine id (for search box).') ->addOption(CO::GOOGLE_ANALYTICS, NULL, InputOption::VALUE_REQUIRED, 'Google Analytics tracking code.') ->addOption(CO::DEBUG, NULL, InputOption::VALUE_NONE, 'Turn on debug mode.') ->addOption(CO::DEPRECATED, NULL, InputOption::VALUE_NONE, 'Generate documentation for elements marked as @deprecated') ->addOption(CO::DOWNLOAD, NULL, InputOption::VALUE_NONE, 'Add link to ZIP archive of documentation.') ->addOption(CO::EXTENSIONS, NULL, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Scanned file extensions.', ['php']) ->addOption(CO::EXCLUDE, NULL, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Directories and files matching this mask will not be parsed (e.g. */tests/*).') ->addOption(CO::GROUPS, NULL, InputOption::VALUE_REQUIRED, 'The way elements are grouped in menu.', 'auto') ->addOption(CO::CHARSET, NULL, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Charset of scanned files.') ->addOption(CO::MAIN, NULL, InputOption::VALUE_REQUIRED, 'Elements with this name prefix will be first in tree.') ->addOption(CO::INTERNAL, NULL, InputOption::VALUE_NONE, 'Include elements marked as @internal.') ->addOption(CO::PHP, NULL, InputOption::VALUE_NONE, 'Generate documentation for PHP internal classes.') ->addOption(CO::SKIP_DOC_PATH, NULL, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Files matching this mask will be included in class tree,' . ' but will not create a link to their documentation.') ->addOption(CO::NO_SOURCE_CODE, NULL, InputOption::VALUE_NONE, 'Do not generate highlighted source code for elements.') ->addOption(CO::TEMPLATE_THEME, NULL, InputOption::VALUE_REQUIRED, 'ApiGen template theme name.', 'default') ->addOption(CO::TEMPLATE_CONFIG, NULL, InputOption::VALUE_REQUIRED, 'Your own template config, has higher priority ' . CO::TEMPLATE_THEME . '.') ->addOption(CO::TITLE, NULL, InputOption::VALUE_REQUIRED, 'Title of generated documentation.') ->addOption(CO::TODO, NULL, InputOption::VALUE_NONE, 'Generate documentation for elements marked as @todo.') ->addOption(CO::TREE, NULL, InputOption::VALUE_NONE, 'Generate tree view of classes, interfaces, traits and exceptions.'); } protected function execute(InputInterface $input, OutputInterface $output) { try { $options = $this->prepareOptions($input->getOptions()); $this->scanAndParse($options); $this->generate($options); return 0; } catch (\Exception $e) { $output->writeln(PHP_EOL . '' . $e->getMessage() . ''); return 1; } } private function scanAndParse(array $options) { $this->io->writeln('Scanning sources and parsing'); $files = $this->scanner->scan($options[CO::SOURCE], $options[CO::EXCLUDE], $options[CO::EXTENSIONS]); $this->parser->parse($files); $this->reportParserErrors($this->parser->getErrors()); $stats = $this->parserResult->getDocumentedStats(); $this->io->writeln(sprintf( 'Found %d classes, %d constants and %d functions', $stats['classes'], $stats['constants'], $stats['functions'] )); } private function generate(array $options) { $this->prepareDestination($options[CO::DESTINATION]); $this->io->writeln('Generating API documentation'); $this->generatorQueue->run(); } private function reportParserErrors(array $errors) { /** @var FileProcessingException[] $errors */ foreach ($errors as $error) { /** @var \Exception[] $reasons */ $reasons = $error->getReasons(); if (count($reasons) && isset($reasons[0])) { $this->io->writeln("Parse error: " . $reasons[0]->getMessage() . ""); } } } /** * @return array */ private function prepareOptions(array $cliOptions) { $cliOptions = $this->convertDashKeysToCamel($cliOptions); $configFile = $cliOptions[CO::CONFIG]; $options = $cliOptions; if (file_exists($configFile)) { // get reader by file extension $configFileOptions = ConfigurationReader::getReader($configFile)->read(); $options = array_merge($options, $configFileOptions); } return $this->configuration->resolveOptions($options); } /** * @return array */ private function convertDashKeysToCamel(array $options) { foreach ($options as $key => $value) { $camelKey = $this->camelFormat($key); if ($key !== $camelKey) { $options[$camelKey] = $value; unset($options[$key]); } } return $options; } /** * @param string $name * @return string */ private function camelFormat($name) { return preg_replace_callback('~-([a-z])~', function ($matches) { return strtoupper($matches[1]); }, $name); } /** * @param string $destination */ private function prepareDestination($destination) { $this->cleanDestinationWithCaution($destination); $this->themeResources->copyToDestination($destination); } /** * @param string $destination */ private function cleanDestinationWithCaution($destination) { if ( ! $this->fileSystem->isDirEmpty($destination)) { if ($this->io->ask('Destination is not empty. Do you want to erase it?', TRUE)) { $this->fileSystem->purgeDir($destination); } } } } ApiGen-4.1.2/src/Command/SelfUpdateCommand.php000066400000000000000000000026521262665576200211200ustar00rootroot00000000000000setName('self-update') ->setAliases(['selfupdate']) ->setDescription('Updates apigen.phar to the latest available version'); } /** * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { try { $updateManager = $this->createUpdateManager(); $version = $this->getApplication()->getVersion(); if ($updateManager->update($version, FALSE, TRUE)) { $output->writeln('Updated to latest version.'); } else { $output->writeln('Already up-to-date.'); } return 0; } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); return 1; } } /** * @return Manager */ private function createUpdateManager() { return new Manager(Manifest::loadFile(self::MANIFEST_URL)); } } ApiGen-4.1.2/src/Configuration/000077500000000000000000000000001262665576200163005ustar00rootroot00000000000000ApiGen-4.1.2/src/Configuration/Configuration.php000066400000000000000000000052241262665576200216230ustar00rootroot00000000000000configurationOptionsResolver = $configurationOptionsResolver; } /** * @return array */ public function resolveOptions(array $options) { $options = $this->unsetConsoleOptions($options); $this->options = $options = $this->configurationOptionsResolver->resolve($options); $this->onOptionsResolve($options); return $options; } /** * @param string $name * @return mixed|NULL */ public function getOption($name) { if (isset($this->getOptions()[$name])) { return $this->getOptions()[$name]; } return NULL; } /** * @return array */ public function getOptions() { if ($this->options === NULL) { $this->resolveOptions([]); } return $this->options; } /** * @param int $namespaceCount * @param int $packageCount * @return bool */ public function areNamespacesEnabled($namespaceCount, $packageCount) { if ($this->getOption(CO::GROUPS) === self::GROUPS_NAMESPACES) { return TRUE; } if ($this->getOption(CO::GROUPS) === self::GROUPS_AUTO && ($namespaceCount > 0 || $packageCount === 0)) { return TRUE; } return FALSE; } /** * @param bool $areNamespacesEnabled * @return bool */ public function arePackagesEnabled($areNamespacesEnabled) { if ($this->getOption(CO::GROUPS) === self::GROUPS_PACKAGES) { return TRUE; } elseif ($this->getOption(CO::GROUPS) === self::GROUPS_AUTO && ($areNamespacesEnabled === FALSE)) { return TRUE; } return FALSE; } /** * @return string */ public function getZipFileName() { $webalizedTitle = Strings::webalize($this->getOption(CO::TITLE), NULL, FALSE); return ($webalizedTitle ? '-' : '') . 'API-documentation.zip'; } /** * @return array */ private function unsetConsoleOptions(array $options) { unset($options[CO::CONFIG], $options['help'], $options['version'], $options['quiet']); return $options; } } ApiGen-4.1.2/src/Configuration/ConfigurationOptions.php000066400000000000000000000022271262665576200231770ustar00rootroot00000000000000 [], CO::ACCESS_LEVELS => [], CO::BASE_URL => '', CO::CONFIG => '', CO::DEBUG => FALSE, CO::DEPRECATED => FALSE, CO::DESTINATION => NULL, CO::DOWNLOAD => FALSE, CO::EXCLUDE => [], CO::EXTENSIONS => [], CO::GOOGLE_CSE_ID => '', CO::GOOGLE_ANALYTICS => '', CO::GROUPS => '', CO::CHARSET => [], CO::MAIN => '', CO::INTERNAL => FALSE, CO::PHP => FALSE, CO::SKIP_DOC_PATH => [], CO::SOURCE => [], CO::NO_SOURCE_CODE => FALSE, CO::TEMPLATE => NULL, CO::TEMPLATE_CONFIG => NULL, CO::TEMPLATE_THEME => self::TEMPLATE_THEME_DEFAULT, CO::TITLE => '', CO::TODO => FALSE, CO::TREE => TRUE, // helpers CO::VISIBILITY_LEVELS => [], CO::SOURCE_CODE => '' ]; /** * @var ThemeConfigFactory */ private $themeConfigFactory; /** * @var OptionsResolver */ private $resolver; /** * @var OptionsResolverFactory */ private $optionsResolverFactory; /** * @var ThemeConfigPathResolver */ private $themeConfigPathResolver; public function __construct( ThemeConfigFactory $themeConfigFactory, OptionsResolverFactory $optionsResolverFactory, ThemeConfigPathResolver $themeConfigPathResolver ) { $this->themeConfigFactory = $themeConfigFactory; $this->optionsResolverFactory = $optionsResolverFactory; $this->themeConfigPathResolver = $themeConfigPathResolver; } /** * @return array */ public function resolve(array $options) { $this->resolver = $this->optionsResolverFactory->create(); $this->setDefaults(); $this->setRequired(); $this->setAllowedValues(); $this->setNormalizers(); return $this->resolver->resolve($options); } private function setDefaults() { $this->resolver->setDefaults($this->defaults); $this->resolver->setDefaults([ CO::VISIBILITY_LEVELS => function (Options $options) { return $this->getAccessLevelForReflections($options[CO::ACCESS_LEVELS]); }, CO::TEMPLATE => function (Options $options) { if ( ! $options[CO::TEMPLATE_CONFIG]) { $config = $this->getTemplateConfigPathFromTheme($options[CO::TEMPLATE_THEME]); } else { $config = $options[CO::TEMPLATE_CONFIG]; } return $this->themeConfigFactory->create($config)->getOptions(); } ]); } /** * @return int */ private function getAccessLevelForReflections(array $options) { $accessLevel = NULL; if (in_array(self::AL_PUBLIC, $options)) { $accessLevel |= ReflectionProperty::IS_PUBLIC; } if (in_array(self::AL_PROTECTED, $options)) { $accessLevel |= ReflectionProperty::IS_PROTECTED; } if (in_array(self::AL_PRIVATE, $options)) { $accessLevel |= ReflectionProperty::IS_PRIVATE; } return $accessLevel; } private function setRequired() { $this->resolver->setRequired([ CO::SOURCE, CO::DESTINATION ]); } private function setAllowedValues() { $this->resolver->addAllowedValues(CO::DESTINATION, function ($destination) { return $this->allowedValuesForDestination($destination); }); $this->resolver->addAllowedValues(CO::SOURCE, function ($source) { return $this->allowedValuesForSource($source); }); $this->resolver->addAllowedValues(CO::TEMPLATE_CONFIG, function ($value) { if ($value && ! is_file($value)) { throw new ConfigurationException("Template config '$value' was not found"); } return TRUE; }); } private function setNormalizers() { $this->resolver->setNormalizers([ CO::ANNOTATION_GROUPS => function (Options $options, $value) { $value = (array) $value; if ($options[CO::DEPRECATED]) { $value[] = CO::DEPRECATED; } if ($options[CO::TODO]) { $value[] = CO::TODO; } return array_unique($value); }, CO::DESTINATION => function (Options $options, $value) { return FileSystem::getAbsolutePath($value); }, CO::BASE_URL => function (Options $options, $value) { return rtrim($value, '/'); }, CO::SKIP_DOC_PATH => function (Options $options, $value) { $value = (array) $value; foreach ($value as $key => $source) { $value[$key] = FileSystem::getAbsolutePath($source); } return $value; }, CO::SOURCE => function (Options $options, $value) { if ( ! is_array($value)) { $value = [$value]; } foreach ($value as $key => $source) { $value[$key] = FileSystem::getAbsolutePath($source); } return $value; }, CO::SOURCE_CODE => function (Options $options) { return ! $options[CO::NO_SOURCE_CODE]; }, CO::TEMPLATE_CONFIG => function (Options $options, $value) { return FileSystem::getAbsolutePath($value); } ]); } /** * @param string $theme * @return string */ private function getTemplateConfigPathFromTheme($theme) { if ($theme === self::TEMPLATE_THEME_DEFAULT) { return $this->themeConfigPathResolver->resolve('/vendor/apigen/theme-default/src/config.neon'); } elseif ($theme === self::TEMPLATE_THEME_BOOTSTRAP) { return $this->themeConfigPathResolver->resolve('/vendor/apigen/theme-bootstrap/src/config.neon'); } throw new ConfigurationException(CO::TEMPLATE_THEME . ' ' . $theme . ' is not supported.'); } /** * @param string $destination * @return bool */ private function allowedValuesForDestination($destination) { if ( ! $destination) { throw new ConfigurationException("Destination is not set. Use '-d ' or config to set it"); } elseif ( ! is_dir($destination)) { mkdir($destination, 0755, TRUE); } if ( ! is_writable($destination)) { throw new ConfigurationException("Destination '$destination' is not writable"); } return TRUE; } /** * @param string|array $source * @return bool */ private function allowedValuesForSource($source) { if ( ! $source) { throw new ConfigurationException("Source is not set. Use '-s ' or config to set it"); } elseif ( ! is_array($source)) { $source = [$source]; } foreach ($source as $singleSource) { if ( ! file_exists($singleSource)) { throw new ConfigurationException("Source '$singleSource' does not exist"); } } return TRUE; } } ApiGen-4.1.2/src/Configuration/Exceptions/000077500000000000000000000000001262665576200204215ustar00rootroot00000000000000ApiGen-4.1.2/src/Configuration/Exceptions/ConfigurationException.php000066400000000000000000000006101262665576200256150ustar00rootroot00000000000000validatePath($path); $this->path = $path; } /** * @param string $path */ protected function validatePath($path) { if ( ! file_exists($path)) { throw new MissingFileException($path . ' could not be found'); } if ( ! is_readable($path)) { throw new FileNotReadableException($path . ' is not readable.'); } } } ApiGen-4.1.2/src/Configuration/Readers/Exceptions/000077500000000000000000000000001262665576200220065ustar00rootroot00000000000000ApiGen-4.1.2/src/Configuration/Readers/Exceptions/FileNotReadableException.php000066400000000000000000000005251262665576200273600ustar00rootroot00000000000000path); return (array) Neon::decode($json); } } ApiGen-4.1.2/src/Configuration/Readers/ReaderFactory.php000066400000000000000000000010751262665576200231330ustar00rootroot00000000000000path)); } } ApiGen-4.1.2/src/Configuration/Theme/000077500000000000000000000000001262665576200173425ustar00rootroot00000000000000ApiGen-4.1.2/src/Configuration/Theme/ThemeConfig.php000066400000000000000000000023071262665576200222450ustar00rootroot00000000000000filePath = $filePath; $this->themeConfigOptionsResolver = $themeConfigOptionsResolver; } /** * @return mixed[] */ public function getOptions() { if ($this->options === NULL) { $file = new NeonFile($this->filePath); $values = $file->read(); $values['templatesPath'] = dirname($this->filePath); $this->options = $this->themeConfigOptionsResolver->resolve($values); } return $this->options; } } ApiGen-4.1.2/src/Configuration/Theme/ThemeConfigFactory.php000066400000000000000000000005621262665576200235760ustar00rootroot00000000000000 '', 'options' => [ 'elementDetailsCollapsed' => TRUE, 'elementsOrder' => 'natural' # or: alphabetical ], TCO::RESOURCES => [ 'resources' => 'resources' ], TCO::TEMPLATES => [ TCO::OVERVIEW => [ 'filename' => 'index.html', 'template' => 'overview.latte' ], TCO::COMBINED => [ 'filename' => 'resources/combined.js', 'template' => 'combined.js.latte' ], TCO::ELEMENT_LIST => [ 'filename' => 'elementlist.js', 'template' => 'elementlist.js.latte' ], TCO::E404 => [ 'filename' => '404.html', 'template' => '404.latte' ], TCO::PACKAGE => [ 'filename' => 'package-%s.html', 'template' => 'package.latte' ], TCO::T_NAMESPACE => [ 'filename' => 'namespace-%s.html', 'template' => 'namespace.latte' ], TCO::T_CLASS => [ 'filename' => 'class-%s.html', 'template' => 'class.latte' ], TCO::T_CONSTANT => [ 'filename' => 'constant-%s.html', 'template' => 'constant.latte' ], TCO::T_FUNCTION => [ 'filename' => 'function-%s.html', 'template' => 'function.latte' ], TCO::ANNOTATION_GROUP => [ 'filename' => 'annotation-group-%s.html', 'template' => 'annotation-group.latte' ], TCO::SOURCE => [ 'filename' => 'source-%s.html', 'template' => 'source.latte' ], TCO::TREE => [ 'filename' => 'tree.html', 'template' => 'tree.latte' ], TCO::SITEMAP => [ 'filename' => 'sitemap.xml', 'template' => 'sitemap.xml.latte' ], TCO::OPENSEARCH => [ 'filename' => 'opensearch.xml', 'template' => 'opensearch.xml.latte' ], TCO::ROBOTS => [ 'filename' => 'robots.txt', 'template' => 'robots.txt.latte' ] ], TCO::TEMPLATES_PATH => '' ]; /** * @var OptionsResolver */ private $resolver; /** * @var OptionsResolverFactory */ private $optionsResolverFactory; public function __construct(OptionsResolverFactory $optionsResolverFactory) { $this->optionsResolverFactory = $optionsResolverFactory; } /** * @return array */ public function resolve(array $options) { $this->resolver = $this->optionsResolverFactory->create(); $this->setDefaults(); $this->setNormalizers(); return $this->resolver->resolve($options); } private function setDefaults() { $this->resolver->setDefaults($this->defaults); } private function setNormalizers() { $this->resolver->setNormalizers([ TCO::RESOURCES => function (Options $options, $resources) { $absolutizedResources = []; foreach ($resources as $key => $resource) { $key = $options['templatesPath'] . '/' . $key; $absolutizedResources[$key] = $resource; } return $absolutizedResources; }, TCO::TEMPLATES => function (Options $options, $value) { return $this->makeTemplatePathsAbsolute($value, $options); } ]); } /** * @return array */ private function makeTemplatePathsAbsolute(array $value, Options $options) { foreach ($value as $type => $settings) { $filePath = $options[TCO::TEMPLATES_PATH] . '/' . $settings['template']; $value[$type]['template'] = $filePath; $this->validateFileExistence($filePath, $type); } return $value; } /** * @param string $file * @param string $type */ private function validateFileExistence($file, $type) { if ( ! is_file($file)) { throw new ConfigurationException("Template for $type was not found in $file"); } } } ApiGen-4.1.2/src/Console/000077500000000000000000000000001262665576200150735ustar00rootroot00000000000000ApiGen-4.1.2/src/Console/Application.php000066400000000000000000000041001262665576200200420ustar00rootroot00000000000000setMemoryLimitTo('1024M'); } /** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $this->onRun($input, $output); return parent::doRun($input, $output); } /** * {@inheritdoc} */ public function run(InputInterface $input = NULL, OutputInterface $output = NULL) { return parent::run(new LiberalFormatArgvInput, $output); } public function setEventManager(EventManager $eventManager) { $this->eventManager = $eventManager; } /** * {@inheritdoc} */ protected function getDefaultInputDefinition() { return new InputDefinition([ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), new InputOption('help', 'h', InputOption::VALUE_NONE, 'Display this help message.'), new InputOption('quiet', 'q', InputOption::VALUE_NONE, 'Do not output any message.'), new InputOption('version', 'V', InputOption::VALUE_NONE, 'Display this application version.') ]); } private function onRun(InputInterface $input, OutputInterface $output) { $this->eventManager->dispatchEvent(__METHOD__, new EventArgsList([$input, $output])); } } ApiGen-4.1.2/src/Console/IO.php000066400000000000000000000032631262665576200161170ustar00rootroot00000000000000input = new ArrayInput([]); $this->output = new NullOutput; $this->helperSet = $helperSet; } /** * @return InputInterface */ public function getInput() { return $this->input; } public function setInput(InputInterface $input) { $this->input = $input; } /** * @return OutputInterface */ public function getOutput() { return $this->output; } public function setOutput(OutputInterface $output) { $this->output = $output; } /** * {@inheritdoc} */ public function writeln($message) { return $this->output->writeln($message); } /** * {@inheritdoc} */ public function ask($question, $default = NULL) { /** @var QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new ConfirmationQuestion($question, $default); return $helper->ask($this->input, $this->output, $question); } } ApiGen-4.1.2/src/Console/IOInterface.php000066400000000000000000000007141262665576200177360ustar00rootroot00000000000000 $value) { $options[$key] = $this->removeEqualsSign($value); $options[$key] = $this->splitByComma($value); } return $options; } /** * @param string $name * @return mixed */ public function getOption($name) { $this->options = $this->getOptions(); return parent::getOption($name); } /** * @param array|string $value * @return array|string */ private function removeEqualsSign($value) { if (is_array($value)) { array_walk($value, function (&$singleValue) { $singleValue = ltrim($singleValue, '='); }); } else { $value = ltrim($value, '='); } return $value; } /** * @param mixed $value * @return mixed */ private function splitByComma($value) { if (is_array($value)) { array_walk($value, function (&$singleValue) { $singleValue = $this->splitByCommaIfHasAny($singleValue); }); if (count($value) && is_array($value[0])) { return $value[0]; } } else { $value = $this->splitByCommaIfHasAny($value); } return $value; } /** * @param string $value * @return bool */ private function containsComma($value) { return strpos($value, ',') !== FALSE; } /** * @param string $value * @return string|array */ private function splitByCommaIfHasAny($value) { if ($this->containsComma($value)) { return explode(',', $value); } return $value; } } ApiGen-4.1.2/src/Console/ProgressBar.php000066400000000000000000000030331262665576200200340ustar00rootroot00000000000000consoleIO = $consoleIO; } /** * @param int $maximum */ public function init($maximum = 1) { $this->bar = new ProgressBarHelper($this->consoleIO->getOutput(), $maximum); $this->bar->setFormat($this->getBarFormat()); $this->bar->start(); } /** * @param int $increment */ public function increment($increment = 1) { if ($this->bar === NULL) { return; } $this->bar->advance($increment); if ($this->bar->getProgress() === $this->bar->getMaxSteps()) { $this->consoleIO->getOutput()->writeln(' - Finished!'); } } /** * @return string */ private function getBarFormat() { if ($this->getDebugOption()) { return 'debug'; } else { return '%percent:3s% %'; } } /** * @return bool */ private function getDebugOption() { if ($this->consoleIO->getInput() && $this->consoleIO->getInput()->hasOption(CO::DEBUG)) { return $this->consoleIO->getInput()->getOption(CO::DEBUG); } else { return FALSE; } } } ApiGen-4.1.2/src/Console/Question/000077500000000000000000000000001262665576200167025ustar00rootroot00000000000000ApiGen-4.1.2/src/Console/Question/ConfirmationQuestion.php000066400000000000000000000011351262665576200235730ustar00rootroot00000000000000%s [%s] ', parent::getQuestion(), $this->getDefault() === TRUE ? 'yes' : 'no' ); } } ApiGen-4.1.2/src/DI/000077500000000000000000000000001262665576200137655ustar00rootroot00000000000000ApiGen-4.1.2/src/DI/ApiGenExtension.php000066400000000000000000000047471262665576200175520ustar00rootroot00000000000000loadServicesFromConfig(); $this->setupTemplating(); } public function beforeCompile() { $builder = $this->getContainerBuilder(); $builder->prepareClassList(); $this->setupConsole(); $this->setupTemplatingFilters(); $this->setupGeneratorQueue(); } private function loadServicesFromConfig() { $builder = $this->getContainerBuilder(); $config = $this->loadFromFile(__DIR__ . '/apigen.services.neon'); $this->compiler->parseServices($builder, $config); } private function setupTemplating() { $builder = $this->getContainerBuilder(); $builder->addDefinition($this->prefix('latteFactory')) ->setClass('Latte\Engine') ->addSetup('setTempDirectory', [$builder->expand('%tempDir%/cache/latte')]); } private function setupConsole() { $builder = $this->getContainerBuilder(); $application = $builder->getDefinition($builder->getByType('ApiGen\Console\Application')); foreach (array_keys($builder->findByTag(self::TAG_CONSOLE_COMMAND)) as $serviceName) { $className = $builder->getDefinition($serviceName)->getClass(); if ( ! $this->isPhar() && $className === 'ApiGen\Command\SelfUpdateCommand') { continue; } $application->addSetup('add', ['@' . $serviceName]); } } /** * @return bool */ private function isPhar() { return substr(__FILE__, 0, 5) === 'phar:'; } private function setupTemplatingFilters() { $builder = $this->getContainerBuilder(); $latteFactory = $builder->getDefinition($builder->getByType('Latte\Engine')); foreach (array_keys($builder->findByTag(self::TAG_LATTE_FILTER)) as $serviceName) { $latteFactory->addSetup('addFilter', [NULL, ['@' . $serviceName, 'loader']]); } } private function setupGeneratorQueue() { $builder = $this->getContainerBuilder(); $generator = $builder->getDefinition($builder->getByType('ApiGen\Generator\GeneratorQueue')); foreach (array_keys($builder->findByTag(self::TAG_TEMPLATE_GENERATOR)) as $serviceName) { $generator->addSetup('addToQueue', ['@' . $serviceName]); } } } ApiGen-4.1.2/src/DI/CharsetConvertorExtension.php000066400000000000000000000013641262665576200216720ustar00rootroot00000000000000getContainerBuilder(); $builder->addDefinition($this->prefix('convertor')) ->setClass('ApiGen\Charset\CharsetConvertor'); $builder->addDefinition($this->prefix('detector')) ->setClass('ApiGen\Charset\CharsetDetector'); $builder->addDefinition($this->prefix('charsetOptionsResolver')) ->setClass('ApiGen\Charset\Configuration\CharsetOptionsResolver'); } } ApiGen-4.1.2/src/DI/ParserExtension.php000066400000000000000000000015771262665576200176410ustar00rootroot00000000000000getContainerBuilder(); $config = $this->loadFromFile(__DIR__ . '/parser.services.neon'); $this->compiler->parseServices($builder, $config); $backend = $builder->addDefinition($this->prefix('backend')) ->setClass('ApiGen\Parser\Broker\Backend'); $builder->addDefinition($this->prefix('broker')) ->setClass('TokenReflection\Broker') ->setArguments([ $backend, Broker::OPTION_DEFAULT & ~(Broker::OPTION_PARSE_FUNCTION_BODY | Broker::OPTION_SAVE_TOKEN_STREAM) ]); } } ApiGen-4.1.2/src/DI/apigen.services.neon000066400000000000000000000104041262665576200177320ustar00rootroot00000000000000services: # commands - {class: ApiGen\Command\GenerateCommand, tags: [console.command]} - {class: ApiGen\Command\SelfUpdateCommand, tags: [console.command]} # configuration - ApiGen\Configuration\Configuration - ApiGen\Configuration\ConfigurationOptionsResolver - ApiGen\Configuration\OptionsResolverFactory - implement: ApiGen\Configuration\Theme\ThemeConfigFactory parameters: [filePath] arguments: [%filePath%] - ApiGen\Configuration\Theme\ThemeConfigOptionsResolver # console - class: ApiGen\Console\Application setup: - setEventManager - ApiGen\Console\IO - ApiGen\Console\ProgressBar - Symfony\Component\Console\Helper\ProgressHelper - Symfony\Component\Console\Helper\QuestionHelper - class: Symfony\Component\Console\Helper\HelperSet setup: - set(@Symfony\Component\Console\Helper\ProgressHelper, 'progress') - set(@Symfony\Component\Console\Helper\QuestionHelper, 'question') # elements - ApiGen\Generator\Resolvers\ElementResolver - ApiGen\Generator\Resolvers\RelativePathResolver # events - {class: ApiGen\Events\ProgressBarIncrement, tags: [kdyby.subscriber]} - {class: ApiGen\Events\InjectConfig, tags: [kdyby.subscriber]} - {class: ApiGen\Events\SetIoOnConsoleRun, tags: [kdyby.subscriber]} # filesystem - ApiGen\FileSystem\FileSystem - ApiGen\FileSystem\ZipArchiveGenerator # generator - ApiGen\Scanner\Scanner - ApiGen\Generator\GeneratorQueue # intentionally first to collect output from other generators - {class: ApiGen\Generator\TemplateGenerators\ZipGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\CombinedGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\AnnotationGroupsGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\E404Generator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\ElementListGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\OpensearchGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\OverviewGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\SitemapGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\SourceCodeGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\TreeGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\RobotsGenerator, tags: [template.generator]} # elements - {class: ApiGen\Generator\TemplateGenerators\ClassElementGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\ConstantElementGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\FunctionElementGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\NamespaceGenerator, tags: [template.generator]} - {class: ApiGen\Generator\TemplateGenerators\PackageGenerator, tags: [template.generator]} - ApiGen\Generator\TemplateGenerators\Loaders\NamespaceAndPackageLoader - ApiGen\Generator\Markups\MarkdownMarkup - Michelf\MarkdownExtra # templating - ApiGen\Templating\TemplateElementsLoader - ApiGen\Templating\TemplateFactory - ApiGen\Templating\TemplateNavigator - ApiGen\Templating\Filters\Helpers\ElementLinkFactory - ApiGen\Templating\Filters\Helpers\ElementUrlFactory - ApiGen\Templating\Filters\Helpers\LinkBuilder - {class: ApiGen\Templating\Filters\AnnotationFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\PathFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\PhpManualFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\ResolverFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\SourceFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\UrlFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\NamespaceAndPackageUrlFilters, tags: [latte.filter]} - {class: ApiGen\Templating\Filters\ElementUrlFilters, tags: [latte.filter]} # theme - ApiGen\Theme\ThemeResources - ApiGen\Theme\ThemeConfigPathResolver(%rootDir%) # syntax highlighter - ApiGen\Generator\SourceCodeHighlighter\FshlSourceCodeHighlighter - FSHL\Output\Html - FSHL\Lexer\Php - class: FSHL\Highlighter setup: - setLexer(@FSHL\Lexer\Php) ApiGen-4.1.2/src/DI/config.neon000066400000000000000000000002201262665576200161050ustar00rootroot00000000000000extensions: - ApiGen\DI\ApiGenExtension - ApiGen\DI\CharsetConvertorExtension - ApiGen\DI\ParserExtension - Kdyby\Events\DI\EventsExtension ApiGen-4.1.2/src/DI/parser.services.neon000066400000000000000000000006231262665576200177650ustar00rootroot00000000000000services: - ApiGen\Parser\Elements\AutocompleteElements - ApiGen\Parser\Elements\ElementExtractor - ApiGen\Parser\Elements\ElementFilter - ApiGen\Parser\Elements\Elements - ApiGen\Parser\Elements\ElementSorter - ApiGen\Parser\Elements\ElementStorage - ApiGen\Parser\Elements\GroupSorter - ApiGen\Parser\Parser - ApiGen\Parser\ParserResult - ApiGen\Reflection\TokenReflection\ReflectionFactory ApiGen-4.1.2/src/Events/000077500000000000000000000000001262665576200147355ustar00rootroot00000000000000ApiGen-4.1.2/src/Events/InjectConfig.php000066400000000000000000000014171262665576200200130ustar00rootroot00000000000000charsetDetector = $charsetDetector; } /** * @return string[] */ public function getSubscribedEvents() { return ['ApiGen\Configuration\Configuration::onOptionsResolve']; } public function onOptionsResolve(array $config) { $this->charsetDetector->setCharsets($config['charset']); } } ApiGen-4.1.2/src/Events/ProgressBarIncrement.php000066400000000000000000000023051262665576200215440ustar00rootroot00000000000000progressBar = $progressBar; } /** * @return string[] */ public function getSubscribedEvents() { return [ 'ApiGen\Generator\TemplateGenerators\NamespaceGenerator::onGenerateProgress', 'ApiGen\Generator\TemplateGenerators\PackageGenerator::onGenerateProgress', 'ApiGen\Generator\TemplateGenerators\ClassElementGenerator::onGenerateProgress', 'ApiGen\Generator\TemplateGenerators\ConstantElementGenerator::onGenerateProgress', 'ApiGen\Generator\TemplateGenerators\FunctionElementGenerator::onGenerateProgress', 'ApiGen\Generator\TemplateGenerators\SourceCodeGenerator::onGenerateProgress' ]; } /** * @param int $size */ public function onGenerateProgress($size = 1) { $this->progressBar->increment($size); } } ApiGen-4.1.2/src/Events/SetIoOnConsoleRun.php000066400000000000000000000015421262665576200210000ustar00rootroot00000000000000consoleIO = $consoleIO; } /** * @return string[] */ public function getSubscribedEvents() { return ['ApiGen\Console\Application::onRun']; } public function onRun(InputInterface $input, OutputInterface $output) { $this->consoleIO->setInput($input); $this->consoleIO->setOutput($output); } } ApiGen-4.1.2/src/FileSystem/000077500000000000000000000000001262665576200155555ustar00rootroot00000000000000ApiGen-4.1.2/src/FileSystem/FileSystem.php000066400000000000000000000036051262665576200203560ustar00rootroot00000000000000from($path)->exclude('.git')->childFirst() as $item) { /** @var \SplFileInfo $item */ if ($item->isDir()) { rmdir($item); } elseif ($item->isFile()) { unlink($item); } } } /** * @param string $path * @param array $baseDirectories * @return string */ public static function getAbsolutePath($path, array $baseDirectories = []) { if (self::isAbsolutePath($path)) { return $path; } foreach ($baseDirectories as $directory) { $fileName = $directory . '/' . $path; if (is_file($fileName)) { return self::normalizePath(realpath($fileName)); } } if (file_exists($path)) { return self::normalizePath(realpath($path)); } return $path; } /** * @param string $path * @return bool */ public function isDirEmpty($path) { if (count(glob($path . "/*"))) { return FALSE; } return TRUE; } /** * @param string $path * @return bool */ private static function isAbsolutePath($path) { if (preg_match('~/|[a-z]:~Ai', $path)) { return TRUE; } return FALSE; } } ApiGen-4.1.2/src/FileSystem/ZipArchiveGenerator.php000066400000000000000000000017231262665576200222040ustar00rootroot00000000000000open($zipFile, ZipArchive::CREATE); $directory = basename($zipFile, '.zip'); /** @var SplFileInfo $file */ foreach (Finder::findFiles('*')->from($source) as $file) { $relativePath = Strings::substring($file->getRealPath(), strlen($source) + 1); $archive->addFile($file, $directory . '/' . $relativePath); } $archive->close(); } } ApiGen-4.1.2/src/Generator/000077500000000000000000000000001262665576200154175ustar00rootroot00000000000000ApiGen-4.1.2/src/Generator/ConditionalTemplateGenerator.php000066400000000000000000000005431262665576200237400ustar00rootroot00000000000000progressBar = $progressBar; } public function run() { $this->progressBar->init($this->getStepCount()); foreach ($this->getAllowedQueue() as $templateGenerator) { $templateGenerator->generate(); } } public function addToQueue(TemplateGenerator $templateGenerator) { $this->queue[] = $templateGenerator; } /** * @return TemplateGenerator[] */ public function getQueue() { return $this->queue; } /** * @return TemplateGenerator[] */ private function getAllowedQueue() { return array_filter($this->queue, function (TemplateGenerator $generator) { if ($generator instanceof ConditionalTemplateGenerator) { return $generator->isAllowed(); } else { return TRUE; } }); } /** * @return int */ private function getStepCount() { $steps = 0; foreach ($this->getAllowedQueue() as $templateGenerator) { if ($templateGenerator instanceof StepCounter) { $steps += $templateGenerator->getStepCount(); } } return $steps; } } ApiGen-4.1.2/src/Generator/Markups/000077500000000000000000000000001262665576200170415ustar00rootroot00000000000000ApiGen-4.1.2/src/Generator/Markups/MarkdownMarkup.php000066400000000000000000000025641262665576200225230ustar00rootroot00000000000000markdown = $markdown; $this->highlighter = $highlighter; } /** * @param string $text * @return string */ public function line($text) { $text = $this->block($text); $text = preg_replace('/^]*>(.*)<\/p[^>]*>$/i', '$1', $text); return trim($text); } /** * @param string $text * @return string */ public function block($text) { $pattern = '~<(code|pre)>(.+?)|```php\s(.+?)\n```~s'; $highlighted = preg_replace_callback($pattern, [$this, 'highlightCb'], $text); $text = $this->markdown->transform($highlighted); return trim($text); } /** * @return string */ private function highlightCb(array $match) { $highlighted = $this->highlighter->highlight(trim(isset($match[3]) ? $match[3] : $match[2])); return "
$highlighted
"; } } ApiGen-4.1.2/src/Generator/Markups/Markup.php000066400000000000000000000006441262665576200210150ustar00rootroot00000000000000 1, 'integer' => 1, 'float' => 1, 'string' => 1, 'array' => 1, 'object' => 1, 'resource' => 1, 'callback' => 1, 'callable' => 1, 'NULL' => 1, 'false' => 1, 'true' => 1, 'mixed' => 1 ]; /** * @var ParserResult */ private $parserResult; public function __construct(ParserResult $parserResult) { $this->parserResult = $parserResult; } /** * @param string $name * @param string $namespace * @return ReflectionClass|NULL */ public function getClass($name, $namespace = '') { $parsedClasses = $this->parserResult->getClasses(); $class = $this->findElementByNameAndNamespace($parsedClasses, $name, $namespace); if ($class && $class->isDocumented()) { return $class; } return NULL; } /** * @param string $name * @param string $namespace * @return ReflectionConstant|NULL */ public function getConstant($name, $namespace = '') { $parsedConstants = $this->parserResult->getConstants(); $constant = $this->findElementByNameAndNamespace($parsedConstants, $name, $namespace); if ($constant && $constant->isDocumented()) { return $constant; } return NULL; } /** * @param string $name * @param string $namespace * @return ReflectionFunction|NULL */ public function getFunction($name, $namespace = '') { $parsedFunctions = $this->parserResult->getFunctions(); $function = $this->findElementByNameAndNamespace($parsedFunctions, $name, $namespace); if ($function && $function->isDocumented()) { return $function; } return NULL; } /** * Tries to parse a definition of a class/method/property/constant/function * * @param string $definition * @param ReflectionElement|ReflectionParameter $reflectionElement Link context * @param string $expectedName * @return ReflectionElement|NULL */ public function resolveElement($definition, $reflectionElement, &$expectedName = NULL) { if ($this->isSimpleType($definition)) { return NULL; } $originalContext = $reflectionElement; $reflectionElement = $this->correctContextForParameterOrClassMember($reflectionElement); if ($reflectionElement === NULL) { return NULL; } // self, $this references if ($definition === 'self' || $definition === '$this') { return $reflectionElement instanceof ReflectionClass ? $reflectionElement : NULL; } $definitionBase = substr($definition, 0, strcspn($definition, '\\:')); $namespaceAliases = $reflectionElement->getNamespaceAliases(); $className = Resolver::resolveClassFqn($definition, $namespaceAliases, $reflectionElement->getNamespaceName()); if ($resolved = $this->resolveIfParsed($definition, $reflectionElement)) { return $resolved; } if ( ! empty($definitionBase) && isset($namespaceAliases[$definitionBase]) && $definition !== $className) { // Aliased class $expectedName = $className; if (strpos($className, ':') === FALSE) { return $this->getClass($className, $reflectionElement->getNamespaceName()); } else { $definition = $className; } } if (($reflectionElement instanceof ClassReflectionInterface) && ($pos = strpos($definition, '::') || $pos = strpos($definition, '->')) ) { $reflectionElement = $this->resolveContextForClassProperty($definition, $reflectionElement, $pos); $definition = substr($definition, $pos + 2); } elseif ($originalContext instanceof ReflectionParameter) { return NULL; } if ( ! $this->isContextUsable($reflectionElement)) { return NULL; } return $this->resolveIfInContext($definition, $reflectionElement); } /** * @param ReflectionClass|ReflectionParameter|ReflectionFunction|ReflectionElement $reflectionElement * @return ReflectionClass|ReflectionFunction */ private function correctContextForParameterOrClassMember($reflectionElement) { if ($reflectionElement instanceof ReflectionParameter && $reflectionElement->getDeclaringClassName() === NULL) { // Parameter of function in namespace or global space return $this->getFunction($reflectionElement->getDeclaringFunctionName()); } elseif ($reflectionElement instanceof ReflectionMethod || $reflectionElement instanceof ReflectionParameter || ($reflectionElement instanceof ReflectionConstant && $reflectionElement->getDeclaringClassName() !== NULL) || $reflectionElement instanceof ReflectionProperty ) { // Member of a class return $this->getClass($reflectionElement->getDeclaringClassName()); } return $reflectionElement; } /** * @param string $definition * @param int $pos * @param ReflectionElement $reflectionElement * @return ReflectionClass */ private function resolveContextForSelfProperty($definition, $pos, ReflectionElement $reflectionElement) { $class = $this->getClass(substr($definition, 0, $pos), $reflectionElement->getNamespaceName()); if ($class === NULL) { $fqnName = Resolver::resolveClassFqn( substr($definition, 0, $pos), $reflectionElement->getNamespaceAliases(), $reflectionElement->getNamespaceName() ); $class = $this->getClass($fqnName); } return $class; } /** * @param string $definition * @return bool */ private function isSimpleType($definition) { if (empty($definition) || isset($this->simpleTypes[$definition])) { return TRUE; } return FALSE; } /** * @param string $definition * @param ReflectionElement $reflectionElement * @return ReflectionClass|ReflectionConstant|ReflectionFunction|NULL */ private function resolveIfParsed($definition, ReflectionElement $reflectionElement) { $definition = $this->removeEndBrackets($definition); if ($class = $this->getClass($definition, $reflectionElement->getNamespaceName())) { return $class; } elseif ($constant = $this->getConstant($definition, $reflectionElement->getNamespaceName())) { return $constant; } elseif ($function = $this->getFunction($definition, $reflectionElement->getNamespaceName())) { return $function; } return NULL; } /** * @param $definition * @param ReflectionClass $context * @return ReflectionConstant|ReflectionMethod|ReflectionProperty|NULL */ private function resolveIfInContext($definition, ReflectionClass $context) { $definition = $this->removeEndBrackets($definition); $definition = $this->removeStartDollar($definition); if ($context->hasProperty($definition)) { return $context->getProperty($definition); } elseif ($context->hasMethod($definition)) { return $context->getMethod($definition); } elseif ($context->hasConstant($definition)) { return $context->getConstant($definition); } return NULL; } /** * @param string $definition * @return string */ private function removeEndBrackets($definition) { if (substr($definition, -2) === '()') { return substr($definition, 0, -2); } return $definition; } /** * @param string $definition * @return string */ private function removeStartDollar($definition) { if ($definition[0] === '$') { return substr($definition, 1); } return $definition; } /** * @param string $definition * @param ReflectionClass $reflectionClass * @param int $pos * @return ReflectionClass */ private function resolveContextForClassProperty($definition, ReflectionClass $reflectionClass, $pos) { // Class::something or Class->something if (strpos($definition, 'parent::') === 0 && ($parentClassName = $reflectionClass->getParentClassName())) { return $this->getClass($parentClassName); } elseif (strpos($definition, 'self::') !== 0) { return $this->resolveContextForSelfProperty($definition, $pos, $reflectionClass); } return $reflectionClass; } /** * @param NULL|ReflectionElement $reflectionElement * @return bool */ private function isContextUsable($reflectionElement) { if ($reflectionElement === NULL || $reflectionElement instanceof ReflectionConstant || $reflectionElement instanceof ReflectionFunction ) { return FALSE; } return TRUE; } /** * @param array|ArrayObject $elements * @param string $name * @param string $namespace * @return ReflectionClass|NULL */ private function findElementByNameAndNamespace($elements, $name, $namespace) { $namespacedName = $namespace . '\\' . $name; if (isset($elements[$namespacedName])) { return $elements[$namespacedName]; } $shortName = ltrim($name, '\\'); if (isset($elements[$shortName])) { return $elements[$shortName]; } return NULL; } } ApiGen-4.1.2/src/Generator/Resolvers/RelativePathResolver.php000066400000000000000000000024441262665576200242320ustar00rootroot00000000000000configuration = $configuration; } /** * @param string $fileName * @return string */ public function getRelativePath($fileName) { foreach ($this->configuration->getOption(CO::SOURCE) as $directory) { if (strpos($fileName, $directory) === 0) { return $this->getFileNameWithoutSourcePath($fileName, $directory); } } throw new InvalidArgumentException(sprintf('Could not determine "%s" relative path', $fileName)); } /** * @param string $fileName * @param string $directory * @return string */ private function getFileNameWithoutSourcePath($fileName, $directory) { $directory = rtrim($directory, '/'); $fileName = substr($fileName, strlen($directory) + 1); return FileSystem::normalizePath($fileName); } } ApiGen-4.1.2/src/Generator/SourceCodeHighlighter/000077500000000000000000000000001262665576200216315ustar00rootroot00000000000000ApiGen-4.1.2/src/Generator/SourceCodeHighlighter/FshlSourceCodeHighlighter.php000066400000000000000000000017601262665576200273750ustar00rootroot00000000000000highlighter = $highlighter; } /** * @param string $sourceCode * @return string */ public function highlight($sourceCode) { $this->highlighter->setOptions(Highlighter::OPTION_TAB_INDENT); return $this->highlighter->highlight($sourceCode); } /** * @param string $sourceCode * @return string */ public function highlightAndAddLineNumbers($sourceCode) { $this->highlighter->setOptions(Highlighter::OPTION_TAB_INDENT | Highlighter::OPTION_LINE_COUNTER); return $this->highlighter->highlight($sourceCode); } } ApiGen-4.1.2/src/Generator/SourceCodeHighlighter/SourceCodeHighlighter.php000066400000000000000000000011271262665576200265550ustar00rootroot00000000000000configuration = $configuration; $this->templateFactory = $templateFactory; $this->elementExtractor = $elementExtractor; } public function generate() { $annotations = $this->configuration->getOption(CO::ANNOTATION_GROUPS); foreach ($annotations as $annotation) { $template = $this->templateFactory->createNamedForElement(TemplateFactory::ELEMENT_ANNOTATION_GROUP, $annotation); $template = $this->setElementsWithAnnotationToTemplate($template, $annotation); $template->save(); } } /** * @param Template $template * @param string $annotation * @return Template */ private function setElementsWithAnnotationToTemplate(Template $template, $annotation) { $elements = $this->elementExtractor->extractElementsByAnnotation($annotation); $template->setParameters([ 'annotation' => $annotation, 'hasElements' => (bool) count(array_filter($elements, 'count')), 'annotationClasses' => $elements[Elements::CLASSES], 'annotationInterfaces' => $elements[Elements::INTERFACES], 'annotationTraits' => $elements[Elements::TRAITS], 'annotationExceptions' => $elements[Elements::EXCEPTIONS], 'annotationConstants' => $elements[Elements::CONSTANTS], 'annotationMethods' => $elements[Elements::METHODS], 'annotationFunctions' => $elements[Elements::FUNCTIONS], 'annotationProperties' => $elements[Elements::PROPERTIES] ]); return $template; } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ClassElementGenerator.php000066400000000000000000000046571262665576200261770ustar00rootroot00000000000000templateFactory = $templateFactory; $this->elementStorage = $elementStorage; $this->namespaceAndPackageLoader = $namespaceAndPackageLoader; } public function generate() { foreach ($this->elementStorage->getClassElements() as $name => $reflectionClass) { $template = $this->templateFactory->createForReflection($reflectionClass); $template = $this->loadTemplateWithParameters($template, $reflectionClass); $template->save(); $this->onGenerateProgress(); } } /** * @return int */ public function getStepCount() { return count($this->elementStorage->getClassElements()); } /** * @return Template */ private function loadTemplateWithParameters(Template $template, ReflectionClass $class) { $template = $this->namespaceAndPackageLoader->loadTemplateWithElementNamespaceOrPackage($template, $class); $template->setParameters([ 'class' => $class, 'tree' => array_merge(array_reverse($class->getParentClasses()), [$class]), 'directSubClasses' => $class->getDirectSubClasses(), 'indirectSubClasses' => $class->getIndirectSubClasses(), 'directImplementers' => $class->getDirectImplementers(), 'indirectImplementers' => $class->getIndirectImplementers(), 'directUsers' => $class->getDirectUsers(), 'indirectUsers' => $class->getIndirectUsers(), ]); return $template; } } ApiGen-4.1.2/src/Generator/TemplateGenerators/CombinedGenerator.php000066400000000000000000000013341262665576200253250ustar00rootroot00000000000000templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::COMBINED) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ConstantElementGenerator.php000066400000000000000000000040451262665576200267120ustar00rootroot00000000000000templateFactory = $templateFactory; $this->elementStorage = $elementStorage; $this->namespaceAndPackageLoader = $namespaceAndPackageLoader; } public function generate() { foreach ($this->elementStorage->getConstants() as $name => $reflectionConstant) { $template = $this->templateFactory->createForReflection($reflectionConstant); $template = $this->loadTemplateWithParameters($template, $reflectionConstant); $template->save(); $this->onGenerateProgress(); } } /** * @return int */ public function getStepCount() { return count($this->elementStorage->getConstants()); } /** * @return Template */ private function loadTemplateWithParameters(Template $template, ReflectionConstant $constant) { $template = $this->namespaceAndPackageLoader->loadTemplateWithElementNamespaceOrPackage($template, $constant); $template->setParameters([ 'constant' => $constant ]); return $template; } } ApiGen-4.1.2/src/Generator/TemplateGenerators/E404Generator.php000066400000000000000000000013241262665576200242200ustar00rootroot00000000000000templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::E404) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ElementListGenerator.php000066400000000000000000000013431262665576200260320ustar00rootroot00000000000000templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::ELEMENT_LIST) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/FunctionElementGenerator.php000066400000000000000000000040451262665576200267060ustar00rootroot00000000000000templateFactory = $templateFactory; $this->elementStorage = $elementStorage; $this->namespaceAndPackageLoader = $namespaceAndPackageLoader; } public function generate() { foreach ($this->elementStorage->getFunctions() as $name => $reflectionFunction) { $template = $this->templateFactory->createForReflection($reflectionFunction); $template = $this->loadTemplateWithParameters($template, $reflectionFunction); $template->save(); $this->onGenerateProgress(); } } /** * @return int */ public function getStepCount() { return count($this->elementStorage->getFunctions()); } /** * @return Template */ private function loadTemplateWithParameters(Template $template, ReflectionFunction $function) { $template = $this->namespaceAndPackageLoader->loadTemplateWithElementNamespaceOrPackage($template, $function); $template->setParameters([ 'function' => $function ]); return $template; } } ApiGen-4.1.2/src/Generator/TemplateGenerators/Loaders/000077500000000000000000000000001262665576200226155ustar00rootroot00000000000000ApiGen-4.1.2/src/Generator/TemplateGenerators/Loaders/NamespaceAndPackageLoader.php000066400000000000000000000056301262665576200302540ustar00rootroot00000000000000elementStorage = $elementStorage; } /** * @return Template */ public function loadTemplateWithElementNamespaceOrPackage(Template $template, ReflectionElement $element) { if ($namespaces = $this->elementStorage->getNamespaces()) { $name = $element->getPseudoNamespaceName(); $template = $this->loadTemplateWithNamespace($template, $name, $namespaces[$name]); } elseif ($packages = $this->elementStorage->getPackages()) { $name = $element->getPseudoPackageName(); $template = $this->loadTemplateWithNamespace($template, $name, $packages[$name]); } return $template; } /** * @param Template $template * @param string $name * @param array $namespace * @return Template */ public function loadTemplateWithNamespace(Template $template, $name, $namespace) { $template->setParameters([ 'package' => NULL, 'namespace' => $name, 'subnamespaces' => $this->getSubnamesForName($name, $template->getParameters()['namespaces']) ]); $template = $this->loadTemplateWithElements($template, $namespace); return $template; } /** * @param Template $template * @param string $name * @param array $package * @return Template */ public function loadTemplateWithPackage(Template $template, $name, $package) { $template->setParameters([ 'namespace' => NULL, 'package' => $name, 'subpackages' => $this->getSubnamesForName($name, $template->getParameters()['packages']) ]); $template = $this->loadTemplateWithElements($template, $package); return $template; } /** * @param Template $template * @param array $elements * @return Template */ private function loadTemplateWithElements(Template $template, $elements) { return $template->setParameters([ Elements::CLASSES => $elements[Elements::CLASSES], Elements::INTERFACES => $elements[Elements::INTERFACES], Elements::TRAITS => $elements[Elements::TRAITS], Elements::EXCEPTIONS => $elements[Elements::EXCEPTIONS], Elements::CONSTANTS => $elements[Elements::CONSTANTS], Elements::FUNCTIONS => $elements[Elements::FUNCTIONS] ]); } /** * @param string $name * @return array */ private function getSubnamesForName($name, $elements) { return array_filter($elements, function ($subname) use ($name) { $pattern = '~^' . preg_quote($name) . '\\\\[^\\\\]+$~'; return (bool) preg_match($pattern, $subname); }); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/NamespaceGenerator.php000066400000000000000000000035031262665576200255010ustar00rootroot00000000000000templateFactory = $templateFactory; $this->elementStorage = $elementStorage; $this->namespaceAndPackageLoader = $namespaceAndPackageLoader; } public function generate() { foreach ($this->elementStorage->getNamespaces() as $name => $namespace) { $template = $this->templateFactory->createNamedForElement(TemplateFactory::ELEMENT_NAMESPACE, $name); $template = $this->namespaceAndPackageLoader->loadTemplateWithNamespace($template, $name, $namespace); $template->save(); $this->onGenerateProgress(); } } /** * @return int */ public function getStepCount() { return count($this->elementStorage->getNamespaces()); } /** * @return bool */ public function isAllowed() { return (bool) $this->elementStorage->getNamespaces(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/OpensearchGenerator.php000066400000000000000000000022061262665576200256730ustar00rootroot00000000000000configuration = $configuration; $this->templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::OPENSEARCH) ->save(); } /** * @return bool */ public function isAllowed() { $options = $this->configuration->getOptions(); return $options[CO::GOOGLE_CSE_ID] && $options[CO::BASE_URL]; } } ApiGen-4.1.2/src/Generator/TemplateGenerators/OverviewGenerator.php000066400000000000000000000013341262665576200254130ustar00rootroot00000000000000templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::OVERVIEW) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/PackageGenerator.php000066400000000000000000000034631262665576200251450ustar00rootroot00000000000000templateFactory = $templateFactory; $this->elementStorage = $elementStorage; $this->namespaceAndPackageLoader = $namespaceAndPackageLoader; } public function generate() { foreach ($this->elementStorage->getPackages() as $name => $package) { $template = $this->templateFactory->createNamedForElement(TemplateFactory::ELEMENT_PACKAGE, $name); $template = $this->namespaceAndPackageLoader->loadTemplateWithPackage($template, $name, $package); $template->save(); $this->onGenerateProgress(); } } /** * @return int */ public function getStepCount() { return count($this->elementStorage->getPackages()); } /** * @return bool */ public function isAllowed() { return (bool) $this->elementStorage->getPackages(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/RobotsGenerator.php000066400000000000000000000021141262665576200250520ustar00rootroot00000000000000configuration = $configuration; $this->templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::ROBOTS) ->save(); } /** * @return bool */ public function isAllowed() { return (bool) $this->configuration->getOption(CO::BASE_URL); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/SitemapGenerator.php000066400000000000000000000021161262665576200252060ustar00rootroot00000000000000configuration = $configuration; $this->templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::SITEMAP) ->save(); } /** * @return bool */ public function isAllowed() { return (bool) $this->configuration->getOption(CO::BASE_URL); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/SourceCodeGenerator.php000066400000000000000000000071271262665576200256460ustar00rootroot00000000000000configuration = $configuration; $this->elementStorage = $elementStorage; $this->templateFactory = $templateFactory; $this->relativePathResolver = $relativePathResolver; $this->charsetConvertor = $charsetConvertor; $this->sourceCodeHighlighter = $sourceCodeHighlighter; } public function generate() { foreach ($this->elementStorage->getElements() as $type => $elementList) { foreach ($elementList as $element) { /** @var ReflectionElement $element */ if ($element->isTokenized()) { $this->generateForElement($element); $this->onGenerateProgress(); } } } } /** * @return bool */ public function isAllowed() { return $this->configuration->getOption(CO::SOURCE_CODE); } /** * @return int */ public function getStepCount() { $tokenizedFilter = function (ReflectionClass $class) { return $class->isTokenized(); }; $count = count(array_filter($this->elementStorage->getClasses(), $tokenizedFilter)) + count(array_filter($this->elementStorage->getInterfaces(), $tokenizedFilter)) + count(array_filter($this->elementStorage->getTraits(), $tokenizedFilter)) + count(array_filter($this->elementStorage->getExceptions(), $tokenizedFilter)) + count($this->elementStorage->getConstants()) + count($this->elementStorage->getFunctions()); return $count; } private function generateForElement(ReflectionElement $element) { $template = $this->templateFactory->createNamedForElement(TCO::SOURCE, $element); $template->setParameters([ 'fileName' => $this->relativePathResolver->getRelativePath($element->getFileName()), 'source' => $this->getHighlightedCodeFromElement($element) ]); $template->save(); } /** * @return string */ private function getHighlightedCodeFromElement(ReflectionElement $element) { $content = $this->charsetConvertor->convertFileToUtf($element->getFileName()); return $this->sourceCodeHighlighter->highlightAndAddLineNumbers($content); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/TreeGenerator.php000066400000000000000000000075631262665576200245160ustar00rootroot00000000000000 [], Elements::INTERFACES => [], Elements::TRAITS => [], Elements::EXCEPTIONS => [] ]; /** * @var ParserResult */ private $parserResult; public function __construct( Configuration $configuration, TemplateFactory $templateFactory, ParserResult $parserResult ) { $this->configuration = $configuration; $this->templateFactory = $templateFactory; $this->parserResult = $parserResult; } public function generate() { $template = $this->templateFactory->createForType(TCO::TREE); $classes = $this->parserResult->getClasses(); foreach ($classes as $className => $reflection) { if ($this->canBeProcessed($reflection)) { $this->addToTreeByReflection($reflection); } } $this->sortTreeStorageElements(); $template->setParameters([ 'classTree' => new Tree($this->treeStorage[Elements::CLASSES], $classes), 'interfaceTree' => new Tree($this->treeStorage[Elements::INTERFACES], $classes), 'traitTree' => new Tree($this->treeStorage[Elements::TRAITS], $classes), 'exceptionTree' => new Tree($this->treeStorage[Elements::EXCEPTIONS], $classes) ]); $template->save(); } /** * @return bool */ public function isAllowed() { return $this->configuration->getOption(CO::TREE); } /** * @return bool */ private function canBeProcessed(ReflectionClass $reflection) { if ( ! $reflection->isMain()) { return FALSE; } if ( ! $reflection->isDocumented()) { return FALSE; } if (isset($this->processed[$reflection->getName()])) { return FALSE; } return TRUE; } private function addToTreeByReflection(ReflectionClass $reflection) { if ($reflection->getParentClassName() === NULL) { $type = $this->getTypeByReflection($reflection); $this->addToTreeByTypeAndName($type, $reflection->getName()); } else { foreach (array_values(array_reverse($reflection->getParentClasses())) as $level => $parent) { $type = NULL; if ($level === 0) { // The topmost parent decides about the reflection type $type = $this->getTypeByReflection($reflection); } /** @var ReflectionClass $parent */ $parentName = $parent->getName(); if ( ! isset($this->treeStorage[$type][$parentName])) { $this->addToTreeByTypeAndName($type, $parentName); } } } } /** * @return string */ private function getTypeByReflection(ReflectionClass $reflection) { if ($reflection->isInterface()) { return Elements::INTERFACES; } elseif ($reflection->isTrait()) { return Elements::TRAITS; } elseif ($reflection->isException()) { return Elements::EXCEPTIONS; } else { return Elements::CLASSES; } } /** * @param string $type * @param string $name */ private function addToTreeByTypeAndName($type, $name) { $this->treeStorage[$type][$name] = []; $this->processed[$name] = TRUE; } private function sortTreeStorageElements() { foreach ($this->treeStorage as $key => $elements) { ksort($elements, SORT_STRING); $this->treeStorage[$key] = $elements; } } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ZipGenerator.php000066400000000000000000000022721262665576200243510ustar00rootroot00000000000000configuration = $configuration; $this->zipArchiveGenerator = $zipArchiveGenerator; } public function generate() { $destination = $this->configuration->getOption(CO::DESTINATION); $zipFile = $destination . '/' . $this->configuration->getZipFileName(); $this->zipArchiveGenerator->zipDirToFile($destination, $zipFile); } /** * @return bool */ public function isAllowed() { return (bool) $this->configuration->getOption(CO::DOWNLOAD); } } ApiGen-4.1.2/src/Herrera/000077500000000000000000000000001262665576200150615ustar00rootroot00000000000000ApiGen-4.1.2/src/Herrera/Box/000077500000000000000000000000001262665576200156115ustar00rootroot00000000000000ApiGen-4.1.2/src/Herrera/Box/Compactor/000077500000000000000000000000001262665576200175405ustar00rootroot00000000000000ApiGen-4.1.2/src/Herrera/Box/Compactor/PhpNette.php000066400000000000000000000032541262665576200220040ustar00rootroot00000000000000preserveLineNumbers($token); } elseif ($this->isCommentWithoutAnnotations($token, ['@return', '@method'])) { $output .= $this->preserveLineNumbers($token); } elseif ($token[0] === T_WHITESPACE) { if (strpos($token[1], "\n") === FALSE) { $output .= ' '; } else { $output .= $this->preserveLineNumbers($token); } } else { $output .= $token[1]; } } return $output; } /** * {@inheritdoc} */ public function supports($file) { return (pathinfo($file, PATHINFO_EXTENSION) === 'php'); } /** * @return string */ private function preserveLineNumbers(array $token) { return str_repeat("\n", substr_count($token[1], "\n")); } /** * @return bool */ private function isCommentWithoutAnnotations(array $token, array $annotationList) { if ($token[0] !== T_DOC_COMMENT) { return FALSE; } foreach ($annotationList as $annotation) { if (strpos($token[1], $annotation) !== FALSE) { return FALSE; } } return TRUE; } } ApiGen-4.1.2/src/MemoryLimit.php000066400000000000000000000017121262665576200164520ustar00rootroot00000000000000getMemoryInBytes($memoryLimit) < 512 * 1024 * 1024) { @ini_set('memory_limit', $newMemoryLimit); } unset($memoryInBytes, $memoryLimit); } } /** * @param string $value * @return int */ private function getMemoryInBytes($value) { $unit = strtolower(substr($value, -1, 1)); $value = (int) $value; if ($unit === 'g') { return $value * 1024 * 1024 * 1024; } if ($unit === 'm') { return $value * 1024 * 1024; } if ($unit === 'k') { return $value * 1024; } } } ApiGen-4.1.2/src/Parser/000077500000000000000000000000001262665576200147255ustar00rootroot00000000000000ApiGen-4.1.2/src/Parser/Broker/000077500000000000000000000000001262665576200161515ustar00rootroot00000000000000ApiGen-4.1.2/src/Parser/Broker/Backend.php000066400000000000000000000144751262665576200202240ustar00rootroot00000000000000 [], self::INTERNAL_CLASSES => [], self::NONEXISTENT_CLASSES => [] ]; /** * @var array */ private $declared = []; /** * @var ReflectionFactory */ private $reflectionFactory; public function __construct(ReflectionFactory $reflectionFactory) { $this->reflectionFactory = $reflectionFactory; } /** * @return ReflectionConstant[] */ public function getConstants() { return array_map(function (IReflectionConstant $constant) { return $this->reflectionFactory->createFromReflection($constant); }, parent::getConstants()); } /** * @return ReflectionFunction[] */ public function getFunctions() { return array_map(function (IReflectionFunction $function) { return $this->reflectionFactory->createFromReflection($function); }, parent::getFunctions()); } /** * Prepares and returns used class lists. * * @return ReflectionClass[] */ protected function parseClassLists() { $this->declared = array_flip(array_merge(get_declared_classes(), get_declared_interfaces())); foreach ($this->getNamespaces() as $namespace) { foreach ($namespace->getClasses() as $name => $ref) { $class = $this->reflectionFactory->createFromReflection($ref); $this->allClasses[self::TOKENIZED_CLASSES][$name] = $class; if ( ! $class->isDocumented()) { continue; } $this->loadParentClassesAndInterfacesFromClassReflection($ref); } } /** @var ReflectionClass $class */ foreach ($this->allClasses[self::TOKENIZED_CLASSES] as $class) { if ( ! $class->isDocumented()) { continue; } foreach ($class->getOwnMethods() as $method) { $this->processFunction($method); } foreach ($class->getOwnProperties() as $property) { $this->loadAnnotationFromReflection($class, $property->getAnnotations(), 'var'); } } foreach ($this->getFunctions() as $function) { $this->processFunction($function); } array_walk_recursive($this->allClasses, function (&$reflection) { if ( ! $reflection instanceof ReflectionClass) { $reflection = $this->reflectionFactory->createFromReflection($reflection); } }); return $this->allClasses; } /** * Processes a function/method and adds classes from annotations to the overall class array. * * @param ReflectionMethod|ReflectionFunction $reflection */ private function processFunction($reflection) { $annotations = $reflection->getAnnotations(); foreach (['param', 'return', 'throws'] as $annotation) { $this->loadAnnotationFromReflection($reflection, $annotations, $annotation); } foreach ($reflection->getParameters() as $parameter) { if ($hint = $parameter->getClassName()) { $this->addClass($hint); } } } /** * @param string $name */ private function addClass($name) { $name = ltrim($name, '\\'); if ( ! isset($this->declared[$name]) || $this->isClassLoaded($name)) { return FALSE; } $parameterClass = $this->getBroker()->getClass($name); if ($parameterClass->isInternal()) { $this->allClasses[self::INTERNAL_CLASSES][$name] = $parameterClass; foreach (array_merge($parameterClass->getInterfaces(), $parameterClass->getParentClasses()) as $parentClass) { if ( ! isset($this->allClasses[self::INTERNAL_CLASSES][$parentName = $parentClass->getName()])) { $this->allClasses[self::INTERNAL_CLASSES][$parentName] = $parentClass; } } } elseif ( ! $parameterClass->isTokenized()) { if ( ! isset($this->allClasses[self::NONEXISTENT_CLASSES][$name])) { $this->allClasses[self::NONEXISTENT_CLASSES][$name] = $parameterClass; } } } /** * @param TokenReflection\ReflectionClass|TokenReflection\Invalid\ReflectionClass $ref */ private function loadParentClassesAndInterfacesFromClassReflection($ref) { foreach (array_merge($ref->getParentClasses(), $ref->getInterfaces()) as $parentName => $parentReflection) { /** @var TokenReflection\ReflectionClass $parentReflection */ if ($parentReflection->isInternal()) { if ( ! isset($this->allClasses[self::INTERNAL_CLASSES][$parentName])) { $this->allClasses[self::INTERNAL_CLASSES][$parentName] = $parentReflection; } } elseif ( ! $parentReflection->isTokenized()) { if ( ! isset($this->allClasses[self::NONEXISTENT_CLASSES][$parentName])) { $this->allClasses[self::NONEXISTENT_CLASSES][$parentName] = $parentReflection; } } } } /** * @param string $name * @return bool */ private function isClassLoaded($name) { return isset($this->allClasses[self::TOKENIZED_CLASSES][$name]) || isset($this->allClasses[self::INTERNAL_CLASSES][$name]) || isset($this->allClasses[self::NONEXISTENT_CLASSES][$name]); } /** * @param ReflectionClass|ReflectionMethod $reflection * @param array $annotations * @param string $name */ private function loadAnnotationFromReflection($reflection, array $annotations, $name) { if ( ! isset($annotations[$name])) { return; } foreach ($annotations[$name] as $doc) { foreach (explode('|', preg_replace('~\\s.*~', '', $doc)) as $name) { if ($name = rtrim($name, '[]')) { $name = $this->getClassFqn($name, $reflection); $this->addClass($name); } } } } /** * @param string $name * @param ReflectionClass|ReflectionMethod $reflection * @return string */ private function getClassFqn($name, $reflection) { return Resolver::resolveClassFqn($name, $reflection->getNamespaceAliases(), $reflection->getNamespaceName()); } } ApiGen-4.1.2/src/Parser/Elements/000077500000000000000000000000001262665576200165015ustar00rootroot00000000000000ApiGen-4.1.2/src/Parser/Elements/AutocompleteElements.php000066400000000000000000000027011262665576200233500ustar00rootroot00000000000000elementStorage = $elementStorage; } /** * @return array */ public function getElements() { foreach ($this->elementStorage->getElements() as $type => $elementList) { foreach ($elementList as $element) { $this->processElement($element); } } $this->sortElements(); return $this->elements; } private function processElement(ReflectionBase $element) { if ($element instanceof ReflectionConstant) { $this->elements[] = ['co', $element->getPrettyName()]; } elseif ($element instanceof ReflectionFunction) { $this->elements[] = ['f', $element->getPrettyName()]; } elseif ($element instanceof ReflectionClass) { $this->elements[] = ['c', $element->getPrettyName()]; } } private function sortElements() { usort($this->elements, function ($one, $two) { return strcasecmp($one[1], $two[1]); }); } } ApiGen-4.1.2/src/Parser/Elements/ElementExtractor.php000066400000000000000000000055661262665576200225130ustar00rootroot00000000000000elements = $elements; $this->elementFilter = $elementFilter; $this->elementStorage = $elementStorage; $this->elementSorter = $elementSorter; } /** * @param string $annotation * @param callable $skipClassCallback * @return array[] */ public function extractElementsByAnnotation($annotation, callable $skipClassCallback = NULL) { $elements = $this->elements->getEmptyList(); $elements[Elements::METHODS] = []; $elements[Elements::PROPERTIES] = []; foreach ($this->elementStorage->getElements() as $type => $elementList) { $elementsForMain = $this->elementFilter->filterForMain($elementList); $elements[$type] += $this->elementFilter->filterByAnnotation($elementsForMain, $annotation); if ($type === Elements::CONSTANTS || $type === Elements::FUNCTIONS) { continue; } foreach ($elementList as $class) { /** @var ReflectionClass $class */ if ( ! $class->isMain()) { continue; } if ($skipClassCallback && $skipClassCallback($class)) { // in case when class is prior to it's elements continue; } $elements[Elements::METHODS] = $this->extractByAnnotationAndMerge( $class->getOwnMethods(), $annotation, $elements[Elements::METHODS] ); $elements[Elements::CONSTANTS] = $this->extractByAnnotationAndMerge( $class->getOwnConstants(), $annotation, $elements[Elements::CONSTANTS] ); $elements[Elements::PROPERTIES] = $this->extractByAnnotationAndMerge( $class->getOwnProperties(), $annotation, $elements[Elements::PROPERTIES] ); } } return $this->sortElements($elements); } /** * @param array $elements * @param string $annotation * @param array[] $storage * @return array[] */ private function extractByAnnotationAndMerge($elements, $annotation, $storage) { $foundElements = $this->elementFilter->filterByAnnotation($elements, $annotation); return array_merge($storage, array_values($foundElements)); } /** * @param array { key => elementList[] } $elements * @return array */ private function sortElements($elements) { foreach ($elements as $key => $elementList) { $this->elementSorter->sortElementsByFqn($elementList); } return $elements; } } ApiGen-4.1.2/src/Parser/Elements/ElementFilter.php000066400000000000000000000015661262665576200217610ustar00rootroot00000000000000isMain(); }); } /** * @param ReflectionElement[] $elements * @param string $annotation * @return ReflectionElement[] */ public function filterByAnnotation(array $elements, $annotation) { return array_filter($elements, function (ReflectionElement $element) use ($annotation) { return $element->hasAnnotation($annotation); }); } } ApiGen-4.1.2/src/Parser/Elements/ElementSorter.php000066400000000000000000000071171262665576200220100ustar00rootroot00000000000000sortConstantsByFqn($elements); } elseif ($firstElement instanceof ReflectionFunction) { return $this->sortFunctionsByFqn($elements); } elseif ($firstElement instanceof ReflectionMethod || $firstElement instanceof ReflectionProperty) { return $this->sortPropertiesOrMethodsByFqn($elements); } } return $elements; } /** * @param ReflectionConstant[] $reflectionConstants * @return ReflectionConstant[] */ private function sortConstantsByFqn($reflectionConstants) { usort($reflectionConstants, function ($a, $b) { return $this->compareConstantsByFqn($a, $b); }); return $reflectionConstants; } /** * @param ReflectionFunction[] $reflectionFunctions * @return ReflectionFunction[] */ private function sortFunctionsByFqn($reflectionFunctions) { usort($reflectionFunctions, function ($a, $b) { return $this->compareFunctionsByFqn($a, $b); }); return $reflectionFunctions; } /** * @param ReflectionMethod[]|ReflectionProperty[] $reflectionElements * @return ReflectionMethod[] */ private function sortPropertiesOrMethodsByFqn($reflectionElements) { usort($reflectionElements, function ($a, $b) { return $this->compareMethodsOrPropertiesByFqn($a, $b); }); return $reflectionElements; } /** * @return int */ private function compareConstantsByFqn(ReflectionConstant $reflection1, ReflectionConstant $reflection2) { return strcasecmp($this->getConstantFqnName($reflection1), $this->getConstantFqnName($reflection2)); } /** * @return int */ private function compareFunctionsByFqn(ReflectionFunction $reflection1, ReflectionFunction $reflection2) { return strcasecmp($this->getFunctionFqnName($reflection1), $this->getFunctionFqnName($reflection2)); } /** * @param ReflectionMethod|ReflectionProperty $reflection1 * @param ReflectionMethod|ReflectionProperty $reflection2 * @return int */ private function compareMethodsOrPropertiesByFqn($reflection1, $reflection2) { return strcasecmp( $this->getPropertyOrMethodFqnName($reflection1), $this->getPropertyOrMethodFqnName($reflection2) ); } /** * @return string */ private function getConstantFqnName(ReflectionConstant $reflection) { $class = $reflection->getDeclaringClassName() ?: $reflection->getNamespaceName(); return $class . '\\' . $reflection->getName(); } /** * @return string */ private function getFunctionFqnName(ReflectionFunction $reflection) { return $reflection->getNamespaceName() . '\\' . $reflection->getName(); } /** * @param ReflectionMethod|ReflectionProperty $reflection * @return string */ private function getPropertyOrMethodFqnName(ReflectionElement $reflection) { return $reflection->getDeclaringClassName() . '::' . $reflection->getName(); } } ApiGen-4.1.2/src/Parser/Elements/ElementStorage.php000066400000000000000000000162671262665576200221440ustar00rootroot00000000000000parserResult = $parserResult; $this->configuration = $configuration; $this->groupSorter = $groupSorter; $this->elementResolver = $elementResolver; } /** * @return ReflectionClass[] */ public function getClasses() { $this->ensureCategorization(); return $this->classes; } /** * @return array */ public function getNamespaces() { $this->ensureCategorization(); return $this->namespaces; } /** * @return array */ public function getPackages() { $this->ensureCategorization(); return $this->packages; } /** * @return array */ public function getInterfaces() { $this->ensureCategorization(); return $this->interfaces; } /** * @return array */ public function getTraits() { $this->ensureCategorization(); return $this->traits; } /** * @return array */ public function getExceptions() { $this->ensureCategorization(); return $this->exceptions; } /** * @return array */ public function getConstants() { $this->ensureCategorization(); return $this->constants; } /** * @return array */ public function getFunctions() { $this->ensureCategorization(); return $this->functions; } /** * @return ReflectionClass[] */ public function getClassElements() { return array_merge($this->getClasses(), $this->getTraits(), $this->getInterfaces(), $this->getExceptions()); } /** * @return array[] */ public function getElements() { $this->ensureCategorization(); $elements = [ Elements::CLASSES => $this->classes, Elements::CONSTANTS => $this->constants, Elements::FUNCTIONS => $this->functions, Elements::INTERFACES => $this->interfaces, Elements::TRAITS => $this->traits, Elements::EXCEPTIONS => $this->exceptions ]; return $elements; } private function categorizeParsedElements() { foreach ($this->parserResult->getTypes() as $type) { $elements = $this->parserResult->getElementsByType($type); foreach ($elements as $elementName => $element) { if ( ! $element->isDocumented()) { continue; } if ($element instanceof ReflectionConstant) { $elementType = Elements::CONSTANTS; $this->constants[$elementName] = $element; } elseif ($element instanceof ReflectionFunction) { $elementType = Elements::FUNCTIONS; $this->functions[$elementName] = $element; } elseif ($element->isInterface()) { $elementType = Elements::INTERFACES; $this->interfaces[$elementName] = $element; } elseif ($element->isTrait()) { $elementType = Elements::TRAITS; $this->traits[$elementName] = $element; } elseif ($element->isException()) { $elementType = Elements::EXCEPTIONS; $this->exceptions[$elementName] = $element; } else { $elementType = Elements::CLASSES; $this->classes[$elementName] = $element; } $this->categorizeElementToNamespaceAndPackage($elementName, $elementType, $element); } } $this->sortNamespacesAndPackages(); $this->areElementsCategorized = TRUE; $this->addUsedByAnnotation(); } /** * @param string $elementName * @param string $elementType * @param ReflectionElement|ReflectionClass $element */ private function categorizeElementToNamespaceAndPackage($elementName, $elementType, ReflectionElement $element) { $packageName = $element->getPseudoPackageName(); $this->packages[$packageName][$elementType][$elementName] = $element; $namespaceName = $element->getPseudoNamespaceName(); $this->namespaces[$namespaceName][$elementType][$element->getShortName()] = $element; } private function sortNamespacesAndPackages() { $areNamespacesEnabled = $this->configuration->areNamespacesEnabled( $this->getNamespaceCount(), $this->getPackageCount() ); $arePackagesEnabled = $this->configuration->arePackagesEnabled($areNamespacesEnabled); if ($areNamespacesEnabled) { $this->namespaces = $this->groupSorter->sort($this->namespaces); $this->packages = []; } elseif ($arePackagesEnabled) { $this->namespaces = []; $this->packages = $this->groupSorter->sort($this->packages); } else { $this->namespaces = []; $this->packages = []; } } /** * @return int */ private function getNamespaceCount() { $nonDefaultNamespaces = array_diff(array_keys($this->namespaces), ['PHP', 'None']); return count($nonDefaultNamespaces); } /** * @return int */ private function getPackageCount() { $nonDefaultPackages = array_diff(array_keys($this->packages), ['PHP', 'None']); return count($nonDefaultPackages); } private function addUsedByAnnotation() { foreach ($this->getElements() as $elementList) { foreach ($elementList as $parentElement) { $elements = $this->getSubElements($parentElement); /** @var ReflectionElement $element */ foreach ($elements as $element) { $this->loadUsesToReferencedElementUsedby($element); } } } } private function ensureCategorization() { if ($this->areElementsCategorized === FALSE) { $this->categorizeParsedElements(); } } /** * @return array */ private function getSubElements(ReflectionElement $parentElement) { $elements = [$parentElement]; if ($parentElement instanceof ReflectionClass) { $elements = array_merge( $elements, array_values($parentElement->getOwnMethods()), array_values($parentElement->getOwnConstants()), array_values($parentElement->getOwnProperties()) ); } return $elements; } private function loadUsesToReferencedElementUsedby(ReflectionElement $element) { $uses = $element->getAnnotation('uses'); if ($uses === NULL) { return; } foreach ($uses as $value) { list($link, $description) = preg_split('~\s+|$~', $value, 2); $resolved = $this->elementResolver->resolveElement($link, $element); if ($resolved) { $resolved->addAnnotation('usedby', $element->getPrettyName() . ' ' . $description); } } } } ApiGen-4.1.2/src/Parser/Elements/Elements.php000066400000000000000000000017651262665576200207770ustar00rootroot00000000000000getAll() as $type) { $emptyList[$type] = []; } return $emptyList; } } ApiGen-4.1.2/src/Parser/Elements/GroupSorter.php000066400000000000000000000054101262665576200215050ustar00rootroot00000000000000elements = $elements; $this->configuration = $configuration; } /** * @return array */ public function sort(array $groups) { if ($this->isNoneGroupOnly($groups)) { return []; } $this->groups = $groups; $groupNames = array_keys($groups); $this->lowercasedGroupNames = $this->convertGroupNamesToLower($groupNames); foreach ($groupNames as $groupName) { $this->addMissingParentGroups($groupName); $this->addMissingElementTypes($groupName); } uksort($this->groups, function ($one, $two) { return $this->compareGroups($one, $two, $this->configuration->getOption(CO::MAIN)); }); return $this->groups; } /** * @return bool */ private function isNoneGroupOnly(array $groups) { if (count($groups) === 1 && isset($groups['None'])) { return TRUE; } return FALSE; } /** * @param array $groupNames * @return array */ private function convertGroupNamesToLower($groupNames) { $names = array_map(function ($name) { return strtolower($name); }, $groupNames); return array_flip($names); } /** * @param string $groupName */ private function addMissingParentGroups($groupName) { $parent = ''; foreach (explode('\\', $groupName) as $part) { $parent = ltrim($parent . '\\' . $part, '\\'); if ( ! isset($this->lowercasedGroupNames[strtolower($parent)])) { $this->groups[$parent] = $this->elements->getEmptyList(); } } } /** * @param string $groupName */ private function addMissingElementTypes($groupName) { foreach ($this->elements->getAll() as $type) { if ( ! isset($this->groups[$groupName][$type])) { $this->groups[$groupName][$type] = []; } } } /** * @param string $one * @param string $two * @param string $main * @return int */ private function compareGroups($one, $two, $main) { // \ as separator has to be first $one = str_replace('\\', ' ', $one); $two = str_replace('\\', ' ', $two); if ($main) { if (strpos($one, $main) === 0 && strpos($two, $main) !== 0) { return -1; } elseif (strpos($one, $main) !== 0 && strpos($two, $main) === 0) { return 1; } } return strcasecmp($one, $two); } } ApiGen-4.1.2/src/Parser/Parser.php000066400000000000000000000050521262665576200166740ustar00rootroot00000000000000broker = $broker; $this->charsetConvertor = $charsetConvertor; $this->parserResult = $parserResult; } /** * @param SplFileInfo[] $files */ public function parse($files) { foreach ($files as $file) { $content = $this->charsetConvertor->convertFileToUtf($file->getPathname()); try { $this->broker->processString($content, $file->getPathname()); } catch (FileProcessingException $exception) { $this->errors[] = $exception; } } $this->extractBrokerDataForParserResult($this->broker); } /** * @return array */ public function getErrors() { return $this->errors; } private function extractBrokerDataForParserResult(Broker $broker) { $allFoundClasses = $broker->getClasses( Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES ); $classes = new ArrayObject($allFoundClasses); $constants = new ArrayObject($broker->getConstants()); $functions = new ArrayObject($broker->getFunctions()); $internalClasses = new ArrayObject($broker->getClasses(Backend::INTERNAL_CLASSES)); $tokenizedClasses = new ArrayObject($broker->getClasses(Backend::TOKENIZED_CLASSES)); $classes->uksort('strcasecmp'); $constants->uksort('strcasecmp'); $functions->uksort('strcasecmp'); $this->loadToParserResult($classes, $constants, $functions, $internalClasses, $tokenizedClasses); } private function loadToParserResult( ArrayObject $classes, ArrayObject $constants, ArrayObject $functions, ArrayObject $internalClasses, ArrayObject $tokenizedClasses ) { $this->parserResult->setClasses($classes); $this->parserResult->setConstants($constants); $this->parserResult->setFunctions($functions); $this->parserResult->setInternalClasses($internalClasses); $this->parserResult->setTokenizedClasses($tokenizedClasses); } } ApiGen-4.1.2/src/Parser/ParserResult.php000066400000000000000000000104021262665576200200660ustar00rootroot00000000000000classes = new ArrayObject; $this->constants = new ArrayObject; $this->functions = new ArrayObject; $this->internalClasses = new ArrayObject; $this->tokenizedClasses = new ArrayObject; } /** * @param string $type * @return ArrayObject */ public function getElementsByType($type) { if ($type === Elements::CLASSES) { return $this->classes; } elseif ($type === Elements::CONSTANTS) { return $this->constants; } elseif ($type === Elements::FUNCTIONS) { return $this->functions; } throw new \Exception("'$type' is not supported element type"); } /** * @return array */ public function getDocumentedStats() { return [ 'classes' => $this->getDocumentedElementsCount($this->tokenizedClasses), 'constants' => $this->getDocumentedElementsCount($this->constants), 'functions' => $this->getDocumentedElementsCount($this->functions), 'internalClasses' => $this->getDocumentedElementsCount($this->internalClasses) ]; } /** * @return ArrayObject */ public function getClasses() { return $this->classes; } /** * @return ArrayObject */ public function getConstants() { return $this->constants; } /** * @return ArrayObject */ public function getFunctions() { return $this->functions; } /** * @return array */ public function getTypes() { return $this->types; } public function setClasses(ArrayObject $classes) { $this->classes = $classes; } public function setConstants(ArrayObject $constants) { $this->constants = $constants; } public function setFunctions(ArrayObject $functions) { $this->functions = $functions; } public function setInternalClasses(ArrayObject $internalClasses) { $this->internalClasses = $internalClasses; } public function setTokenizedClasses(ArrayObject $tokenizedClasses) { $this->tokenizedClasses = $tokenizedClasses; } /** * @return ReflectionClass[]|array */ public function getDirectImplementersOfInterface(ReflectionClass $reflectionClass) { $implementers = []; foreach ($this->classes as $class) { if ($this->isAllowedDirectImplementer($class, $reflectionClass->getName())) { $implementers[] = $class; } } uksort($implementers, 'strcasecmp'); return $implementers; } /** * @return ReflectionClass[]|array */ public function getIndirectImplementersOfInterface(ReflectionClass $reflectionClass) { $implementers = []; foreach ($this->classes as $class) { if ($this->isAllowedIndirectImplementer($class, $reflectionClass->getName())) { $implementers[] = $class; } } uksort($implementers, 'strcasecmp'); return $implementers; } /** * @param ReflectionClass $class * @param string $name * @return bool */ private function isAllowedDirectImplementer(ReflectionClass $class, $name) { if ($class->isDocumented() && in_array($name, $class->getOwnInterfaceNames())) { return TRUE; } return FALSE; } /** * @param ReflectionClass $class * @param string $name * @return bool */ private function isAllowedIndirectImplementer(ReflectionClass $class, $name) { if ($class->isDocumented() && $class->implementsInterface($name) && ! in_array($name, $class->getOwnInterfaceNames()) ) { return TRUE; } return FALSE; } /** * @param ReflectionElement[]|ArrayObject $result * @return int */ private function getDocumentedElementsCount(ArrayObject $result) { $count = 0; foreach ($result as $element) { $count += (int) $element->isDocumented(); } return $count; } } ApiGen-4.1.2/src/Reflection/000077500000000000000000000000001262665576200155635ustar00rootroot00000000000000ApiGen-4.1.2/src/Reflection/Extractors/000077500000000000000000000000001262665576200177215ustar00rootroot00000000000000ApiGen-4.1.2/src/Reflection/Extractors/AnnotationMethodExtractor.php000066400000000000000000000067761262665576200256210ustar00rootroot00000000000000reflectionFactory = $reflectionFactory; } /** * @param ReflectionClass $reflectionClass * @return ReflectionMethodMagic[]|array */ public function extractFromReflection(ReflectionClass $reflectionClass) { $this->reflectionClass = $reflectionClass; $methods = []; if ($reflectionClass->hasAnnotation('method')) { foreach ($reflectionClass->getAnnotation('method') as $annotation) { $methods += $this->processMagicMethodAnnotation($annotation); }; } return $methods; } /** * @param string $annotation * @return ReflectionMethodMagic[]|array */ private function processMagicMethodAnnotation($annotation) { if ( ! preg_match(self::PATTERN_METHOD, $annotation, $matches)) { return []; } list(, $returnTypeHint, $returnsReference, $name, $args, $shortDescription) = $matches; $startLine = $this->getStartLine($annotation); $endLine = $startLine + substr_count($annotation, "\n"); $methods = []; $methods[$name] = $method = $this->reflectionFactory->createMethodMagic([ 'name' => $name, 'shortDescription' => str_replace("\n", ' ', $shortDescription), 'startLine' => $startLine, 'endLine' => $endLine, 'returnsReference' => ($returnsReference === '&'), 'declaringClass' => $this->reflectionClass, 'annotations' => ['return' => [0 => $returnTypeHint]] ]); $this->attachMethodParameters($method, $args); return $methods; } /** * @param string $annotation * @return int */ private function getStartLine($annotation) { $doc = $this->reflectionClass->getDocComment(); $tmp = $annotation; if ($delimiter = strpos($annotation, "\n")) { $tmp = substr($annotation, 0, $delimiter); } return $this->reflectionClass->getStartLine() + substr_count(substr($doc, 0, strpos($doc, $tmp)), "\n"); } /** * @param ReflectionMethodMagic $method * @param string $args */ private function attachMethodParameters(ReflectionMethodMagic $method, $args) { $parameters = []; foreach (array_filter(preg_split('~\\s*,\\s*~', $args)) as $position => $arg) { if ( ! preg_match(self::PATTERN_PARAMETER, $arg, $matches)) { // Wrong annotation format continue; } list(, $typeHint, $passedByReference, $name, $defaultValueDefinition) = $matches; $parameters[$name] = $this->reflectionFactory->createParameterMagic([ 'name' => $name, 'position' => $position, 'typeHint' => $typeHint, 'defaultValueDefinition' => $defaultValueDefinition, 'unlimited' => FALSE, 'passedByReference' => ($passedByReference === '&'), 'declaringFunction' => $method ]); $method->addAnnotation('param', ltrim(sprintf('%s $%s', $typeHint, $name))); } $method->setParameters($parameters); } } ApiGen-4.1.2/src/Reflection/Extractors/AnnotationPropertyExtractor.php000066400000000000000000000047671262665576200262230ustar00rootroot00000000000000reflectionFactory = $reflectionFactory; } public function extractFromReflection(ReflectionClass $reflectionClass) { $this->reflectionClass = $reflectionClass; $properties = []; foreach (['property', 'property-read', 'property-write'] as $annotationName) { if ($reflectionClass->hasAnnotation($annotationName)) { foreach ($reflectionClass->getAnnotation($annotationName) as $annotation) { $properties += $this->processMagicPropertyAnnotation($annotation, $annotationName); }; } } return $properties; } /** * @param string $annotation * @param string $annotationName * @return ReflectionPropertyMagic[]|array */ private function processMagicPropertyAnnotation($annotation, $annotationName) { if ( ! preg_match(self::PATTERN_PROPERTY, $annotation, $matches)) { return []; } list(, $typeHint, $name, $shortDescription) = $matches; $startLine = $this->getStartLine($annotation); $properties = []; $properties[$name] = $this->reflectionFactory->createPropertyMagic([ 'name' => $name, 'typeHint' => $typeHint, 'shortDescription' => str_replace("\n", ' ', $shortDescription), 'startLine' => $startLine, 'endLine' => $startLine + substr_count($annotation, "\n"), 'readOnly' => ($annotationName === 'property-read'), 'writeOnly' => ($annotationName === 'property-write'), 'declaringClass' => $this->reflectionClass ]); return $properties; } /** * @param string $annotation * @return int */ private function getStartLine($annotation) { $doc = $this->reflectionClass->getDocComment(); $tmp = $annotation; if ($delimiter = strpos($annotation, "\n")) { $tmp = substr($annotation, 0, $delimiter); } return $this->reflectionClass->getStartLine() + substr_count(substr($doc, 0, strpos($doc, $tmp)), "\n"); } } ApiGen-4.1.2/src/Reflection/Extractors/ClassMagicElementsExtractor.php000066400000000000000000000124501262665576200260330ustar00rootroot00000000000000reflectionClass = $reflectionClass; } /** * @return ReflectionPropertyMagic[] */ public function getMagicProperties() { return $this->getOwnMagicProperties() + (new MagicPropertyExtractor)->extractFromClass($this->reflectionClass); } /** * @return ReflectionMethodMagic[] */ public function getMagicMethods() { return $this->getOwnMagicMethods() + (new MagicMethodExtractor)->extractFromClass($this->reflectionClass); } /** * @return ReflectionPropertyMagic[]|array */ public function getOwnMagicProperties() { if ($this->ownMagicProperties === NULL) { $this->ownMagicProperties = []; if ($this->reflectionClass->isVisibilityLevelPublic() && $this->reflectionClass->getDocComment()) { $extractor = new AnnotationPropertyExtractor($this->reflectionClass->getReflectionFactory()); $this->ownMagicProperties += $extractor->extractFromReflection($this->reflectionClass); } } return $this->ownMagicProperties; } /** * @return ReflectionMethodMagic[] */ public function getOwnMagicMethods() { if ($this->ownMagicMethods === NULL) { $this->ownMagicMethods = []; if ($this->reflectionClass->isVisibilityLevelPublic() && $this->reflectionClass->getDocComment()) { $extractor = new AnnotationMethodExtractor($this->reflectionClass->getReflectionFactory()); $this->ownMagicMethods += $extractor->extractFromReflection($this->reflectionClass); } } return $this->ownMagicMethods; } /** * @return array {[ declaringClassName => ReflectionPropertyMagic[] ]} */ public function getInheritedMagicProperties() { $properties = []; $allProperties = array_flip(array_map(function (ReflectionProperty $property) { return $property->getName(); }, $this->getOwnMagicProperties())); foreach ($this->reflectionClass->getParentClasses() as $class) { $inheritedProperties = $this->getUsedElements($class->getOwnMagicProperties(), $allProperties); $properties = $this->sortElements($inheritedProperties, $properties, $class); } return $properties; } /** * @return array {[ declaringClassName => ReflectionMethodMagic[] ]} */ public function getInheritedMagicMethods() { $methods = []; $allMethods = array_flip(array_map(function (ReflectionMethod $method) { return $method->getName(); }, $this->getOwnMagicMethods())); /** @var ReflectionClass[] $parentClassesAndInterfaces */ $parentClassesAndInterfaces = array_merge( $this->reflectionClass->getParentClasses(), $this->reflectionClass->getInterfaces() ); foreach ($parentClassesAndInterfaces as $class) { $inheritedMethods = $this->getUsedElements($class->getOwnMagicMethods(), $allMethods); $methods = $this->sortElements($inheritedMethods, $methods, $class); } return $methods; } /** * @return array {[ declaringTraitName => ReflectionPropertyMagic[] ]} */ public function getUsedMagicProperties() { $properties = []; $allProperties = array_flip(array_map(function (ReflectionProperty $property) { return $property->getName(); }, $this->getOwnMagicProperties())); foreach ($this->reflectionClass->getTraits() as $trait) { if ( ! $trait instanceof ReflectionClass) { continue; } $usedProperties = $this->getUsedElements($trait->getOwnMagicProperties(), $allProperties); $properties = $this->sortElements($usedProperties, $properties, $trait); } return $properties; } /** * @return ReflectionMethodMagic[]|array */ public function getUsedMagicMethods() { $usedMethods = []; foreach ($this->getMagicMethods() as $method) { $declaringTraitName = $method->getDeclaringTraitName(); if ($declaringTraitName === NULL || $declaringTraitName === $this->reflectionClass->getName()) { continue; } $usedMethods[$declaringTraitName][$method->getName()]['method'] = $method; } return $usedMethods; } /** * @param ReflectionElement[] $elementsToCheck * @param array $allElements * @return array */ private function getUsedElements(array $elementsToCheck, array &$allElements) { $elements = []; foreach ($elementsToCheck as $property) { if ( ! array_key_exists($property->getName(), $allElements)) { $elements[$property->getName()] = $property; $allElements[$property->getName()] = NULL; } } return $elements; } /** * @return array */ private function sortElements(array $elements, array $allElements, ReflectionClass $reflectionClass) { if ( ! empty($elements)) { ksort($elements); $allElements[$reflectionClass->getName()] = array_values($elements); } return $allElements; } } ApiGen-4.1.2/src/Reflection/Extractors/ClassTraitElementsExtractor.php000066400000000000000000000102671262665576200261020ustar00rootroot00000000000000reflectionClass = $reflectionClass; $this->originalReflection = $originalReflection; } /** * @return ReflectionClass[]|array */ public function getDirectUsers() { $users = []; $name = $this->reflectionClass->getName(); foreach ($this->reflectionClass->getParsedClasses() as $class) { if ( ! $class->isDocumented()) { continue; } if (in_array($name, $class->getOwnTraitNames())) { $users[] = $class; } } uksort($users, 'strcasecmp'); return $users; } /** * @return ReflectionClass[]|array */ public function getIndirectUsers() { $users = []; $name = $this->reflectionClass->getName(); foreach ($this->reflectionClass->getParsedClasses() as $class) { if ( ! $class->isDocumented()) { continue; } if ($class->usesTrait($name) && ! in_array($name, $class->getOwnTraitNames())) { $users[] = $class; } } uksort($users, 'strcasecmp'); return $users; } /** * @return ReflectionProperty[]|array */ public function getTraitProperties() { $properties = []; $traitProperties = $this->originalReflection->getTraitProperties($this->reflectionClass->getVisibilityLevel()); foreach ($traitProperties as $property) { $apiProperty = $this->reflectionClass->getReflectionFactory()->createFromReflection($property); if ( ! $this->reflectionClass->isDocumented() || $apiProperty->isDocumented()) { /** @var ReflectionProperty $property */ $properties[$property->getName()] = $apiProperty; } } return $properties; } /** * @return ReflectionMethod[]|array */ public function getTraitMethods() { $methods = []; foreach ($this->originalReflection->getTraitMethods($this->reflectionClass->getVisibilityLevel()) as $method) { $apiMethod = $this->reflectionClass->getReflectionFactory()->createFromReflection($method); if ( ! $this->reflectionClass->isDocumented() || $apiMethod->isDocumented()) { /** @var ReflectionMethod $method */ $methods[$method->getName()] = $apiMethod; } } return $methods; } /** * @return array {[ traitName => ReflectionProperty[] ]} */ public function getUsedProperties() { $allProperties = array_flip(array_map(function (ReflectionProperty $property) { return $property->getName(); }, $this->reflectionClass->getOwnProperties())); $properties = []; foreach ($this->reflectionClass->getTraits() as $trait) { if ( ! $trait instanceof ReflectionClass) { continue; } $usedProperties = []; foreach ($trait->getOwnProperties() as $property) { if ( ! array_key_exists($property->getName(), $allProperties)) { $usedProperties[$property->getName()] = $property; $allProperties[$property->getName()] = NULL; } } if ( ! empty($usedProperties)) { ksort($usedProperties); $properties[$trait->getName()] = array_values($usedProperties); } } return $properties; } /** * @return array {[ traitName => ReflectionMethod[] ]} */ public function getUsedMethods() { $usedMethods = []; foreach ($this->reflectionClass->getMethods() as $method) { if ($method->getDeclaringTraitName() === NULL || $method->getDeclaringTraitName() === $this->reflectionClass->getName() ) { continue; } $usedMethods[$method->getDeclaringTraitName()][$method->getName()]['method'] = $method; if ($method->getOriginalName() !== NULL && $method->getOriginalName() !== $method->getName()) { $usedMethods[$method->getDeclaringTraitName()][$method->getName()]['aliases'][$method->getName()] = $method; } } return $usedMethods; } } ApiGen-4.1.2/src/Reflection/Extractors/MagicMethodExtractor.php000066400000000000000000000045641262665576200245200ustar00rootroot00000000000000getParentClass()) { $methods += $this->extractFromParentClass($parentClass, $reflectionClass->isDocumented()); } if ($traits = $reflectionClass->getTraits()) { $methods += $this->extractFromTraits($traits, $reflectionClass->isDocumented()); } return $methods; } /** * @param ReflectionClass $parent * @param bool $isDocumented * @return ReflectionMethodMagic[] */ private function extractFromParentClass(ReflectionClass $parent, $isDocumented) { $methods = []; while ($parent) { $methods = $this->extractOwnFromClass($parent, $isDocumented, $methods); $parent = $parent->getParentClass(); } return $methods; } /** * @param array $traits * @param bool $isDocumented * @return ReflectionMethodMagic[] */ private function extractFromTraits($traits, $isDocumented) { $methods = []; foreach ($traits as $trait) { if ( ! $trait instanceof ReflectionClass) { continue; } $methods = $this->extractOwnFromClass($trait, $isDocumented, $methods); } return $methods; } /** * @param ReflectionClass $reflectionClass * @param bool $isDocumented * @param array $methods * @return ReflectionMethodMagic[] */ private function extractOwnFromClass(ReflectionClass $reflectionClass, $isDocumented, array $methods) { foreach ($reflectionClass->getOwnMagicMethods() as $method) { if ($this->canBeExtracted($isDocumented, $methods, $method)) { $methods[$method->getName()] = $method; } } return $methods; } /** * @param bool $isDocumented * @param array $methods * @param ReflectionMethodMagic $method * @return bool */ private function canBeExtracted($isDocumented, array $methods, ReflectionMethodMagic $method) { if (isset($methods[$method->getName()])) { return FALSE; } if ($isDocumented && ! $method->isDocumented()) { return FALSE; } return TRUE; } } ApiGen-4.1.2/src/Reflection/Extractors/MagicPropertyExtractor.php000066400000000000000000000047221262665576200251200ustar00rootroot00000000000000getParentClass()) { $properties += $this->extractFromParentClass($parentClass, $reflectionClass->isDocumented()); } if ($traits = $reflectionClass->getTraits()) { $properties += $this->extractFromTraits($traits, $reflectionClass->isDocumented()); } return $properties; } /** * @param ReflectionClass $parent * @param bool $isDocumented * @return ReflectionPropertyMagic[] */ private function extractFromParentClass(ReflectionClass $parent, $isDocumented) { $properties = []; while ($parent) { $properties = $this->extractOwnFromClass($parent, $isDocumented, $properties); $parent = $parent->getParentClass(); } return $properties; } /** * @param array $traits * @param bool $isDocumented * @return ReflectionPropertyMagic[] */ private function extractFromTraits($traits, $isDocumented) { $properties = []; foreach ($traits as $trait) { if ( ! $trait instanceof ReflectionClass) { continue; } $properties = $this->extractOwnFromClass($trait, $isDocumented, $properties); } return $properties; } /** * @param ReflectionClass $reflectionClass * @param bool $isDocumented * @param array $properties * @return ReflectionPropertyMagic[] */ private function extractOwnFromClass(ReflectionClass $reflectionClass, $isDocumented, array $properties) { foreach ($reflectionClass->getOwnMagicProperties() as $property) { if ($this->canBeExtracted($isDocumented, $properties, $property)) { $properties[$property->getName()] = $property; } } return $properties; } /** * @param bool $isDocumented * @param array $properties * @param ReflectionPropertyMagic $property * @return bool */ private function canBeExtracted($isDocumented, array $properties, ReflectionPropertyMagic $property) { if (isset($properties[$property->getName()])) { return FALSE; } if ($isDocumented && ! $property->isDocumented()) { return FALSE; } return TRUE; } } ApiGen-4.1.2/src/Reflection/Extractors/ParentClassElementsExtractor.php000066400000000000000000000055301262665576200262450ustar00rootroot00000000000000reflectionClass = $reflectionClass; } /** * @return array */ public function getInheritedConstants() { return array_filter( array_map( function (ReflectionClass $class) { $reflections = $class->getOwnConstants(); ksort($reflections); return $reflections; }, $this->getParentClassesAndInterfaces() ) ); } /** * @return array {[ className => ReflectionProperties[] ]} */ public function getInheritedProperties() { $properties = []; $allProperties = array_flip(array_map(function (ReflectionProperty $property) { return $property->getName(); }, $this->reflectionClass->getOwnProperties())); foreach ($this->reflectionClass->getParentClasses() as $class) { $inheritedProperties = []; foreach ($class->getOwnProperties() as $property) { if ( ! array_key_exists($property->getName(), $allProperties) && ! $property->isPrivate()) { $inheritedProperties[$property->getName()] = $property; $allProperties[$property->getName()] = NULL; } } $properties = $this->sortElements($inheritedProperties, $properties, $class); } return $properties; } /** * @return array {[ className => ReflectionMethod[] ]} */ public function getInheritedMethods() { $methods = []; $allMethods = array_flip(array_map(function (ReflectionMethod $method) { return $method->getName(); }, $this->reflectionClass->getOwnMethods())); foreach ($this->getParentClassesAndInterfaces() as $class) { $inheritedMethods = []; foreach ($class->getOwnMethods() as $method) { if ( ! array_key_exists($method->getName(), $allMethods) && ! $method->isPrivate()) { $inheritedMethods[$method->getName()] = $method; $allMethods[$method->getName()] = NULL; } } $methods = $this->sortElements($inheritedMethods, $methods, $class); } return $methods; } /** * @return ReflectionClass[]|array */ private function getParentClassesAndInterfaces() { return array_merge($this->reflectionClass->getParentClasses(), $this->reflectionClass->getInterfaces()); } /** * @return array */ private function sortElements(array $elements, array $allElements, ReflectionClass $reflectionClass) { if ( ! empty($elements)) { ksort($elements); $allElements[$reflectionClass->getName()] = array_values($elements); } return $allElements; } } ApiGen-4.1.2/src/Reflection/Parts/000077500000000000000000000000001262665576200166545ustar00rootroot00000000000000ApiGen-4.1.2/src/Reflection/Parts/IsDocumentedMagic.php000066400000000000000000000013601262665576200227110ustar00rootroot00000000000000isDocumented === NULL) { $deprecated = $this->configuration->getOption(CO::DEPRECATED); $this->isDocumented = $deprecated || ! $this->isDeprecated(); } return $this->isDocumented; } } ApiGen-4.1.2/src/Reflection/Parts/StartLineEndLine.php000066400000000000000000000015031262665576200225300ustar00rootroot00000000000000startLine = $startLine; return $this; } /** * @return int */ public function getStartLine() { return $this->startLine; } /** * @param int $endLine * @return $this */ public function setEndLine($endLine) { $this->endLine = $endLine; return $this; } /** * @return int */ public function getEndLine() { return $this->endLine; } } ApiGen-4.1.2/src/Reflection/Parts/StartPositionEndPositionMagic.php000066400000000000000000000011531262665576200253240ustar00rootroot00000000000000declaringClass->getStartPosition(); } /** * @return int */ public function getEndPosition() { return $this->declaringClass->getEndPosition(); } } ApiGen-4.1.2/src/Reflection/Parts/Visibility.php000066400000000000000000000013401262665576200215120ustar00rootroot00000000000000reflection->isPrivate(); } /** * @return bool */ public function isProtected() { return $this->reflection->isProtected(); } /** * @return bool */ public function isPublic() { return $this->reflection->isPublic(); } } ApiGen-4.1.2/src/Reflection/ReflectionBase.php000066400000000000000000000053031262665576200211620ustar00rootroot00000000000000reflectionType = get_class($this); $this->reflection = $reflection; } /** * @return string */ public function getName() { return $this->reflection->getName(); } /** * @return string */ public function getPrettyName() { return $this->reflection->getPrettyName(); } /** * @return bool */ public function isInternal() { return $this->reflection->isInternal(); } /** * @return bool */ public function isTokenized() { return $this->reflection->isTokenized(); } /** * @return string */ public function getFileName() { return $this->reflection->getFileName(); } /** * @return int */ public function getStartLine() { $startLine = $this->reflection->getStartLine(); if ($doc = $this->getDocComment()) { $startLine -= substr_count($doc, "\n") + 1; } return $startLine; } /** * @return int */ public function getEndLine() { return $this->reflection->getEndLine(); } public function setConfiguration(Configuration $configuration) { $this->configuration = $configuration; } public function setParserResult(ParserResult $parserResult) { $this->parserResult = $parserResult; } public function setReflectionFactory(ReflectionFactory $reflectionFactory) { $this->reflectionFactory = $reflectionFactory; } /** * @return ArrayObject|ReflectionClass[] */ public function getParsedClasses() { return $this->parserResult->getElementsByType(Elements::CLASSES); } } ApiGen-4.1.2/src/Reflection/ReflectionClass.php000066400000000000000000000407431262665576200213640ustar00rootroot00000000000000classMagicElementExtractor = new ClassMagicElementsExtractor($this); $this->classTraitElementExtractor = new ClassTraitElementsExtractor($this, $reflectionClass); $this->parentClassElementExtractor = new ParentClassElementsExtractor($this); } /** * @return string */ public function getShortName() { return $this->reflection->getShortName(); } /** * @return bool */ public function isAbstract() { return $this->reflection->isAbstract(); } /** * @return bool */ public function isFinal() { return $this->reflection->isFinal(); } /** * @return bool */ public function isInterface() { return $this->reflection->isInterface(); } /** * @return bool */ public function isException() { return $this->reflection->isException(); } /** * @param string $class * @return bool */ public function isSubclassOf($class) { return $this->reflection->isSubclassOf($class); } /** * @return ReflectionMethod[] */ public function getMethods() { if ($this->methods === NULL) { $this->methods = $this->getOwnMethods(); foreach ($this->getOwnTraits() as $trait) { if (!$trait instanceof ReflectionClass) { continue; } foreach ($trait->getOwnMethods() as $method) { if (isset($this->methods[$method->getName()])) { continue; } if (! $this->isDocumented() || $method->isDocumented()) { $this->methods[$method->getName()] = $method; } } } if (null !== $this->getParentClassName()) { foreach ($this->getParentClass()->getMethods() as $parentMethod) { if (!isset($this->methods[$parentMethod->getName()])) { $this->methods[$parentMethod->getName()] = $parentMethod; } } } foreach ($this->getOwnInterfaces() as $interface) { foreach ($interface->getMethods(null) as $parentMethod) { if (!isset($this->methods[$parentMethod->getName()])) { $this->methods[$parentMethod->getName()] = $parentMethod; } } } $this->methods = array_filter($this->methods, function(ReflectionMethod $method) { $classVisibilityLevel = $this->getVisibilityLevel(); $methodVisibilityLevel = $method->configuration->getOption(CO::VISIBILITY_LEVELS); return $classVisibilityLevel === $methodVisibilityLevel; }); } return $this->methods; } /** * @return ReflectionMethod[] */ public function getOwnMethods() { if ($this->ownMethods === NULL) { $this->ownMethods = []; foreach ($this->reflection->getOwnMethods($this->getVisibilityLevel()) as $method) { $apiMethod = $this->reflectionFactory->createFromReflection($method); if ( ! $this->isDocumented() || $apiMethod->isDocumented()) { $this->ownMethods[$method->getName()] = $apiMethod; } } } return $this->ownMethods; } /** * @return ReflectionMethodMagic[] */ public function getMagicMethods() { return $this->classMagicElementExtractor->getMagicMethods(); } /** * @return ReflectionMethodMagic[] */ public function getOwnMagicMethods() { return $this->classMagicElementExtractor->getOwnMagicMethods(); } /** * @return ReflectionMethod[] */ public function getTraitMethods() { return $this->classTraitElementExtractor->getTraitMethods(); } /** * @param string $name * @return ReflectionMethod */ public function getMethod($name) { if ($this->hasMethod($name)) { return $this->methods[$name]; } throw new InvalidArgumentException(sprintf( 'Method %s does not exist in class %s', $name, $this->reflection->getName() )); } /** * @return ReflectionProperty[] */ public function getProperties() { if ($this->properties === NULL) { $this->properties = $this->getOwnProperties(); foreach ($this->reflection->getProperties($this->getVisibilityLevel()) as $property) { /** @var ReflectionElement $property */ if (isset($this->properties[$property->getName()])) { continue; } $apiProperty = $this->reflectionFactory->createFromReflection($property); if ( ! $this->isDocumented() || $apiProperty->isDocumented()) { $this->properties[$property->getName()] = $apiProperty; } } } return $this->properties; } /** * @return ReflectionPropertyMagic[] */ public function getMagicProperties() { return $this->classMagicElementExtractor->getMagicProperties(); } /** * @return ReflectionPropertyMagic[] */ public function getOwnMagicProperties() { return $this->classMagicElementExtractor->getOwnMagicProperties(); } /** * @return ReflectionProperty[] */ public function getOwnProperties() { if ($this->ownProperties === NULL) { $this->ownProperties = []; foreach ($this->reflection->getOwnProperties($this->getVisibilityLevel()) as $property) { $apiProperty = $this->reflectionFactory->createFromReflection($property); if ( ! $this->isDocumented() || $apiProperty->isDocumented()) { /** @var ReflectionElement $property */ $this->ownProperties[$property->getName()] = $apiProperty; } } } return $this->ownProperties; } /** * @return ReflectionProperty[] */ public function getTraitProperties() { return $this->classTraitElementExtractor->getTraitProperties(); } /** * @param string $name * @return ReflectionProperty */ public function getProperty($name) { if ($this->hasProperty($name)) { return $this->properties[$name]; } throw new InvalidArgumentException(sprintf( 'Property %s does not exist in class %s', $name, $this->reflection->getName() )); } /** * @return ReflectionConstant[] */ public function getConstants() { if ($this->constants === NULL) { $this->constants = []; foreach ($this->reflection->getConstantReflections() as $constant) { $apiConstant = $this->reflectionFactory->createFromReflection($constant); if ( ! $this->isDocumented() || $apiConstant->isDocumented()) { /** @var ReflectionElement $constant */ $this->constants[$constant->getName()] = $apiConstant; } } } return $this->constants; } /** * @return ReflectionConstant[]|array */ public function getOwnConstants() { if ($this->ownConstants === NULL) { $this->ownConstants = []; $className = $this->reflection->getName(); foreach ($this->getConstants() as $constantName => $constant) { if ($className === $constant->getDeclaringClassName()) { $this->ownConstants[$constantName] = $constant; } } } return $this->ownConstants; } /** * @param string $name * @return ReflectionConstant */ public function getConstantReflection($name) { if (isset($this->getConstants()[$name])) { return $this->getConstants()[$name]; } throw new InvalidArgumentException(sprintf( 'Constant %s does not exist in class %s', $name, $this->reflection->getName() )); } /** * @param string $name * @return ReflectionConstant */ public function getConstant($name) { return $this->getConstantReflection($name); } /** * @param string $name * @return bool */ public function hasConstant($name) { return isset($this->getConstants()[$name]); } /** * @param string $name * @return bool */ public function hasOwnConstant($name) { return isset($this->getOwnConstants()[$name]); } /** * @param string $name * @return ReflectionConstant */ public function getOwnConstant($name) { if (isset($this->getOwnConstants()[$name])) { return $this->getOwnConstants()[$name]; } throw new InvalidArgumentException(sprintf( 'Constant %s does not exist in class %s', $name, $this->reflection->getName() )); } /** * @return ReflectionClass */ public function getParentClass() { if ($className = $this->reflection->getParentClassName()) { return $this->getParsedClasses()[$className]; } return $className; } /** * @return string|NULL */ public function getParentClassName() { return $this->reflection->getParentClassName(); } /** * @return ReflectionClass[] */ public function getParentClasses() { if ($this->parentClasses === NULL) { $this->parentClasses = array_map(function (IReflectionClass $class) { return $this->getParsedClasses()[$class->getName()]; }, $this->reflection->getParentClasses()); } return $this->parentClasses; } /** * @return array */ public function getParentClassNameList() { return $this->reflection->getParentClassNameList(); } /** * @param string|object $interface * @return bool */ public function implementsInterface($interface) { return $this->reflection->implementsInterface($interface); } /** * @return ReflectionClass[]|array */ public function getInterfaces() { return array_map(function (IReflectionClass $class) { return $this->getParsedClasses()[$class->getName()]; }, $this->reflection->getInterfaces()); } /** * @return ReflectionClass[]|array */ public function getOwnInterfaces() { return array_map(function (IReflectionClass $class) { return $this->getParsedClasses()[$class->getName()]; }, $this->reflection->getOwnInterfaces()); } /** * @return string[] */ public function getOwnInterfaceNames() { return $this->reflection->getOwnInterfaceNames(); } /** * @return ReflectionClass[]|string[] */ public function getTraits() { return array_map(function (IReflectionClass $class) { if ( ! isset($this->getParsedClasses()[$class->getName()])) { return $class->getName(); } else { return $this->getParsedClasses()[$class->getName()]; } }, $this->reflection->getTraits()); } /** * @return array */ public function getTraitNames() { return $this->reflection->getTraitNames(); } /** * @return array */ public function getOwnTraitNames() { return $this->reflection->getOwnTraitNames(); } /** * @return array */ public function getTraitAliases() { return $this->reflection->getTraitAliases(); } /** * @return ReflectionClass[]|string[] */ public function getOwnTraits() { return array_map(function (IReflectionClass $class) { if ( ! isset($this->getParsedClasses()[$class->getName()])) { return $class->getName(); } else { return $this->getParsedClasses()[$class->getName()]; } }, $this->reflection->getOwnTraits()); } /** * @return bool */ public function isTrait() { return $this->reflection->isTrait(); } /** * @param string $trait * @return bool */ public function usesTrait($trait) { return $this->reflection->usesTrait($trait); } /** * @return ReflectionClass[]|array */ public function getDirectSubClasses() { $subClasses = []; foreach ($this->getParsedClasses() as $class) { if ($class->isDocumented() && $this->getName() === $class->getParentClassName()) { $subClasses[] = $class; } } uksort($subClasses, 'strcasecmp'); return $subClasses; } /** * @return ReflectionClass[]|array */ public function getIndirectSubClasses() { $subClasses = []; foreach ($this->getParsedClasses() as $class) { if ($class->isDocumented() && $this->getName() !== $class->getParentClassName() && $class->isSubclassOf($this->getName()) ) { $subClasses[] = $class; } } uksort($subClasses, 'strcasecmp'); return $subClasses; } /** * @return array */ public function getDirectImplementers() { if ( ! $this->isInterface()) { return []; } return $this->parserResult->getDirectImplementersOfInterface($this); } /** * @return array */ public function getIndirectImplementers() { if ( ! $this->isInterface()) { return []; } return $this->parserResult->getIndirectImplementersOfInterface($this); } /** * @return ReflectionClass[]|array */ public function getDirectUsers() { if ( ! $this->isTrait()) { return []; } return $this->classTraitElementExtractor->getDirectUsers(); } /** * @return ReflectionClass[]|array */ public function getIndirectUsers() { if ( ! $this->isTrait()) { return []; } return $this->classTraitElementExtractor->getIndirectUsers(); } /** * @return array {[ className => ReflectionMethod[] ]} */ public function getInheritedMethods() { return $this->parentClassElementExtractor->getInheritedMethods(); } /** * @return array */ public function getInheritedMagicMethods() { return $this->classMagicElementExtractor->getInheritedMagicMethods(); } /** * @return array */ public function getUsedMethods() { $usedMethods = $this->classTraitElementExtractor->getUsedMethods(); return $this->sortUsedMethods($usedMethods); } /** * @return array */ public function getUsedMagicMethods() { $usedMethods = $this->classMagicElementExtractor->getUsedMagicMethods(); return $this->sortUsedMethods($usedMethods); } /** * @return array */ public function getInheritedConstants() { return $this->parentClassElementExtractor->getInheritedConstants(); } /** * @return array {[ className => ReflectionProperty[] ]} */ public function getInheritedProperties() { return $this->parentClassElementExtractor->getInheritedProperties(); } /** * @return ReflectionPropertyMagic[]|array */ public function getInheritedMagicProperties() { return $this->classMagicElementExtractor->getInheritedMagicProperties(); } /** * @return array {[ traitName => ReflectionProperty[] ]} */ public function getUsedProperties() { return $this->classTraitElementExtractor->getUsedProperties(); } /** * @return array */ public function getUsedMagicProperties() { return $this->classMagicElementExtractor->getUsedMagicProperties(); } /** * @param string $name * @return bool */ public function hasProperty($name) { if ($this->properties === NULL) { $this->getProperties(); } return isset($this->properties[$name]); } /** * @param string $name * @return bool */ public function hasMethod($name) { return isset($this->getMethods()[$name]); } /** * @return bool */ public function isValid() { if ($this->reflection instanceof TokenReflection\Invalid\ReflectionClass) { return FALSE; } return TRUE; } /** * @return bool */ public function isDocumented() { if ($this->isDocumented === NULL && parent::isDocumented()) { $fileName = $this->reflection->getFilename(); $skipDocPath = $this->configuration->getOption(CO::SKIP_DOC_PATH); foreach ($skipDocPath as $mask) { if (fnmatch($mask, $fileName, FNM_NOESCAPE)) { $this->isDocumented = FALSE; break; } } } return $this->isDocumented; } /** * @return bool */ public function isVisibilityLevelPublic() { return $this->getVisibilityLevel() & Visibility::IS_PUBLIC; } /** * @return ReflectionFactory */ public function getReflectionFactory() { return $this->reflectionFactory; } /** * @return int */ public function getVisibilityLevel() { return $this->configuration->getOption(CO::VISIBILITY_LEVELS); } /** * @return array */ private function sortUsedMethods(array $usedMethods) { array_walk($usedMethods, function (&$methods) { ksort($methods); array_walk($methods, function (&$aliasedMethods) { if ( ! isset($aliasedMethods['aliases'])) { $aliasedMethods['aliases'] = []; } ksort($aliasedMethods['aliases']); }); }); return $usedMethods; } } ApiGen-4.1.2/src/Reflection/ReflectionConstant.php000066400000000000000000000045201262665576200221010ustar00rootroot00000000000000reflection->getName(); } /** * Returns the unqualified name (UQN). * * @return string */ public function getShortName() { return $this->reflection->getShortName(); } /** * @return string */ public function getTypeHint() { if ($annotations = $this->getAnnotation('var')) { list($types) = preg_split('~\s+|$~', $annotations[0], 2); if ( ! empty($types)) { return $types; } } try { $type = gettype($this->getValue()); if (strtolower($type) !== 'null') { return $type; } } catch (\Exception $e) { return NULL; } } /** * @return ReflectionClass|NULL */ public function getDeclaringClass() { $className = $this->reflection->getDeclaringClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string|NULL */ public function getDeclaringClassName() { return $this->reflection->getDeclaringClassName(); } /** * @return mixed */ public function getValue() { return $this->reflection->getValue(); } /** * @return string */ public function getValueDefinition() { return $this->reflection->getValueDefinition(); } /** * @return bool */ public function isValid() { if ($this->reflection instanceof TokenReflection\Invalid\ReflectionConstant) { return FALSE; } if ($class = $this->getDeclaringClass()) { return $class->isValid(); } return TRUE; } /** * @return bool */ public function isDocumented() { if ($this->isDocumented === NULL && parent::isDocumented() && $this->reflection->getDeclaringClassName() === NULL) { $fileName = $this->reflection->getFilename(); $skipDocPath = $this->configuration->getOption(CO::SKIP_DOC_PATH); foreach ($skipDocPath as $mask) { if (fnmatch($mask, $fileName, FNM_NOESCAPE)) { $this->isDocumented = FALSE; break; } } } return $this->isDocumented; } } ApiGen-4.1.2/src/Reflection/ReflectionElement.php000066400000000000000000000200561262665576200217030ustar00rootroot00000000000000reflection->getExtension(); return $extension === NULL ? NULL : $this->reflectionFactory->createFromReflection($extension); } /** * @return bool */ public function getExtensionName() { return $this->reflection->getExtensionName(); } /** * @return int */ public function getStartPosition() { return $this->reflection->getStartPosition(); } /** * @return int */ public function getEndPosition() { return $this->reflection->getEndPosition(); } /** * @return bool */ public function isMain() { $main = $this->configuration->getOption(CO::MAIN); return empty($main) || strpos($this->getName(), $main) === 0; } /** * @return bool */ public function isDocumented() { if ($this->isDocumented === NULL) { $this->isDocumented = $this->reflection->isTokenized() || $this->reflection->isInternal(); if ($this->isDocumented) { $php = $this->configuration->getOption(CO::PHP); $internal = $this->configuration->getOption(CO::INTERNAL); if ( ! $php && $this->reflection->isInternal()) { $this->isDocumented = FALSE; } elseif ( ! $internal && ($internal = $this->reflection->getAnnotation('internal')) && empty($internal[0]) ) { $this->isDocumented = FALSE; } elseif ($this->reflection->hasAnnotation('ignore')) { $this->isDocumented = FALSE; } } } return $this->isDocumented; } /** * @return bool */ public function isDeprecated() { if ($this->reflection->isDeprecated()) { return TRUE; } if (($this instanceof ReflectionMethod || $this instanceof ReflectionProperty || $this instanceof ReflectionConstant) && $class = $this->getDeclaringClass() ) { return $class->isDeprecated(); } return FALSE; } /** * @return bool */ public function inPackage() { return ($this->getPackageName() !== ''); } /** * @return string */ public function getPackageName() { static $packages = []; if ($package = $this->getAnnotation('package')) { $packageName = preg_replace('~\s+.*~s', '', $package[0]); if (empty($packageName)) { return ''; } if ($subpackage = $this->getAnnotation('subpackage')) { $subpackageName = preg_replace('~\s+.*~s', '', $subpackage[0]); if ( ! empty($subpackageName) && strpos($subpackageName, $packageName) === 0) { $packageName = $subpackageName; } else { $packageName .= '\\' . $subpackageName; } } $packageName = strtr($packageName, '._/', '\\\\\\'); $lowerPackageName = strtolower($packageName); if ( ! isset($packages[$lowerPackageName])) { $packages[$lowerPackageName] = $packageName; } return $packages[$lowerPackageName]; } return ''; } /** * Returns element package name (including subpackage name). * For internal elements returns "PHP", for elements in global space returns "None". * * @return string */ public function getPseudoPackageName() { if ($this->isInternal()) { return 'PHP'; } return $this->getPackageName() ?: 'None'; } /** * @return bool */ public function inNamespace() { return $this->getNamespaceName() !== ''; } /** * @return string */ public function getNamespaceName() { static $namespaces = []; $namespaceName = $this->reflection->getNamespaceName(); if ( ! $namespaceName) { return $namespaceName; } $lowerNamespaceName = strtolower($namespaceName); if ( ! isset($namespaces[$lowerNamespaceName])) { $namespaces[$lowerNamespaceName] = $namespaceName; } return $namespaces[$lowerNamespaceName]; } /** * Returns element namespace name. * For internal elements returns "PHP", for elements in global space returns "None". * * @return string */ public function getPseudoNamespaceName() { return $this->isInternal() ? 'PHP' : $this->getNamespaceName() ?: 'None'; } /** * @return string[] */ public function getNamespaceAliases() { return $this->reflection->getNamespaceAliases(); } /** * @return string */ public function getShortDescription() { $short = $this->reflection->getAnnotation(ReflectionAnnotation::SHORT_DESCRIPTION); if ( ! empty($short)) { return $short; } if ($this instanceof ReflectionProperty || $this instanceof ReflectionConstant) { $var = $this->getAnnotation('var'); list(, $short) = preg_split('~\s+|$~', $var[0], 2); } return $short; } /** * @return string */ public function getLongDescription() { $short = $this->getShortDescription(); $long = $this->reflection->getAnnotation(ReflectionAnnotation::LONG_DESCRIPTION); if ( ! empty($long)) { $short .= "\n\n" . $long; } return $short; } /** * @return string|bool */ public function getDocComment() { return $this->reflection->getDocComment(); } /** * Returns reflection element annotations. * Removes the short and long description. * In case of classes, functions and constants, @package, @subpackage, @author and @license annotations * are added from declaring files if not already present. * * @return array */ public function getAnnotations() { if ($this->annotations === NULL) { $annotations = $this->reflection->getAnnotations(); $annotations = array_change_key_case($annotations, CASE_LOWER); unset($annotations[ReflectionAnnotation::SHORT_DESCRIPTION]); unset($annotations[ReflectionAnnotation::LONG_DESCRIPTION]); $annotations += $this->getAnnotationsFromReflection($this->reflection); $this->annotations = $annotations; } return $this->annotations; } /** * @param string $annotation * @return array */ public function getAnnotation($annotation) { $annotations = $this->getAnnotations(); return isset($annotations[$annotation]) ? $annotations[$annotation] : NULL; } /** * @param string $annotation * @return bool */ public function hasAnnotation($annotation) { $annotations = $this->getAnnotations(); return isset($annotations[$annotation]); } /** * @param string $annotation * @param string $value * @return ReflectionElement */ public function addAnnotation($annotation, $value) { if ($this->annotations === NULL) { $this->getAnnotations(); } $this->annotations[$annotation][] = $value; return $this; } /** * @return TokenReflection\Invalid\ReflectionElement */ public function addReason(BaseException $reason) { $this->reasons[] = $reason; return $this; } /** * @return TokenReflection\Invalid\ReflectionElement */ public function getReasons() { return $this->reasons; } /** * @return bool */ public function hasReasons() { return ! empty($this->reasons); } /** * @param mixed $reflection * @return array */ private function getAnnotationsFromReflection($reflection) { $fileLevel = [ 'package' => TRUE, 'subpackage' => TRUE, 'author' => TRUE, 'license' => TRUE, 'copyright' => TRUE ]; $annotations = []; if ($reflection instanceof ReflectionClass || $reflection instanceof ReflectionFunction || ($reflection instanceof ReflectionConstant && $reflection->getDeclaringClassName() === NULL) ) { foreach ($reflection->getFileReflection()->getAnnotations() as $name => $value) { if (isset($fileLevel[$name]) && empty($annotations[$name])) { $annotations[$name] = $value; } } } return $annotations; } } ApiGen-4.1.2/src/Reflection/ReflectionExtension.php000066400000000000000000000004411262665576200222620ustar00rootroot00000000000000reflection instanceof TokenReflection\Invalid\ReflectionFunction) { return FALSE; } return TRUE; } /** * @return bool */ public function isDocumented() { if ($this->isDocumented === NULL && parent::isDocumented()) { $fileName = $this->reflection->getFilename(); $skipDocPath = $this->configuration->getOption(CO::SKIP_DOC_PATH); foreach ($skipDocPath as $mask) { if (fnmatch($mask, $fileName, FNM_NOESCAPE)) { $this->isDocumented = FALSE; break; } } } return $this->isDocumented; } } ApiGen-4.1.2/src/Reflection/ReflectionFunctionBase.php000066400000000000000000000052331262665576200226720ustar00rootroot00000000000000reflection->getShortName(); } /** * @return bool */ public function returnsReference() { return $this->reflection->returnsReference(); } /** * @return ReflectionParameter[] */ public function getParameters() { if ($this->parameters === NULL) { $this->parameters = array_map(function (IReflectionParameter $parameter) { return $this->reflectionFactory->createFromReflection($parameter); }, $this->reflection->getParameters()); $annotations = (array) $this->getAnnotation('param'); foreach ($annotations as $position => $annotation) { if (isset($this->parameters[$position])) { // Standard parameter continue; } $this->processAnnotation($annotation, $position); } } return $this->parameters; } /** * @param int|string $key * @return ReflectionParameter */ public function getParameter($key) { $parameters = $this->getParameters(); if (isset($parameters[$key])) { return $parameters[$key]; } foreach ($parameters as $parameter) { if ($parameter->getName() === $key) { return $parameter; } } throw new InvalidArgumentException(sprintf( 'There is no parameter with name/position "%s" in function/method "%s"', $key, $this->getName() )); } /** * @return int */ public function getNumberOfParameters() { return count($this->getParameters()); } /** * @return int */ public function getNumberOfRequiredParameters() { return $this->reflection->getNumberOfRequiredParameters(); } /** * @param string $annotation * @param int $position */ private function processAnnotation($annotation, $position) { if ( ! preg_match(self::PARAM_ANNOTATION, $annotation, $matches)) { return; } list(, $typeHint, $name) = $matches; $this->parameters[$position] = $this->reflectionFactory->createParameterMagic([ 'name' => $name, 'position' => $position, 'typeHint' => $typeHint, 'defaultValueDefinition' => NULL, 'unlimited' => TRUE, 'passedByReference' => FALSE, 'declaringFunction' => $this ]); } } ApiGen-4.1.2/src/Reflection/ReflectionMethod.php000066400000000000000000000057761262665576200215460ustar00rootroot00000000000000reflection->getDeclaringClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string|NULL */ public function getDeclaringClassName() { return $this->reflection->getDeclaringClassName(); } /** * @return bool */ public function isAbstract() { return $this->reflection->isAbstract(); } /** * @return bool */ public function isFinal() { return $this->reflection->isFinal(); } /** * @return bool */ public function isStatic() { return $this->reflection->isStatic(); } /** * @return bool */ public function isConstructor() { return $this->reflection->isConstructor(); } /** * @return bool */ public function isDestructor() { return $this->reflection->isDestructor(); } /** * @return ReflectionClass|NULL */ public function getDeclaringTrait() { $traitName = $this->reflection->getDeclaringTraitName(); return $traitName === NULL ? NULL : $this->getParsedClasses()[$traitName]; } /** * @return string|NULL */ public function getDeclaringTraitName() { return $this->reflection->getDeclaringTraitName(); } /** * @return ReflectionMethod|NULL */ public function getImplementedMethod() { foreach ($this->getDeclaringClass()->getOwnInterfaces() as $interface) { if ($interface->hasMethod($this->getName())) { return $interface->getMethod($this->getName()); } } return NULL; } /** * @return ReflectionMethod|NULL */ public function getOverriddenMethod() { $parent = $this->getDeclaringClass()->getParentClass(); if ($parent === NULL) { return NULL; } foreach ($parent->getMethods() as $method) { if ($method->getName() === $this->getName()) { if ( ! $method->isPrivate() && ! $method->isAbstract()) { return $method; } else { return NULL; } } } return NULL; } /** * @return ReflectionMethod|NULL */ public function getOriginal() { $originalName = $this->reflection->getOriginalName(); if ($originalName === NULL) { return NULL; } $originalDeclaringClassName = $this->reflection->getOriginal()->getDeclaringClassName(); return $this->getParsedClasses()[$originalDeclaringClassName]->getMethod($originalName); } /** * @return string|NULL */ public function getOriginalName() { return $this->reflection->getOriginalName(); } /** * @return bool */ public function isValid() { if ($class = $this->getDeclaringClass()) { return $class->isValid(); } return TRUE; } } ApiGen-4.1.2/src/Reflection/ReflectionMethodMagic.php000066400000000000000000000144641262665576200225010ustar00rootroot00000000000000name = $settings['name']; $this->shortDescription = $settings['shortDescription']; $this->startLine = $settings['startLine']; $this->endLine = $settings['endLine']; $this->returnsReference = $settings['returnsReference']; $this->declaringClass = $settings['declaringClass']; $this->annotations = $settings['annotations']; $this->reflectionType = get_class($this); } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function getShortDescription() { return $this->shortDescription; } /** * @return string */ public function getLongDescription() { return $this->shortDescription; } /** * @return bool */ public function returnsReference() { return $this->returnsReference; } /** * @return bool */ public function isMagic() { return TRUE; } /** * Returns the unqualified name (UQN). * * @return string */ public function getShortName() { return $this->name; } /** * @return bool */ public function isDeprecated() { return $this->declaringClass->isDeprecated(); } /** * @return string */ public function getPackageName() { return $this->declaringClass->getPackageName(); } /** * @return string */ public function getNamespaceName() { return $this->declaringClass->getNamespaceName(); } /** * @return array */ public function getAnnotations() { if ($this->annotations === NULL) { $this->annotations = []; } return $this->annotations; } /** * @return ReflectionClass */ public function getDeclaringClass() { return $this->declaringClass; } /** * @return string */ public function getDeclaringClassName() { return $this->declaringClass->getName(); } /** * @return bool */ public function isAbstract() { return FALSE; } /** * @return bool */ public function isFinal() { return FALSE; } /** * @return bool */ public function isPrivate() { return FALSE; } /** * @return bool */ public function isProtected() { return FALSE; } /** * @return bool */ public function isPublic() { return TRUE; } /** * @return bool */ public function isStatic() { return FALSE; } /** * @return bool */ public function isConstructor() { return FALSE; } /** * @return bool */ public function isDestructor() { return FALSE; } /** * @return ReflectionClass|NULL */ public function getDeclaringTrait() { return $this->declaringClass->isTrait() ? $this->declaringClass : NULL; } /** * @return string|NULL */ public function getDeclaringTraitName() { if ($declaringTrait = $this->getDeclaringTrait()) { return $declaringTrait->getName(); } return NULL; } /** * @return ReflectionMethod|NULL */ public function getImplementedMethod() { return NULL; } /** * @return ReflectionMethod|NULL */ public function getOverriddenMethod() { $parent = $this->declaringClass->getParentClass(); if ($parent === NULL) { return NULL; } foreach ($parent->getMagicMethods() as $method) { if ($method->getName() === $this->name) { return $method; } } return NULL; } /** * @return string */ public function getOriginalName() { return $this->getName(); } /** * @return ReflectionMethod|NULL */ public function getOriginal() { return NULL; } /** * @return array */ public function getParameters() { return $this->parameters; } public function setParameters(array $parameters) { $this->parameters = $parameters; } /** * @return int */ public function getNumberOfParameters() { return count($this->parameters); } /** * @return int */ public function getNumberOfRequiredParameters() { $count = 0; array_walk($this->parameters, function (ReflectionParameter $parameter) use (&$count) { if ( ! $parameter->isOptional()) { $count++; } }); return $count; } /** * Returns imported namespaces and aliases from the declaring namespace. * * @return array */ public function getNamespaceAliases() { return $this->declaringClass->getNamespaceAliases(); } /** * Returns an property pretty (docblock compatible) name. * * @return string */ public function getPrettyName() { return sprintf('%s::%s()', $this->declaringClass->getName(), $this->name); } /** * @return string */ public function getFileName() { return $this->declaringClass->getFileName(); } /** * @return bool */ public function isTokenized() { return TRUE; } /** * @return string */ public function getDocComment() { $docComment = "/**\n"; if ( ! empty($this->shortDescription)) { $docComment .= $this->shortDescription . "\n\n"; } if ($annotations = $this->getAnnotation('param')) { foreach ($annotations as $annotation) { $docComment .= sprintf("@param %s\n", $annotation); } } if ($annotations = $this->getAnnotation('return')) { foreach ($annotations as $annotation) { $docComment .= sprintf("@return %s\n", $annotation); } } $docComment .= "*/\n"; return $docComment; } /** * @param string $name * @return bool */ public function hasAnnotation($name) { $annotations = $this->getAnnotations(); return array_key_exists($name, $annotations); } /** * @param string $name * @return string|array|NULL */ public function getAnnotation($name) { $annotations = $this->getAnnotations(); if (array_key_exists($name, $annotations)) { return $annotations[$name]; } return NULL; } } ApiGen-4.1.2/src/Reflection/ReflectionParameter.php000066400000000000000000000067531262665576200222420ustar00rootroot00000000000000isArray()) { return 'array'; } elseif ($this->isCallable()) { return 'callable'; } elseif ($className = $this->getClassName()) { return $className; } elseif ($annotations = $this->getDeclaringFunction()->getAnnotation('param')) { if ( ! empty($annotations[$this->getPosition()])) { list($types) = preg_split('~\s+|$~', $annotations[$this->getPosition()], 2); if ( ! empty($types) && $types[0] !== '$') { return $types; } } } } /** * @return string */ public function getDescription() { $annotations = $this->getDeclaringFunction()->getAnnotation('param'); if (empty($annotations[$this->getPosition()])) { return ''; } $description = trim(strpbrk($annotations[$this->getPosition()], "\n\r\t ")); return preg_replace('~^(\\$' . $this->getName() . '(?:,\\.{3})?)(\\s+|$)~i', '\\2', $description, 1); } /** * @return string */ public function getDefaultValueDefinition() { return $this->reflection->getDefaultValueDefinition(); } /** * @return bool */ public function isDefaultValueAvailable() { return $this->reflection->isDefaultValueAvailable(); } /** * @return int */ public function getPosition() { return $this->reflection->getPosition(); } /** * @return bool */ public function isArray() { return $this->reflection->isArray(); } /** * @return bool */ public function isCallable() { return $this->reflection->isCallable(); } /** * @return ReflectionClass|NULL */ public function getClass() { $className = $this->reflection->getClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string|NULL */ public function getClassName() { return $this->reflection->getClassName(); } /** * @return bool */ public function allowsNull() { return $this->reflection->allowsNull(); } /** * @return bool */ public function isOptional() { return $this->reflection->isOptional(); } /** * @return bool */ public function isPassedByReference() { return $this->reflection->isPassedByReference(); } /** * @return bool */ public function canBePassedByValue() { return $this->reflection->canBePassedByValue(); } /** * @return ReflectionFunctionBase */ public function getDeclaringFunction() { $functionName = $this->reflection->getDeclaringFunctionName(); if ($className = $this->reflection->getDeclaringClassName()) { return $this->getParsedClasses()[$className]->getMethod($functionName); } else { return $this->parserResult->getFunctions()[$functionName]; } } /** * @return string */ public function getDeclaringFunctionName() { return $this->reflection->getDeclaringFunctionName(); } /** * @return ReflectionClass|NULL */ public function getDeclaringClass() { $className = $this->reflection->getDeclaringClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string|NULL */ public function getDeclaringClassName() { return $this->reflection->getDeclaringClassName(); } /** * @return bool */ public function isUnlimited() { return FALSE; } } ApiGen-4.1.2/src/Reflection/ReflectionParameterMagic.php000066400000000000000000000102131262665576200231650ustar00rootroot00000000000000name = $settings['name']; $this->position = $settings['position']; $this->typeHint = $settings['typeHint']; $this->defaultValueDefinition = $settings['defaultValueDefinition']; $this->unlimited = $settings['unlimited']; $this->passedByReference = $settings['passedByReference']; $this->declaringFunction = $settings['declaringFunction']; $this->reflectionType = get_class($this); } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function getTypeHint() { return $this->typeHint; } /** * @return string */ public function getFileName() { return $this->declaringFunction->getFileName(); } /** * @return bool */ public function isTokenized() { return TRUE; } /** * @return string */ public function getPrettyName() { return str_replace('()', '($' . $this->name . ')', $this->declaringFunction->getPrettyName()); } /** * @return ReflectionClass */ public function getDeclaringClass() { return $this->declaringFunction->getDeclaringClass(); } /** * @return string */ public function getDeclaringClassName() { return $this->declaringFunction->getDeclaringClassName(); } /** * @return ReflectionMethod */ public function getDeclaringFunction() { return $this->declaringFunction; } /** * @return string */ public function getDeclaringFunctionName() { return $this->declaringFunction->getName(); } /** * @return int */ public function getStartLine() { return $this->declaringFunction->getStartLine(); } /** * @return int */ public function getEndLine() { return $this->declaringFunction->getEndLine(); } /** * {@inheritdoc} */ public function getDocComment() { return ''; } /** * @return string */ public function getDefaultValueDefinition() { return $this->defaultValueDefinition; } /** * @return bool */ public function isDefaultValueAvailable() { return (bool) $this->defaultValueDefinition; } /** * @return int */ public function getPosition() { return $this->position; } /** * @return bool */ public function isArray() { return TokenReflection\ReflectionParameter::ARRAY_TYPE_HINT === $this->typeHint; } /** * @return bool */ public function isCallable() { return TokenReflection\ReflectionParameter::CALLABLE_TYPE_HINT === $this->typeHint; } /** * @return ReflectionClass|NULL */ public function getClass() { $className = $this->getClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string|NULL */ public function getClassName() { if ($this->isArray() || $this->isCallable()) { return NULL; } if (isset($this->getParsedClasses()[$this->typeHint])) { return $this->typeHint; } return NULL; } /** * @return bool */ public function allowsNull() { if ($this->isArray() || $this->isCallable()) { return strtolower($this->defaultValueDefinition) === 'null'; } return ! empty($this->defaultValueDefinition); } /** * @return bool */ public function isOptional() { return $this->isDefaultValueAvailable(); } /** * @return bool */ public function isPassedByReference() { return $this->passedByReference; } /** * @return bool */ public function canBePassedByValue() { return FALSE; } /** * @return bool */ public function isUnlimited() { return $this->unlimited; } } ApiGen-4.1.2/src/Reflection/ReflectionProperty.php000066400000000000000000000044501262665576200221360ustar00rootroot00000000000000getAnnotation('var')) { list($types) = preg_split('~\s+|$~', $annotations[0], 2); if ( ! empty($types) && $types[0] !== '$') { return $types; } } try { $type = gettype($this->getDefaultValue()); if (strtolower($type) !== 'null') { return $type; } } catch (\Exception $e) { return; } } /** * @return ReflectionClass|null */ public function getDeclaringClass() { $className = $this->reflection->getDeclaringClassName(); return $className === NULL ? NULL : $this->getParsedClasses()[$className]; } /** * @return string */ public function getDeclaringClassName() { return $this->reflection->getDeclaringClassName(); } /** * @return mixed */ public function getDefaultValue() { return $this->reflection->getDefaultValue(); } /** * @return string */ public function getDefaultValueDefinition() { return $this->reflection->getDefaultValueDefinition(); } /** * @return bool */ public function isDefault() { return $this->reflection->isDefault(); } /** * @return bool */ public function isStatic() { return $this->reflection->isStatic(); } /** * @return ReflectionClass|null */ public function getDeclaringTrait() { $traitName = $this->reflection->getDeclaringTraitName(); return $traitName === NULL ? NULL : $this->getParsedClasses()[$traitName]; } /** * @return string|null */ public function getDeclaringTraitName() { return $this->reflection->getDeclaringTraitName(); } /** * @return bool */ public function isValid() { if ($class = $this->getDeclaringClass()) { return $class->isValid(); } return TRUE; } } ApiGen-4.1.2/src/Reflection/ReflectionPropertyMagic.php000066400000000000000000000124621262665576200231010ustar00rootroot00000000000000name = $options['name']; $this->typeHint = $options['typeHint']; $this->shortDescription = $options['shortDescription']; $this->startLine = $options['startLine']; $this->endLine = $options['endLine']; $this->readOnly = $options['readOnly']; $this->writeOnly = $options['writeOnly']; $this->declaringClass = $options['declaringClass']; $this->addAnnotation('var', $options['typeHint']); $this->reflectionType = get_class($this); } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function getTypeHint() { return $this->typeHint; } /** * @return bool */ public function getWriteOnly() { return $this->writeOnly; } /** * @return string */ public function getShortDescription() { return $this->shortDescription; } /** * @return string */ public function getLongDescription() { return $this->longDescription; } /** * @return bool */ public function isReadOnly() { return $this->readOnly; } /** * @return bool */ public function isMagic() { return TRUE; } /** * @return bool */ public function isDeprecated() { return $this->declaringClass->isDeprecated(); } /** * @return string */ public function getPackageName() { return $this->declaringClass->getPackageName(); } /** * @return string */ public function getNamespaceName() { return $this->declaringClass->getNamespaceName(); } /** * @return array */ public function getAnnotations() { if ($this->annotations === NULL) { $this->annotations = []; } return $this->annotations; } /** * @return string */ public function getDeclaringClassName() { return $this->declaringClass->getName(); } /** * @return ReflectionClass */ public function getDeclaringClass() { return $this->declaringClass; } /** * @return $this */ public function setDeclaringClass(ReflectionClass $declaringClass) { $this->declaringClass = $declaringClass; return $this; } /** * @return mixed */ public function getDefaultValue() { return NULL; } /** * @return string */ public function getDefaultValueDefinition() { return ''; } /** * @return bool */ public function isDefault() { return FALSE; } /** * @return bool */ public function isPrivate() { return FALSE; } /** * @return bool */ public function isProtected() { return FALSE; } /** * @return bool */ public function isPublic() { return TRUE; } /** * @return bool */ public function isStatic() { return FALSE; } /** * @return ReflectionClass|NULL */ public function getDeclaringTrait() { return $this->declaringClass->isTrait() ? $this->declaringClass : NULL; } /** * @return string|NULL */ public function getDeclaringTraitName() { if ($declaringTrait = $this->getDeclaringTrait()) { return $declaringTrait->getName(); } return NULL; } /** * @return array */ public function getNamespaceAliases() { return $this->declaringClass->getNamespaceAliases(); } /** * Returns an property pretty (docblock compatible) name. * * @return string */ public function getPrettyName() { return sprintf('%s::$%s', $this->declaringClass->getName(), $this->name); } /** * @return string */ public function getFileName() { return $this->declaringClass->getFileName(); } /** * @return bool */ public function isTokenized() { return TRUE; } /** * @return string */ public function getDocComment() { $docComment = "/**\n"; if ( ! empty($this->shortDescription)) { $docComment .= $this->shortDescription . "\n\n"; } if ($annotations = $this->getAnnotation('var')) { $docComment .= sprintf("@var %s\n", $annotations[0]); } $docComment .= "*/\n"; return $docComment; } /** * @param string $name * @return bool */ public function hasAnnotation($name) { $annotations = $this->getAnnotations(); return array_key_exists($name, $annotations); } /** * @param string $name * @return string|array|NULL */ public function getAnnotation($name) { $annotations = $this->getAnnotations(); if (array_key_exists($name, $annotations)) { return $annotations[$name]; } return NULL; } } ApiGen-4.1.2/src/Reflection/TokenReflection/000077500000000000000000000000001262665576200206565ustar00rootroot00000000000000ApiGen-4.1.2/src/Reflection/TokenReflection/Reflection.php000066400000000000000000000016711262665576200234660ustar00rootroot00000000000000configuration = $configuration; $this->parserResult = $parserResult; } /** * @param IReflectionClass|IReflectionConstant|IReflectionFunction $tokenReflection * @return ReflectionClass|ReflectionConstant|ReflectionMethod */ public function createFromReflection($tokenReflection) { $reflection = $this->createByReflectionType($tokenReflection); return $this->setDependencies($reflection); } /** * @return ReflectionMethodMagic */ public function createMethodMagic(array $settings) { $reflection = new ReflectionMethodMagic($settings); return $this->setDependencies($reflection); } /** * @return ReflectionParameterMagic */ public function createParameterMagic(array $settings) { $reflection = new ReflectionParameterMagic($settings); return $this->setDependencies($reflection); } /** * @return ReflectionPropertyMagic */ public function createPropertyMagic(array $settings) { $reflection = new ReflectionPropertyMagic($settings); return $this->setDependencies($reflection); } /** * @param IReflectionClass|IReflectionConstant|IReflectionMethod $reflection * @return ReflectionClass|ReflectionConstant|ReflectionMethod */ private function createByReflectionType($reflection) { if ($reflection instanceof IReflectionClass) { return new ReflectionClass($reflection); } elseif ($reflection instanceof IReflectionConstant) { return new ReflectionConstant($reflection); } elseif ($reflection instanceof IReflectionMethod) { return new ReflectionMethod($reflection); } elseif ($reflection instanceof IReflectionProperty) { return new ReflectionProperty($reflection); } elseif ($reflection instanceof IReflectionParameter) { return new ReflectionParameter($reflection); } elseif ($reflection instanceof IReflectionFunction) { return new ReflectionFunction($reflection); } elseif ($reflection instanceof IReflectionExtension) { return new ReflectionExtension($reflection); } throw new RuntimeException('Invalid reflection class type ' . get_class($reflection)); } /** * @return ReflectionBase */ private function setDependencies(ReflectionBase $reflection) { $reflection->setConfiguration($this->configuration); $reflection->setParserResult($this->parserResult); $reflection->setReflectionFactory($this); return $reflection; } } ApiGen-4.1.2/src/Scanner/000077500000000000000000000000001262665576200150625ustar00rootroot00000000000000ApiGen-4.1.2/src/Scanner/Scanner.php000066400000000000000000000034301262665576200171640ustar00rootroot00000000000000turnToIterator($source); $fileMasks = $this->turnExtensionsToMask($extensions); $files = []; foreach ($sources as $source) { $files = array_merge($files, $this->getFilesFromSource($source, $exclude, $fileMasks)); } return $files; } /** * @param string $source * @param array $exclude * @param string $fileMasks * @return SplFileInfo[] */ private function getFilesFromSource($source, array $exclude, $fileMasks) { if (is_file($source)) { $foundFiles[$source] = new SplFileInfo($source); return $foundFiles; } else { $finder = Finder::findFiles($fileMasks)->exclude($exclude) ->from($source)->exclude($exclude); return $this->convertFinderToArray($finder); } } /** * @param array|string $source * @return array */ private function turnToIterator($source) { if ( ! is_array($source)) { return [$source]; } return $source; } /** * @return array */ private function turnExtensionsToMask(array $extensions) { array_walk($extensions, function (&$value) { $value = '*.' . $value; }); return $extensions; } /** * @return SplFileInfo[] */ private function convertFinderToArray(Finder $finder) { return iterator_to_array($finder->getIterator()); } } ApiGen-4.1.2/src/Templating/000077500000000000000000000000001262665576200155755ustar00rootroot00000000000000ApiGen-4.1.2/src/Templating/Exceptions/000077500000000000000000000000001262665576200177165ustar00rootroot00000000000000ApiGen-4.1.2/src/Templating/Exceptions/UnsupportedElementException.php000066400000000000000000000005151262665576200261510ustar00rootroot00000000000000 'used by' ]; /** * @var string[] */ private $remove = [ 'package', 'subpackage', 'property', 'property-read', 'property-write', 'method', 'abstract', 'access', 'final', 'filesource', 'global', 'name', 'static', 'staticvar' ]; /** * @var array */ private $order = [ 'deprecated' => 0, 'category' => 1, 'copyright' => 2, 'license' => 3, 'author' => 4, 'version' => 5, 'since' => 6, 'see' => 7, 'uses' => 8, 'usedby' => 9, 'link' => 10, 'internal' => 11, 'example' => 12, 'tutorial' => 13, 'todo' => 14 ]; /** * @var Configuration */ private $configuration; public function __construct(Configuration $configuration) { $this->configuration = $configuration; } /** * @param string $name * @return string */ public function annotationBeautify($name) { if (isset($this->rename[$name])) { $name = $this->rename[$name]; } return Nette\Utils\Strings::firstUpper($name); } /** * @return array */ public function annotationFilter(array $annotations, array $customToRemove = []) { $annotations = $this->filterOut($annotations, $this->remove); $annotations = $this->filterOut($annotations, $customToRemove); if ( ! $this->configuration->getOption(CO::INTERNAL)) { unset($annotations['internal']); } if ( ! $this->configuration->getOption(CO::TODO)) { unset($annotations['todo']); } return $annotations; } /** * @return array */ public function annotationSort(array $annotations) { uksort($annotations, function ($one, $two) { if (isset($this->order[$one], $this->order[$two])) { return $this->order[$one] - $this->order[$two]; } elseif (isset($this->order[$one])) { return -1; } elseif (isset($this->order[$two])) { return 1; } else { return strcasecmp($one, $two); } }); return $annotations; } /** * @return array */ private function filterOut(array $annotations, array $toRemove) { foreach ($toRemove as $annotation) { unset($annotations[$annotation]); } return $annotations; } } ApiGen-4.1.2/src/Templating/Filters/ElementUrlFilters.php000066400000000000000000000034361262665576200233310ustar00rootroot00000000000000elementUrlFactory = $elementUrlFactory; } /** * @return string */ public function elementUrl(ReflectionElement $element) { return $this->elementUrlFactory->createForElement($element); } /** * @param string|ReflectionClass $class * @return string */ public function classUrl($class) { return $this->elementUrlFactory->createForClass($class); } /** * @return string */ public function methodUrl(ReflectionMethod $method, ReflectionClass $class = NULL) { return $this->elementUrlFactory->createForMethod($method, $class); } /** * @return string */ public function propertyUrl(ReflectionProperty $property, ReflectionClass $class = NULL) { return $this->elementUrlFactory->createForProperty($property, $class); } /** * @return string */ public function constantUrl(ReflectionConstant $constant) { return $this->elementUrlFactory->createForConstant($constant); } /** * @return string */ public function functionUrl(ReflectionFunction $function) { return $this->elementUrlFactory->createForFunction($function); } } ApiGen-4.1.2/src/Templating/Filters/Filters.php000066400000000000000000000026111262665576200213260ustar00rootroot00000000000000 'integer', 'bool' => 'boolean', 'double' => 'float', 'void' => '', 'FALSE' => 'false', 'TRUE' => 'true', 'NULL' => 'null', 'callback' => 'callable' ]; // Simple type if (isset($names[$name])) { return $names[$name]; } // Class, constant or function return $trimNamespaceSeparator ? ltrim($name, '\\') : $name; } /** * @param string $url * @return string */ private function url($url) { return rawurlencode($url); } } ApiGen-4.1.2/src/Templating/Filters/Helpers/000077500000000000000000000000001262665576200206075ustar00rootroot00000000000000ApiGen-4.1.2/src/Templating/Filters/Helpers/ElementLinkFactory.php000066400000000000000000000075241262665576200250670ustar00rootroot00000000000000elementUrlFactory = $elementUrlFactory; $this->linkBuilder = $linkBuilder; } /** * @return string */ public function createForElement(ReflectionElement $element, array $classes = []) { if ($element instanceof ReflectionClass) { return $this->createForClass($element, $classes); } elseif ($element instanceof ReflectionMethod) { return $this->createForMethod($element, $classes); } elseif ($element instanceof ReflectionProperty) { return $this->createForProperty($element, $classes); } elseif ($element instanceof ReflectionConstant) { return $this->createForConstant($element, $classes); } elseif ($element instanceof ReflectionFunction) { return $this->createForFunction($element, $classes); } throw new UnexpectedValueException( 'Descendant of ApiGen\Reflection\Reflection class expected. Got "' . get_class($element) . ' class".' ); } /** * @return string */ private function createForClass(ReflectionClass $reflectionClass, array $classes) { return $this->linkBuilder->build( $this->elementUrlFactory->createForClass($reflectionClass), $reflectionClass->getName(), TRUE, $classes ); } /** * @return string */ private function createForMethod(ReflectionMethod $reflectionMethod, array $classes) { return $this->linkBuilder->build( $this->elementUrlFactory->createForMethod($reflectionMethod), $reflectionMethod->getDeclaringClassName() . '::' . $reflectionMethod->getName() . '()', FALSE, $classes ); } /** * @return string */ private function createForProperty(ReflectionProperty $reflectionProperty, array $classes) { $text = $reflectionProperty->getDeclaringClassName() . '::' . Html::el('var')->setText('$' . $reflectionProperty->getName()); return $this->linkBuilder->build( $this->elementUrlFactory->createForProperty($reflectionProperty), $text, FALSE, $classes ); } /** * @return string */ private function createForConstant(ReflectionConstant $reflectionConstant, array $classes) { $url = $this->elementUrlFactory->createForConstant($reflectionConstant); if ($reflectionConstant->getDeclaringClassName()) { $text = $reflectionConstant->getDeclaringClassName() . '::' . Html::el('b')->setText($reflectionConstant->getName()); } else { $text = $this->getGlobalConstantName($reflectionConstant); } return $this->linkBuilder->build($url, $text, FALSE, $classes); } /** * @return string */ private function createForFunction(ReflectionFunction $reflectionFunction, array $classes) { return $this->linkBuilder->build( $this->elementUrlFactory->createForFunction($reflectionFunction), $reflectionFunction->getName() . '()', TRUE, $classes ); } /** * @return string */ private function getGlobalConstantName(ReflectionConstant $reflectionConstant) { if ($reflectionConstant->inNamespace()) { return $reflectionConstant->getNamespaceName() . '\\' . Html::el('b')->setText($reflectionConstant->getShortName()); } else { return Html::el('b')->setText($reflectionConstant->getName()); } } } ApiGen-4.1.2/src/Templating/Filters/Helpers/ElementUrlFactory.php000066400000000000000000000066741262665576200247410ustar00rootroot00000000000000configuration = $configuration; } /** * @param ReflectionElement|string $element * @return string|NULL */ public function createForElement($element) { if ($element instanceof ReflectionClass) { return $this->createForClass($element); } elseif ($element instanceof ReflectionMethod) { return $this->createForMethod($element); } elseif ($element instanceof ReflectionProperty) { return $this->createForProperty($element); } elseif ($element instanceof ReflectionConstant) { return $this->createForConstant($element); } elseif ($element instanceof ReflectionFunction) { return $this->createForFunction($element); } return NULL; } /** * @param string|ReflectionClass $class * @return string */ public function createForClass($class) { $className = $class instanceof ReflectionClass ? $class->getName() : $class; return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates']['class']['filename'], Filters::urlize($className) ); } /** * @return string */ public function createForMethod(ReflectionMethod $method, ReflectionClass $class = NULL) { $className = $class !== NULL ? $class->getName() : $method->getDeclaringClassName(); return $this->createForClass($className) . '#' . ($method->isMagic() ? 'm' : '') . '_' . ($method->getOriginalName() ?: $method->getName()); } /** * @return string */ public function createForProperty(ReflectionProperty $property, ReflectionClass $class = NULL) { $className = $class !== NULL ? $class->getName() : $property->getDeclaringClassName(); return $this->createForClass($className) . '#' . ($property->isMagic() ? 'm' : '') . '$' . $property->getName(); } /** * @return string */ public function createForConstant(ReflectionConstant $constant) { // Class constant if ($className = $constant->getDeclaringClassName()) { return $this->createForClass($className) . '#' . $constant->getName(); } // Constant in namespace or global space return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates']['constant']['filename'], Filters::urlize($constant->getName()) ); } /** * @return string */ public function createForFunction(ReflectionFunction $function) { return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates']['function']['filename'], Filters::urlize($function->getName()) ); } /** * @param string $name * @return string */ public function createForAnnotationGroup($name) { return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates'][TCO::ANNOTATION_GROUP]['filename'], Filters::urlize($name) ); } } ApiGen-4.1.2/src/Templating/Filters/Helpers/LinkBuilder.php000066400000000000000000000012561262665576200235300ustar00rootroot00000000000000href($url) ->setHtml($escape ? Filters::escapeHtml($text) : $text) ->addAttributes(['class' => $classes]) ->render(); } } ApiGen-4.1.2/src/Templating/Filters/Helpers/Strings.php000066400000000000000000000006331262665576200227530ustar00rootroot00000000000000configuration = $configuration; $this->linkBuilder = $linkBuilder; $this->elementStorage = $elementStorage; } /** * @param string $groupName * @return string */ public function subgroupName($groupName) { if ($pos = strrpos($groupName, '\\')) { return substr($groupName, $pos + 1); } return $groupName; } /** * @param string $package * @param bool $skipLast * @return string */ public function packageLinks($package, $skipLast = TRUE) { if ( ! $this->elementStorage->getPackages()) { return $package; } $links = []; $parent = ''; foreach (explode('\\', $package) as $part) { $parent = ltrim($parent . '\\' . $part, '\\'); $links[] = ($skipLast || $parent !== $package) ? $this->linkBuilder->build($this->packageUrl($parent), $part) : $part; } return implode('\\', $links); } /** * @param string $namespace * @param bool $skipLast * @return string */ public function namespaceLinks($namespace, $skipLast = TRUE) { if ( ! $this->elementStorage->getNamespaces()) { return $namespace; } $links = []; $parent = ''; foreach (explode('\\', $namespace) as $part) { $parent = ltrim($parent . '\\' . $part, '\\'); $links[] = $skipLast || $parent !== $namespace ? $this->linkBuilder->build($this->namespaceUrl($parent), $part) : $part; } return implode('\\', $links); } /** * @param string $name * @return string */ public function packageUrl($name) { return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates']['package']['filename'], $this->urlize($name) ); } /** * @param string $name * @return string */ public function namespaceUrl($name) { return sprintf( $this->configuration->getOption(CO::TEMPLATE)['templates']['namespace']['filename'], $this->urlize($name) ); } } ApiGen-4.1.2/src/Templating/Filters/PathFilters.php000066400000000000000000000013151262665576200221430ustar00rootroot00000000000000relativePathResolver = $relativePathResolver; } /** * @param string $fileName * @return string */ public function relativePath($fileName) { return $this->relativePathResolver->getRelativePath($fileName); } } ApiGen-4.1.2/src/Templating/Filters/PhpManualFilters.php000066400000000000000000000110301262665576200231270ustar00rootroot00000000000000 callback ] */ private $assignments = []; public function __construct() { $this->prepareAssignments(); } /** * @param ReflectionElement|ReflectionExtension|ReflectionMethod $element * @return string */ public function manualUrl($element) { if ($element instanceof ReflectionExtension) { return $this->createExtensionUrl($element); } $class = $this->detectClass($element); if ($class && $this->isReservedClass($class)) { return self::PHP_MANUAL_URL . '/reserved.classes.php'; } $className = get_class($element); if (isset($this->assignments[$className])) { return $this->assignments[$className]($element, $class); } return ''; } /** * @return string */ private function createExtensionUrl(ReflectionExtension $reflectionExtension) { $extensionName = strtolower($reflectionExtension->getName()); if ($extensionName === 'core') { return self::PHP_MANUAL_URL; } if ($extensionName === 'date') { $extensionName = 'datetime'; } return self::PHP_MANUAL_URL . '/book.' . $extensionName . '.php'; } /** * @return array */ private function prepareAssignments() { $this->assignments['ApiGen\Reflection\ReflectionClass'] = function ($element, $class) { return $this->createClassUrl($class); }; $this->assignments['ApiGen\Reflection\ReflectionMethod'] = function ($element, $class) { return $this->createMethodUrl($element, $class); }; $this->assignments['ApiGen\Reflection\ReflectionFunction'] = function ($element, $class) { return $this->createFunctionUrl($element); }; $this->assignments['ApiGen\Reflection\ReflectionProperty'] = function ($element, $class) { return $this->createPropertyUrl($element, $class); }; $this->assignments['ApiGen\Reflection\ReflectionConstant'] = function ($element, $class) { return $this->createConstantUrl($element, $class); }; } /** * @return string */ private function createClassUrl(ReflectionClass $classReflection) { return self::PHP_MANUAL_URL . '/class.' . strtolower($classReflection->getName()) . '.php'; } /** * @return string */ private function createConstantUrl(ReflectionConstant $reflectionConstant, ReflectionClass $classReflection) { return $this->createClassUrl($classReflection) . '#' . strtolower($classReflection->getName()) . '.constants.' . $this->getElementName($reflectionConstant); } /** * @return string */ private function createPropertyUrl(ReflectionProperty $reflectionProperty, ReflectionClass $classReflection) { return $this->createClassUrl($classReflection) . '#' . strtolower($classReflection->getName()) . '.props.' . $this->getElementName($reflectionProperty); } /** * @return string */ private function createMethodUrl(ReflectionMethod $reflectionMethod, ReflectionClass $reflectionClass) { return self::PHP_MANUAL_URL . '/' . strtolower($reflectionClass->getName()) . '.' . $this->getElementName($reflectionMethod) . '.php'; } /** * @return string */ private function createFunctionUrl(ReflectionElement $reflectionElement) { return self::PHP_MANUAL_URL . '/function.' . strtolower($reflectionElement->getName()) . '.php'; } /** * @return bool */ private function isReservedClass(ReflectionClass $class) { $reservedClasses = ['stdClass', 'Closure', 'Directory']; return (in_array($class->getName(), $reservedClasses)); } /** * @return string */ private function getElementName(ReflectionElement $element) { return strtolower(strtr(ltrim($element->getName(), '_'), '_', '-')); } /** * @param ReflectionElement|string $element * @return string */ private function detectClass($element) { if ($element instanceof ReflectionClass) { return $element; } if ($element instanceof ReflectionMethod || $element instanceof ReflectionProperty || $element instanceof ReflectionConstant ) { return $element->getDeclaringClass(); } return ''; } } ApiGen-4.1.2/src/Templating/Filters/ResolverFilters.php000066400000000000000000000024201262665576200230460ustar00rootroot00000000000000elementResolver = $elementResolver; } /** * @param string $className * @param string|NULL $namespace * @return ReflectionClass|FALSE */ public function getClass($className, $namespace = NULL) { $reflection = $this->elementResolver->getClass($className, $namespace); if ($reflection) { return $reflection; } return FALSE; } /** * @param string $definition * @param ReflectionElement $context * @param NULL $expectedName * @return ReflectionElement|bool|NULL */ public function resolveElement($definition, $context, &$expectedName = NULL) { $reflection = $this->elementResolver->resolveElement($definition, $context, $expectedName); if ($reflection) { return $reflection; } return FALSE; } } ApiGen-4.1.2/src/Templating/Filters/SourceFilters.php000066400000000000000000000046631262665576200225200ustar00rootroot00000000000000configuration = $configuration; } /** * @param string $name * @return string */ public function staticFile($name) { $filename = $this->configuration->getOption(CO::DESTINATION) . '/' . $name; if (is_file($filename)) { $name .= '?' . sha1_file($filename); } return $name; } /** * @param ReflectionElement|ReflectionConstant $element * @param bool $withLine Include file line number into the link * @return string */ public function sourceUrl(ReflectionElement $element, $withLine = TRUE) { $file = ''; if ($this->isDirectUrl($element)) { $elementName = $element->getName(); if ($element instanceof ReflectionClass) { $file = 'class-'; } elseif ($element instanceof ReflectionConstant) { $file = 'constant-'; } elseif ($element instanceof ReflectionFunction) { $file = 'function-'; } } else { $elementName = $element->getDeclaringClassName(); $file = 'class-'; } $file .= $this->urlize($elementName); $url = sprintf($this->configuration->getOption(CO::TEMPLATE)['templates']['source']['filename'], $file); if ($withLine) { $url .= $this->getElementLinesAnchor($element); } return $url; } /** * @return bool */ private function isDirectUrl(ReflectionElement $element) { if ($element instanceof ReflectionClass || $element instanceof ReflectionFunction || ($element instanceof ReflectionConstant && $element->getDeclaringClassName() === NULL) ) { return TRUE; } return FALSE; } /** * @param ReflectionElement $element * @return string */ private function getElementLinesAnchor(ReflectionElement $element) { $anchor = '#' . $element->getStartLine(); if ($element->getStartLine() !== $element->getEndLine()) { $anchor .= '-' . $element->getEndLine(); } return $anchor; } } ApiGen-4.1.2/src/Templating/Filters/UrlFilters.php000066400000000000000000000242461262665576200220210ustar00rootroot00000000000000highlighter = $highlighter; $this->markup = $markup; $this->elementResolver = $elementResolver; $this->configuration = $configuration; $this->linkBuilder = $linkBuilder; $this->elementLinkFactory = $elementLinkFactory; } /** * Tries to parse a definition of a class/method/property/constant/function * and returns the appropriate link if successful. * * @param string $definition * @param ReflectionElement $reflectionElement * @return string|NULL */ public function resolveLink($definition, ReflectionElement $reflectionElement) { if (empty($definition)) { return NULL; } $suffix = ''; if (substr($definition, -2) === '[]') { $definition = substr($definition, 0, -2); $suffix = '[]'; } $element = $this->elementResolver->resolveElement($definition, $reflectionElement, $expectedName); if ($element === NULL) { return $expectedName; } $classes = []; if ($element->isDeprecated()) { $classes[] = 'deprecated'; } /** @var ReflectionFunction $element */ if ( ! $element->isValid()) { $classes[] = 'invalid'; } $link = $this->createLinkForElement($element, $classes); return '' . $link . $suffix . ''; } /** * @param string $value * @param string $name * @param ReflectionElement $reflectionElement * @return string */ public function annotation($value, $name, ReflectionElement $reflectionElement) { $annotationProcessors = [ 'return' => $this->processReturnAnnotations($value, $reflectionElement), 'throws' => $this->processThrowsAnnotations($value, $reflectionElement), 'license' => $this->processLicenseAnnotations($value), 'link' => $this->processLinkAnnotations($value), 'see' => $this->processSeeAnnotations($value, $reflectionElement), 'uses' => $this->processUsesAndUsedbyAnnotations($value, $reflectionElement), 'usedby' => $this->processUsesAndUsedbyAnnotations($value, $reflectionElement), ]; if (isset($annotationProcessors[$name])) { return $annotationProcessors[$name]; } return $this->doc($value, $reflectionElement); } /** * Returns links for types. * * @param string $annotation * @param ReflectionElement $reflectionElement * @return string */ public function typeLinks($annotation, ReflectionElement $reflectionElement) { $links = []; list($types) = Strings::split($annotation); if ( ! empty($types) && $types[0] === '$') { $types = NULL; } foreach (explode('|', $types) as $type) { $type = $this->getTypeName($type, FALSE); $links[] = $this->resolveLink($type, $reflectionElement) ?: LatteFilters::escapeHtml(ltrim($type, '\\')); } return implode('|', $links); } /********************* description *********************/ /** * @param string $annotation * @param ReflectionElement $reflectionElement * @return string */ public function description($annotation, ReflectionElement $reflectionElement) { $description = trim(strpbrk($annotation, "\n\r\t $")) ?: $annotation; return $this->doc($description, $reflectionElement); } /** * @param ReflectionElement $reflectionElement * @param bool $block * @return string */ public function shortDescription(ReflectionElement $reflectionElement, $block = FALSE) { return $this->doc($reflectionElement->getShortDescription(), $reflectionElement, $block); } /** * @return string */ public function longDescription(ReflectionElement $element) { $long = $element->getLongDescription(); // Merge lines $long = preg_replace_callback('~(?:<(code|pre)>.+?)|([^<]*)~s', function ($matches) { return ! empty($matches[2]) ? preg_replace('~\n(?:\t|[ ])+~', ' ', $matches[2]) : $matches[0]; }, $long); return $this->doc($long, $element, TRUE); } /********************* text formatter *********************/ /** * @param string $text * @param ReflectionElement $reflectionElement * @param bool $block * @return string */ public function doc($text, ReflectionElement $reflectionElement, $block = FALSE) { $text = $this->resolveInternalAnnotation($text); // Process markup if ($block) { $text = $this->markup->block($text); } else { $text = $this->markup->line($text); } return $this->resolveLinkAndSeeAnnotation($text, $reflectionElement); } /** * @param string $text * @return string */ private function resolveInternalAnnotation($text) { $pattern = '~\\{@(\\w+)(?:(?:\\s+((?>(?R)|[^{}]+)*)\\})|\\})~'; return preg_replace_callback($pattern, function ($matches) { if ($matches[1] !== 'internal') { return $matches[0]; } if ($this->configuration->getOption(CO::INTERNAL) && isset($matches[2])) { return $matches[2]; } return ''; }, $text); } /** * @param string $text * @param ReflectionElement $reflectionElement * @return string */ private function resolveLinkAndSeeAnnotation($text, ReflectionElement $reflectionElement) { return preg_replace_callback('~{@(?:link|see)\\s+([^}]+)}~', function ($matches) use ($reflectionElement) { list($url, $description) = Strings::split($matches[1]); if (Validators::isUri($url)) { return $this->linkBuilder->build($url, $description ?: $url); } if ($link = $this->resolveLink($matches[1], $reflectionElement)) { return $link; } return $matches[1]; }, $text); } /********************* highlight *********************/ /** * @param string $source * @param ReflectionElement $reflectionElement * @return string */ public function highlightPhp($source, ReflectionElement $reflectionElement) { return $this->resolveLink($this->getTypeName($source), $reflectionElement) ?: $this->highlighter->highlight((string) $source); } /** * @param string $definition * @param ReflectionElement $reflectionElement * @return string */ public function highlightValue($definition, ReflectionElement $reflectionElement) { return $this->highlightPhp(preg_replace('~^(?:[ ]{4}|\t)~m', '', $definition), $reflectionElement); } /** * @return string */ private function createLinkForElement($reflectionElement, array $classes) { return $this->elementLinkFactory->createForElement($reflectionElement, $classes); } /** * @param string $value * @param ReflectionElement $reflectionElement * @return string */ private function processReturnAnnotations($value, ReflectionElement $reflectionElement) { $description = $this->getDescriptionFromValue($value, $reflectionElement); $typeLinks = $this->typeLinks($value, $reflectionElement); return $typeLinks . $description; } /** * @param string $value * @param ReflectionElement $reflectionElement * @return string */ private function processThrowsAnnotations($value, ReflectionElement $reflectionElement) { $description = $this->getDescriptionFromValue($value, $reflectionElement); $typeLinks = $this->typeLinks($value, $reflectionElement); return $typeLinks . $description; } /** * @param mixed $value * @param ReflectionElement $reflectionElement * @return string */ private function getDescriptionFromValue($value, ReflectionElement $reflectionElement) { $description = trim(strpbrk($value, "\n\r\t $")) ?: NULL; if ($description) { $description = '
' . $this->doc($description, $reflectionElement); } return $description; } /** * @param string $value * @return string */ private function processLicenseAnnotations($value) { list($url, $description) = Strings::split($value); return $this->linkBuilder->build($url, $description ?: $url); } /** * @param string $value * @return string */ private function processLinkAnnotations($value) { list($url, $description) = Strings::split($value); if (Validators::isUri($url)) { return $this->linkBuilder->build($url, $description ?: $url); } return NULL; } /** * @param string $value * @param ReflectionElement $reflectionElement * @return string */ private function processSeeAnnotations($value, ReflectionElement $reflectionElement) { $doc = []; foreach (preg_split('~\\s*,\\s*~', $value) as $link) { if ($this->elementResolver->resolveElement($link, $reflectionElement) !== NULL) { $doc[] = $this->typeLinks($link, $reflectionElement); } else { $doc[] = $this->doc($link, $reflectionElement); } } return implode(', ', $doc); } /** * @param string $value * @param ReflectionElement $reflectionElement * @return string */ private function processUsesAndUsedbyAnnotations($value, ReflectionElement $reflectionElement) { list($link, $description) = Strings::split($value); $separator = $reflectionElement instanceof ReflectionClass || ! $description ? ' ' : '
'; if ($this->elementResolver->resolveElement($link, $reflectionElement) !== NULL) { $value = $this->typeLinks($link, $reflectionElement) . $separator . $description; return trim($value); } return NULL; } } ApiGen-4.1.2/src/Templating/Template.php000066400000000000000000000014361262665576200200650ustar00rootroot00000000000000savePath = $file ?: $this->savePath; $dir = dirname($this->savePath); if ( ! is_dir($dir)) { mkdir($dir, 0755, TRUE); } file_put_contents($this->savePath, $this->__toString()); } /** * @param string $savePath */ public function setSavePath($savePath) { $this->savePath = $savePath; } } ApiGen-4.1.2/src/Templating/TemplateElementsLoader.php000066400000000000000000000051501262665576200227060ustar00rootroot00000000000000elementStorage = $elementStorage; $this->configuration = $configuration; $this->autocompleteElements = $autocompleteElements; } /** * @return Template */ public function addElementsToTemplate(Template $template) { return $template->setParameters($this->getParameters()); } /** * @return Closure */ private function getMainFilter() { return function (ReflectionElement $element) { return $element->isMain(); }; } /** * @return array */ private function getParameters() { if ($this->parameters === NULL) { $parameters = [ 'annotationGroups' => $this->configuration->getOption(CO::ANNOTATION_GROUPS), 'namespace' => NULL, 'package' => NULL, 'class' => NULL, 'constant' => NULL, 'function' => NULL, 'namespaces' => array_keys($this->elementStorage->getNamespaces()), 'packages' => array_keys($this->elementStorage->getPackages()), 'classes' => array_filter($this->elementStorage->getClasses(), $this->getMainFilter()), 'interfaces' => array_filter($this->elementStorage->getInterfaces(), $this->getMainFilter()), 'traits' => array_filter($this->elementStorage->getTraits(), $this->getMainFilter()), 'exceptions' => array_filter($this->elementStorage->getExceptions(), $this->getMainFilter()), 'constants' => array_filter($this->elementStorage->getConstants(), $this->getMainFilter()), 'functions' => array_filter($this->elementStorage->getFunctions(), $this->getMainFilter()), 'elements' => $this->autocompleteElements->getElements() ]; if ($this->configuration->getOption(CO::DOWNLOAD)) { $parameters['archive'] = basename($this->configuration->getZipFileName()); } $this->parameters = $parameters; } return $this->parameters; } } ApiGen-4.1.2/src/Templating/TemplateFactory.php000066400000000000000000000106051262665576200214130ustar00rootroot00000000000000latteEngine = $latteEngine; $this->configuration = $configuration; $this->templateNavigator = $templateNavigator; $this->templateElementsLoader = $templateElementsLoader; } /** * @return Template */ public function create() { return $this->buildTemplate(); } /** * @param string $type * @return Template */ public function createForType($type) { $template = $this->buildTemplate(); $template->setFile($this->templateNavigator->getTemplatePath($type)); $template->setSavePath($this->templateNavigator->getTemplateFileName($type)); $template = $this->setEmptyDefaults($template); return $template; } /** * @param string $name * @param ReflectionElement|string $element * @throws \Exception * @return Template */ public function createNamedForElement($name, $element) { $template = $this->buildTemplate(); $template->setFile($this->templateNavigator->getTemplatePath($name)); if ($name === self::ELEMENT_SOURCE) { $template->setSavePath($this->templateNavigator->getTemplatePathForSourceElement($element)); } elseif ($name === self::ELEMENT_NAMESPACE) { $template->setSavePath($this->templateNavigator->getTemplatePathForNamespace($element)); } elseif ($name === self::ELEMENT_PACKAGE) { $template->setSavePath($this->templateNavigator->getTemplatePathForPackage($element)); } elseif ($name === self::ELEMENT_ANNOTATION_GROUP) { $template->setSavePath($this->templateNavigator->getTemplatePathForAnnotationGroup($element)); } else { throw new UnsupportedElementException($name . ' is not supported template type.'); } return $template; } /** * @param ReflectionElement $element * @return Template */ public function createForReflection($element) { $template = $this->buildTemplate(); if ($element instanceof ReflectionClass) { $template->setFile($this->templateNavigator->getTemplatePath('class')); $template->setSavePath($this->templateNavigator->getTemplatePathForClass($element)); } elseif ($element instanceof ReflectionConstant) { $template->setFile($this->templateNavigator->getTemplatePath('constant')); $template->setSavePath($this->templateNavigator->getTemplatePathForConstant($element)); } elseif ($element instanceof ReflectionFunction) { $template->setFile($this->templateNavigator->getTemplatePath('function')); $template->setSavePath($this->templateNavigator->getTemplatePathForFunction($element)); } return $template; } /** * @return Template */ private function buildTemplate() { if ($this->builtTemplate === NULL) { $options = $this->configuration->getOptions(); $template = new Template($this->latteEngine); $template->setParameters([ 'config' => ArrayHash::from($options), 'basePath' => $options[CO::TEMPLATE][TCO::TEMPLATES_PATH] ]); $this->builtTemplate = $template; } return $this->templateElementsLoader->addElementsToTemplate($this->builtTemplate); } /** * @return Template */ private function setEmptyDefaults(Template $template) { return $template->setParameters([ 'namespace' => NULL, 'package' => NULL ]); } } ApiGen-4.1.2/src/Templating/TemplateNavigator.php000066400000000000000000000067011262665576200217400ustar00rootroot00000000000000configuration = $configuration; $this->sourceFilters = $sourceFilters; $this->elementUrlFactory = $elementUrlFactory; $this->namespaceAndPackageUrlFilters = $namespaceAndPackageUrlFilters; } /** * @param string $name * @return string */ public function getTemplatePath($name) { $options = $this->configuration->getOptions(); return $options[CO::TEMPLATE][TCO::TEMPLATES][$name]['template']; } /** * @param string $name * @return string */ public function getTemplateFileName($name) { $options = $this->configuration->getOptions(); return $this->getDestination() . '/' . $options[CO::TEMPLATE][TCO::TEMPLATES][$name]['filename']; } /** * @param string $namespace * @return string */ public function getTemplatePathForNamespace($namespace) { return $this->getDestination() . '/' . $this->namespaceAndPackageUrlFilters->namespaceUrl($namespace); } /** * @param string $package * @return string */ public function getTemplatePathForPackage($package) { return $this->getDestination() . '/' . $this->namespaceAndPackageUrlFilters->packageUrl($package); } /** * @return string */ public function getTemplatePathForClass(ReflectionClass $element) { return $this->getDestination() . '/' . $this->elementUrlFactory->createForClass($element); } /** * @return string */ public function getTemplatePathForConstant(ReflectionConstant $element) { return $this->getDestination() . '/' . $this->elementUrlFactory->createForConstant($element); } /** * @return string */ public function getTemplatePathForFunction(ReflectionFunction $element) { return $this->getDestination() . '/' . $this->elementUrlFactory->createForFunction($element); } /** * @return string */ public function getTemplatePathForSourceElement(ReflectionElement $element) { return $this->getDestination() . '/' . $this->sourceFilters->sourceUrl($element, FALSE); } /** * @param string $element * @return string */ public function getTemplatePathForAnnotationGroup($element) { return $this->getDestination() . '/' . $this->elementUrlFactory->createForAnnotationGroup($element); } /** * @return string */ private function getDestination() { return $this->configuration->getOption(CO::DESTINATION); } } ApiGen-4.1.2/src/Theme/000077500000000000000000000000001262665576200145335ustar00rootroot00000000000000ApiGen-4.1.2/src/Theme/ThemeConfigPathResolver.php000066400000000000000000000016411262665576200217750ustar00rootroot00000000000000rootDir = $rootDir; } /** * @param string $path * @return string */ public function resolve($path) { $allowedPaths = [ $this->rootDir, $this->rootDir . '/../../..' ]; foreach ($allowedPaths as $allowedPath) { $absolutePath = $allowedPath . '/' . ltrim($path, DIRECTORY_SEPARATOR); if (file_exists($absolutePath)) { return $absolutePath; } } throw new ConfigurationException(sprintf('Config "%s" was not found.', $path)); } } ApiGen-4.1.2/src/Theme/ThemeResources.php000066400000000000000000000025471262665576200202110ustar00rootroot00000000000000configuration = $configuration; } /** * @param string $destination */ public function copyToDestination($destination) { $resources = $this->configuration->getOption(CO::TEMPLATE)['resources']; foreach ($resources as $resourceSource => $resourceDestination) { // File if (is_file($resourceSource)) { copy($resourceSource, FileSystem::forceDir($destination . '/' . $resourceDestination)); continue; } // Dir /** @var RecursiveDirectoryIterator $iterator */ $iterator = Finder::findFiles('*')->from($resourceSource)->getIterator(); foreach ($iterator as $item) { /** @var SplFileInfo $item */ copy($item->getPathName(), FileSystem::forceDir($destination . '/' . $resourceDestination . '/' . $iterator->getSubPathName())); } } } } ApiGen-4.1.2/src/Tree.php000066400000000000000000000030621262665576200151020ustar00rootroot00000000000000setPrefixPart(RecursiveTreeIterator::PREFIX_END_HAS_NEXT, self::HAS_NEXT); $this->setPrefixPart(RecursiveTreeIterator::PREFIX_END_LAST, self::LAST); $this->rewind(); $this->reflections = $reflections; } /** * @return bool */ public function hasSibling() { $prefix = $this->getPrefix(); return ! empty($prefix) && substr($prefix, -1) === self::HAS_NEXT; } /** * @return ReflectionElement */ public function current() { $className = $this->key(); if ( ! isset($this->reflections[$className])) { throw new RuntimeException(sprintf('Class "%s" is not in the reflection array', $className)); } return $this->reflections[$className]; } } ApiGen-4.1.2/update-gh-pages.sh000077500000000000000000000005741262665576200162220ustar00rootroot00000000000000#!/usr/bin/env sh # Variables VENDOR=${VENDOR:-"deizel"} VERSION=${VERSION:-"0.1.4"} PACKAGE_NAME=${PACKAGE_NAME:-"ApiGen/ApiGen"} TARGET_NAME=${TARGET_NAME:-"ApiGen/ApiGen.github.io"} # Publish manifest curl -O -L "https://github.com/${VENDOR}/manifest-publisher/releases/download/${VERSION}/manifest.phar" php manifest.phar publish:gh-pages "${PACKAGE_NAME}" "${TARGET_NAME}"