pax_global_header 0000666 0000000 0000000 00000000064 12626655762 0014533 g ustar 00root root 0000000 0000000 52 comment=3365433ea3433b0e5c8f763608f8e63cbedb2a3a
ApiGen-4.1.2/ 0000775 0000000 0000000 00000000000 12626655762 0012702 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/LICENSE 0000664 0000000 0000000 00000002532 12626655762 0013711 0 ustar 00root root 0000000 0000000 The 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.md 0000664 0000000 0000000 00000005453 12626655762 0014621 0 ustar 00root root 0000000 0000000 # 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/ 0000775 0000000 0000000 00000000000 12626655762 0013452 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/bin/apigen 0000775 0000000 0000000 00000002235 12626655762 0014645 0 ustar 00root root 0000000 0000000 #!/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.php 0000664 0000000 0000000 00000000577 12626655762 0016211 0 ustar 00root root 0000000 0000000 =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.sh 0000775 0000000 0000000 00000001056 12626655762 0015604 0 ustar 00root root 0000000 0000000 #!/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/ 0000775 0000000 0000000 00000000000 12626655762 0013471 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/ApiGen.php 0000664 0000000 0000000 00000000415 12626655762 0015345 0 ustar 00root root 0000000 0000000 charsetDetector = $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.php 0000664 0000000 0000000 00000003600 12626655762 0020655 0 ustar 00root root 0000000 0000000 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/ 0000775 0000000 0000000 00000000000 12626655762 0017671 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Charset/Configuration/CharsetOptionsResolver.php 0000664 0000000 0000000 00000005310 12626655762 0025070 0 ustar 00root root 0000000 0000000 optionsResolverFactory = $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.php 0000664 0000000 0000000 00000000531 12626655762 0017320 0 ustar 00root root 0000000 0000000 dashFormat($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.php 0000664 0000000 0000000 00000020046 12626655762 0020613 0 ustar 00root root 0000000 0000000 configuration = $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 . '
]*>(.*)<\/p[^>]*>$/i', '$1', $text); return trim($text); } /** * @param string $text * @return string */ public function block($text) { $pattern = '~<(code|pre)>(.+?)\1>|```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.php 0000664 0000000 0000000 00000000644 12626655762 0021015 0 ustar 00root root 0000000 0000000 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.php 0000664 0000000 0000000 00000002444 12626655762 0024232 0 ustar 00root root 0000000 0000000 configuration = $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/ 0000775 0000000 0000000 00000000000 12626655762 0021631 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Generator/SourceCodeHighlighter/FshlSourceCodeHighlighter.php 0000664 0000000 0000000 00000001760 12626655762 0027375 0 ustar 00root root 0000000 0000000 highlighter = $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.php 0000664 0000000 0000000 00000001127 12626655762 0026555 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000004657 12626655762 0026177 0 ustar 00root root 0000000 0000000 templateFactory = $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.php 0000664 0000000 0000000 00000001334 12626655762 0025325 0 ustar 00root root 0000000 0000000 templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::COMBINED) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ConstantElementGenerator.php 0000664 0000000 0000000 00000004045 12626655762 0026712 0 ustar 00root root 0000000 0000000 templateFactory = $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.php 0000664 0000000 0000000 00000001324 12626655762 0024220 0 ustar 00root root 0000000 0000000 templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::E404) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/ElementListGenerator.php 0000664 0000000 0000000 00000001343 12626655762 0026032 0 ustar 00root root 0000000 0000000 templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::ELEMENT_LIST) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/FunctionElementGenerator.php 0000664 0000000 0000000 00000004045 12626655762 0026706 0 ustar 00root root 0000000 0000000 templateFactory = $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/ 0000775 0000000 0000000 00000000000 12626655762 0022615 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Generator/TemplateGenerators/Loaders/NamespaceAndPackageLoader.php 0000664 0000000 0000000 00000005630 12626655762 0030254 0 ustar 00root root 0000000 0000000 elementStorage = $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.php 0000664 0000000 0000000 00000003503 12626655762 0025501 0 ustar 00root root 0000000 0000000 templateFactory = $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.php 0000664 0000000 0000000 00000002206 12626655762 0025673 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000001334 12626655762 0025413 0 ustar 00root root 0000000 0000000 templateFactory = $templateFactory; } public function generate() { $this->templateFactory->createForType(TCO::OVERVIEW) ->save(); } } ApiGen-4.1.2/src/Generator/TemplateGenerators/PackageGenerator.php 0000664 0000000 0000000 00000003463 12626655762 0025145 0 ustar 00root root 0000000 0000000 templateFactory = $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.php 0000664 0000000 0000000 00000002114 12626655762 0025052 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000002116 12626655762 0025206 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000007127 12626655762 0025646 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000007563 12626655762 0024516 0 ustar 00root root 0000000 0000000 [], 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.php 0000664 0000000 0000000 00000002272 12626655762 0024351 0 ustar 00root root 0000000 0000000 configuration = $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/ 0000775 0000000 0000000 00000000000 12626655762 0015061 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Herrera/Box/ 0000775 0000000 0000000 00000000000 12626655762 0015611 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Herrera/Box/Compactor/ 0000775 0000000 0000000 00000000000 12626655762 0017540 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Herrera/Box/Compactor/PhpNette.php 0000664 0000000 0000000 00000003254 12626655762 0022004 0 ustar 00root root 0000000 0000000 preserveLineNumbers($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.php 0000664 0000000 0000000 00000001712 12626655762 0016452 0 ustar 00root root 0000000 0000000 getMemoryInBytes($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/ 0000775 0000000 0000000 00000000000 12626655762 0014725 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Parser/Broker/ 0000775 0000000 0000000 00000000000 12626655762 0016151 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Parser/Broker/Backend.php 0000664 0000000 0000000 00000014475 12626655762 0020224 0 ustar 00root root 0000000 0000000 [], 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/ 0000775 0000000 0000000 00000000000 12626655762 0016501 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Parser/Elements/AutocompleteElements.php 0000664 0000000 0000000 00000002701 12626655762 0023350 0 ustar 00root root 0000000 0000000 elementStorage = $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.php 0000664 0000000 0000000 00000005566 12626655762 0022513 0 ustar 00root root 0000000 0000000 elements = $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.php 0000664 0000000 0000000 00000001566 12626655762 0021761 0 ustar 00root root 0000000 0000000 isMain(); }); } /** * @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.php 0000664 0000000 0000000 00000007117 12626655762 0022010 0 ustar 00root root 0000000 0000000 sortConstantsByFqn($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.php 0000664 0000000 0000000 00000016267 12626655762 0022144 0 ustar 00root root 0000000 0000000 parserResult = $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.php 0000664 0000000 0000000 00000001765 12626655762 0020777 0 ustar 00root root 0000000 0000000 getAll() as $type) { $emptyList[$type] = []; } return $emptyList; } } ApiGen-4.1.2/src/Parser/Elements/GroupSorter.php 0000664 0000000 0000000 00000005410 12626655762 0021505 0 ustar 00root root 0000000 0000000 elements = $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.php 0000664 0000000 0000000 00000005052 12626655762 0016674 0 ustar 00root root 0000000 0000000 broker = $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.php 0000664 0000000 0000000 00000010402 12626655762 0020066 0 ustar 00root root 0000000 0000000 classes = 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/ 0000775 0000000 0000000 00000000000 12626655762 0015563 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Reflection/Extractors/ 0000775 0000000 0000000 00000000000 12626655762 0017721 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Reflection/Extractors/AnnotationMethodExtractor.php 0000664 0000000 0000000 00000006776 12626655762 0025621 0 ustar 00root root 0000000 0000000 reflectionFactory = $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.php 0000664 0000000 0000000 00000004767 12626655762 0026223 0 ustar 00root root 0000000 0000000 reflectionFactory = $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.php 0000664 0000000 0000000 00000012450 12626655762 0026033 0 ustar 00root root 0000000 0000000 reflectionClass = $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.php 0000664 0000000 0000000 00000010267 12626655762 0026102 0 ustar 00root root 0000000 0000000 reflectionClass = $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.php 0000664 0000000 0000000 00000004564 12626655762 0024520 0 ustar 00root root 0000000 0000000 getParentClass()) { $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.php 0000664 0000000 0000000 00000004722 12626655762 0025120 0 ustar 00root root 0000000 0000000 getParentClass()) { $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.php 0000664 0000000 0000000 00000005530 12626655762 0026245 0 ustar 00root root 0000000 0000000 reflectionClass = $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/ 0000775 0000000 0000000 00000000000 12626655762 0016654 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Reflection/Parts/IsDocumentedMagic.php 0000664 0000000 0000000 00000001360 12626655762 0022711 0 ustar 00root root 0000000 0000000 isDocumented === NULL) { $deprecated = $this->configuration->getOption(CO::DEPRECATED); $this->isDocumented = $deprecated || ! $this->isDeprecated(); } return $this->isDocumented; } } ApiGen-4.1.2/src/Reflection/Parts/StartLineEndLine.php 0000664 0000000 0000000 00000001503 12626655762 0022530 0 ustar 00root root 0000000 0000000 startLine = $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.php 0000664 0000000 0000000 00000001153 12626655762 0025324 0 ustar 00root root 0000000 0000000 declaringClass->getStartPosition(); } /** * @return int */ public function getEndPosition() { return $this->declaringClass->getEndPosition(); } } ApiGen-4.1.2/src/Reflection/Parts/Visibility.php 0000664 0000000 0000000 00000001340 12626655762 0021512 0 ustar 00root root 0000000 0000000 reflection->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.php 0000664 0000000 0000000 00000005303 12626655762 0021162 0 ustar 00root root 0000000 0000000 reflectionType = 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.php 0000664 0000000 0000000 00000040743 12626655762 0021364 0 ustar 00root root 0000000 0000000 classMagicElementExtractor = 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.php 0000664 0000000 0000000 00000004520 12626655762 0022101 0 ustar 00root root 0000000 0000000 reflection->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.php 0000664 0000000 0000000 00000020056 12626655762 0021703 0 ustar 00root root 0000000 0000000 reflection->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.php 0000664 0000000 0000000 00000000441 12626655762 0022262 0 ustar 00root root 0000000 0000000 reflection 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.php 0000664 0000000 0000000 00000005233 12626655762 0022672 0 ustar 00root root 0000000 0000000 reflection->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.php 0000664 0000000 0000000 00000005776 12626655762 0021546 0 ustar 00root root 0000000 0000000 reflection->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.php 0000664 0000000 0000000 00000014464 12626655762 0022501 0 ustar 00root root 0000000 0000000 name = $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.php 0000664 0000000 0000000 00000006753 12626655762 0022242 0 ustar 00root root 0000000 0000000 isArray()) { 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.php 0000664 0000000 0000000 00000010213 12626655762 0023165 0 ustar 00root root 0000000 0000000 name = $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.php 0000664 0000000 0000000 00000004450 12626655762 0022136 0 ustar 00root root 0000000 0000000 getAnnotation('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.php 0000664 0000000 0000000 00000012462 12626655762 0023101 0 ustar 00root root 0000000 0000000 name = $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/ 0000775 0000000 0000000 00000000000 12626655762 0020656 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Reflection/TokenReflection/Reflection.php 0000664 0000000 0000000 00000001671 12626655762 0023466 0 ustar 00root root 0000000 0000000 configuration = $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/ 0000775 0000000 0000000 00000000000 12626655762 0015062 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Scanner/Scanner.php 0000664 0000000 0000000 00000003430 12626655762 0017164 0 ustar 00root root 0000000 0000000 turnToIterator($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/ 0000775 0000000 0000000 00000000000 12626655762 0015575 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Templating/Exceptions/ 0000775 0000000 0000000 00000000000 12626655762 0017716 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Templating/Exceptions/UnsupportedElementException.php 0000664 0000000 0000000 00000000515 12626655762 0026151 0 ustar 00root root 0000000 0000000 '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.php 0000664 0000000 0000000 00000003436 12626655762 0023331 0 ustar 00root root 0000000 0000000 elementUrlFactory = $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.php 0000664 0000000 0000000 00000002611 12626655762 0021326 0 ustar 00root root 0000000 0000000 '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/ 0000775 0000000 0000000 00000000000 12626655762 0020607 5 ustar 00root root 0000000 0000000 ApiGen-4.1.2/src/Templating/Filters/Helpers/ElementLinkFactory.php 0000664 0000000 0000000 00000007524 12626655762 0025067 0 ustar 00root root 0000000 0000000 elementUrlFactory = $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.php 0000664 0000000 0000000 00000006674 12626655762 0024741 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000001256 12626655762 0023530 0 ustar 00root root 0000000 0000000 href($url) ->setHtml($escape ? Filters::escapeHtml($text) : $text) ->addAttributes(['class' => $classes]) ->render(); } } ApiGen-4.1.2/src/Templating/Filters/Helpers/Strings.php 0000664 0000000 0000000 00000000633 12626655762 0022753 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000001315 12626655762 0022143 0 ustar 00root root 0000000 0000000 relativePathResolver = $relativePathResolver; } /** * @param string $fileName * @return string */ public function relativePath($fileName) { return $this->relativePathResolver->getRelativePath($fileName); } } ApiGen-4.1.2/src/Templating/Filters/PhpManualFilters.php 0000664 0000000 0000000 00000011030 12626655762 0023127 0 ustar 00root root 0000000 0000000 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.php 0000664 0000000 0000000 00000002420 12626655762 0023046 0 ustar 00root root 0000000 0000000 elementResolver = $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.php 0000664 0000000 0000000 00000004663 12626655762 0022520 0 ustar 00root root 0000000 0000000 configuration = $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.php 0000664 0000000 0000000 00000024246 12626655762 0022021 0 ustar 00root root 0000000 0000000 highlighter = $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)>.+?\1>)|([^<]*)~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 = '