Mark V
1: <?php
2: namespace MOC\V\Component\Documentation\Component\Bridge\Repository;
3:
4: use MOC\V\Component\Documentation\Component\Bridge\Bridge;
5: use MOC\V\Component\Documentation\Component\IBridgeInterface;
6: use MOC\V\Component\Documentation\Component\Parameter\Repository\DirectoryParameter;
7: use MOC\V\Component\Documentation\Component\Parameter\Repository\ExcludeParameter;
8: use MOC\V\Core\AutoLoader\AutoLoader;
9: use MOC\V\Core\FileSystem\FileSystem;
10: use MOC\V\Core\GlobalsKernel\GlobalsKernel;
11: use Nette\Config\Adapters\NeonAdapter;
12:
13: /**
14: * Class ApiGen
15: *
16: * @package MOC\V\Component\Documentation\Component\Bridge\Repository
17: */
18: class ApiGen extends Bridge implements IBridgeInterface
19: {
20:
21: /** @var string $Project */
22: private $Project = '';
23: /** @var string $Title */
24: private $Title = '';
25: /** @var DirectoryParameter|null $Source */
26: private $Source = null;
27: /** @var DirectoryParameter|null $Destination */
28: private $Destination = null;
29: /** @var ExcludeParameter|null $Exclude */
30: private $Exclude = null;
31:
32:
33: /**
34: * @param string $Project
35: * @param string $Title
36: * @param DirectoryParameter $Source
37: * @param DirectoryParameter $Destination
38: * @param null|ExcludeParameter $Exclude
39: */
40: public function __construct(
41: $Project,
42: $Title,
43: DirectoryParameter $Source,
44: DirectoryParameter $Destination,
45: ExcludeParameter $Exclude = null
46: ) {
47:
48: AutoLoader::getNamespaceAutoLoader('ApiGen', __DIR__.'/../../../Vendor/ApiGen');
49: AutoLoader::getNamespaceAutoLoader('TokenReflection', __DIR__.'/../../../Vendor/ApiGen/libs/TokenReflection');
50: AutoLoader::getNamespaceAutoLoader('FSHL', __DIR__.'/../../../Vendor/ApiGen/libs/FSHL');
51:
52: $this->Project = $Project;
53: $this->Title = $Title;
54: $this->Source = $Source;
55: $this->Destination = $Destination;
56: $this->Exclude = $Exclude;
57:
58: set_time_limit(0);
59: $Config = $this->getConfig();
60:
61: require_once( __DIR__.'/../../../Vendor/ApiGen/libs/Nette/Nette/loader.php' );
62: $Neon = new NeonAdapter();
63:
64: $File = FileSystem::getFileWriter(__DIR__.'/ApiGen.config');
65: file_put_contents($File->getLocation(), $Neon->dump($Config));
66:
67: $SERVER = GlobalsKernel::getGlobals()->getSERVER();
68: $SERVER['argv'] = array(
69: 'DUMMY-SHELL-ARGS',
70: '--config',
71: $File->getLocation()
72: );
73: GlobalsKernel::getGlobals()->setSERVER($SERVER);
74:
75: include( __DIR__.'/../../../Vendor/ApiGen/apigen.php' );
76: }
77:
78: /** @codeCoverageIgnore */
79: private function getConfig()
80: {
81:
82: $Default = array(
83: // Source file or directory to parse
84: 'source' => $this->Source->getDirectory(),
85: // Directory where to save the generated documentation
86: 'destination' => $this->Destination->getDirectory(),
87: // List of allowed file extensions
88: 'extensions' => array('php'),
89: // Mask to exclude file or directory from processing
90: // 'exclude' => "'".$this->Exclude->getGlobList()."'",
91: // Don't generate documentation for classes from file or directory with this mask
92: //'skipDocPath' => '',
93: // Don't generate documentation for classes with this name prefix
94: //'skipDocPrefix' => '',
95: // Character set of source files
96: 'charset' => 'auto',
97: // Main project name prefix
98: 'main' => $this->Project,
99: // Title of generated documentation
100: 'title' => $this->Title,
101: // Documentation base URL
102: //'baseUrl' => '',
103: // Google Custom Search ID
104: //'googleCseId' => '',
105: // Google Custom Search label
106: //'googleCseLabel' => '',
107: // Google Analytics tracking code
108: //'googleAnalytics' => '',
109: // Template config file
110: 'templateConfig' => __DIR__.'/../../../Vendor/Template/config.neon',
111: // Grouping of classes
112: 'groups' => 'auto',
113: // List of allowed HTML tags in documentation
114: 'allowedHtml' => array('b', 'i', 'a', 'ul', 'ol', 'li', 'p', 'br', 'var', 'samp', 'kbd', 'tt'),
115: // Element types for search input autocomplete
116: 'autocomplete' => array('classes', 'constants', 'functions'),
117: // Generate documentation for methods and properties with given access level
118: 'accessLevels' => array('public', 'protected', 'private'),
119: // Generate documentation for elements marked as internal and display internal documentation parts
120: 'internal' => true,
121: // Generate documentation for PHP internal classes
122: 'php' => true,
123: // Generate tree view of classes, interfaces and exceptions
124: 'tree' => true,
125: // Generate documentation for deprecated classes, methods, properties and constants
126: 'deprecated' => true,
127: // Generate documentation of tasks
128: 'todo' => true,
129: // Generate highlighted source code files
130: 'sourceCode' => true,
131: // Add a link to download documentation as a ZIP archive
132: 'download' => false,
133: // Save a check style report of poorly documented elements into a file
134: 'report' => $this->Destination->getDirectory().DIRECTORY_SEPARATOR.'_improve.xml',
135: // Wipe out the destination directory first
136: 'wipeout' => false,
137: // Don't display scanning and generating messages
138: 'quiet' => false,
139: // Display progressbar
140: 'progressbar' => false,
141: // Use colors
142: 'colors' => false,
143: // Check for update
144: 'updateCheck' => false,
145: // Display additional information in case of an error
146: 'debug' => false
147: );
148: if (null === $this->Exclude) {
149: return $Default;
150: } else {
151: return array_merge($Default, array(
152: 'exclude' => $this->Exclude->getGlobList()
153: ));
154: }
155: }
156: }
157: