/usr/share/php/ApiGen/Templating/Filters/SourceFilters.php is in php-apigen 4.1.2-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <?php
/**
* This file is part of the ApiGen (http://apigen.org)
*
* For the full copyright and license information, please view
* the file license.md that was distributed with this source code.
*/
namespace ApiGen\Templating\Filters;
use ApiGen\Configuration\Configuration;
use ApiGen\Configuration\ConfigurationOptions as CO;
use ApiGen\Reflection\ReflectionClass;
use ApiGen\Reflection\ReflectionConstant;
use ApiGen\Reflection\ReflectionElement;
use ApiGen\Reflection\ReflectionFunction;
class SourceFilters extends Filters
{
/**
* @var Configuration
*/
private $configuration;
public function __construct(Configuration $configuration)
{
$this->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;
}
}
|