Permalink
Browse files

updated ApiGen to 2.7.0-dev

  • Loading branch information...
1 parent 4a4295d commit 0ba934e5e72ee9985d2ff59c9a1b49705bb87b31 @dg dg committed Aug 21, 2012
Showing with 315 additions and 89 deletions.
  1. +3 −3 build.php
  2. +1 −1 tools/ApiGen/ApiGen/Backend.php
  3. +4 −10 tools/ApiGen/ApiGen/Config.php
  4. +1 −1 tools/ApiGen/ApiGen/ConfigException.php
  5. +86 −14 tools/ApiGen/ApiGen/Generator.php
  6. +28 −0 tools/ApiGen/ApiGen/IHelperSet.php
  7. +23 −0 tools/ApiGen/ApiGen/MacroSet.php
  8. +1 −1 tools/ApiGen/ApiGen/ReflectionBase.php
  9. +5 −6 tools/ApiGen/ApiGen/ReflectionClass.php
  10. +1 −1 tools/ApiGen/ApiGen/ReflectionConstant.php
  11. +8 −2 tools/ApiGen/ApiGen/ReflectionElement.php
  12. +1 −1 tools/ApiGen/ApiGen/ReflectionExtension.php
  13. +1 −1 tools/ApiGen/ApiGen/ReflectionFunction.php
  14. +1 −1 tools/ApiGen/ApiGen/ReflectionFunctionBase.php
  15. +26 −1 tools/ApiGen/ApiGen/ReflectionMethod.php
  16. +1 −1 tools/ApiGen/ApiGen/ReflectionParameter.php
  17. +1 −1 tools/ApiGen/ApiGen/ReflectionProperty.php
  18. +75 −0 tools/ApiGen/ApiGen/SourceFilesFilterIterator.php
  19. +3 −8 tools/ApiGen/ApiGen/Template.php
  20. +1 −1 tools/ApiGen/ApiGen/Tree.php
  21. +1 −1 tools/ApiGen/templates/@elementlist.latte
  22. +1 −1 tools/ApiGen/templates/@layout.latte
  23. +8 −2 tools/ApiGen/templates/class.latte
  24. +1 −1 tools/ApiGen/templates/combined.js.latte
  25. +1 −1 tools/ApiGen/templates/constant.latte
  26. +1 −1 tools/ApiGen/templates/deprecated.latte
  27. +1 −1 tools/ApiGen/templates/elementlist.js.latte
  28. +1 −1 tools/ApiGen/templates/function.latte
  29. +3 −0 tools/ApiGen/templates/js/jquery.autocomplete.js
  30. +16 −16 tools/ApiGen/templates/js/main.js
  31. +1 −1 tools/ApiGen/templates/namespace.latte
  32. +1 −1 tools/ApiGen/templates/opensearch.xml.latte
  33. +1 −1 tools/ApiGen/templates/overview.latte
  34. +1 −1 tools/ApiGen/templates/package.latte
  35. +1 −1 tools/ApiGen/templates/resources/style.css
  36. +1 −1 tools/ApiGen/templates/robots.txt.latte
  37. +1 −1 tools/ApiGen/templates/sitemap.xml.latte
  38. +1 −1 tools/ApiGen/templates/source.latte
  39. +1 −1 tools/ApiGen/templates/todo.latte
  40. +1 −1 tools/ApiGen/templates/tree.latte
View
@@ -14,7 +14,7 @@
// configuration
-$project->gitExecutable = 'C:\Program Files\Git\bin\git.exe';
+$project->gitExecutable = 'C:\Program Files (x86)\Git\bin\git.exe';
$project->phpExecutable = realpath('tools/PHP-5.3/php.exe');
$project->php52Executable = realpath('tools/PHP-5.2/php.exe');
$project->apiGenExecutable = realpath('tools/ApiGen/apigen.php');
@@ -91,8 +91,8 @@
// build API doc
$apiGenConfig = dirname($project->apiGenExecutable) . '/apigen.neon';
$project->apiGen("$dir53/Nette", "$dir53/API-reference", $apiGenConfig, "Nette Framework $label API");
- $project->apiGen("$dir52p/Nette", "$dir52p/API-reference", $apiGenConfig, "Nette Framework $label (for PHP 5.2) API");
- $project->apiGen("$dir52n/Nette", "$dir52n/API-reference", $apiGenConfig, "Nette Framework $label (for PHP 5.2) API");
+ $project->apiGen("$dir52p/Nette", "$dir52p/API-reference", $apiGenConfig, "Nette Framework $label (for PHP 5.2, prefixed) API");
+ $project->apiGen("$dir52n/Nette", "$dir52n/API-reference", $apiGenConfig, "Nette Framework $label (for PHP 5.2, un-prefixed) API");
// create archives
if ($tag === 'master') {
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -323,7 +323,8 @@ public function prepare()
);
// Merge template config
- $this->config = array_merge_recursive($this->config, array('template' => Neon::decode(file_get_contents($this->config['templateConfig']))));
+ $this->config = array_merge_recursive($this->config, array('template' => Neon::decode(file_get_contents($fileName = $this->config['templateConfig']))));
+ $this->config['template']['config'] = realpath($fileName);
// Check template
$this->checkTemplate();
@@ -351,13 +352,6 @@ private function check()
throw new ConfigException(sprintf('Source "%s" doesn\'t exist', $source));
}
}
- foreach ($this->config['source'] as $source) {
- foreach ($this->config['source'] as $source2) {
- if ($source !== $source2 && 0 === strpos($source, $source2)) {
- throw new ConfigException(sprintf('Sources "%s" and "%s" overlap', $source, $source2));
- }
- }
- }
if (empty($this->config['destination'])) {
throw new ConfigException('Destination is not set');
@@ -377,7 +371,7 @@ private function check()
throw new ConfigException(sprintf('Invalid base url "%s"', $this->config['baseUrl']));
}
- if (!empty($this->config['googleCseId']) && !preg_match('~^\d{21}:[-a-z0-9]{11}$~', $this->config['googleCseId'])) {
+ if (!empty($this->config['googleCseId']) && !preg_match('~^\d{21}:[-a-z0-9_]{11}$~', $this->config['googleCseId'])) {
throw new ConfigException(sprintf('Invalid Google Custom Search ID "%s"', $this->config['googleCseId']));
}
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -34,7 +34,7 @@ class Generator extends Nette\Object
*
* @var string
*/
- const VERSION = '2.6.1';
+ const VERSION = '2.7.0';
/**
* Configuration.
@@ -175,10 +175,11 @@ public function parse()
// Available from PHP 5.3.1
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
}
+
foreach ($this->config->source as $source) {
$entries = array();
if (is_dir($source)) {
- foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, $flags)) as $entry) {
+ foreach (new \RecursiveIteratorIterator(new SourceFilesFilterIterator(new \RecursiveDirectoryIterator($source, $flags), $this->config->exclude)) as $entry) {
if (!$entry->isFile()) {
continue;
}
@@ -203,14 +204,8 @@ public function parse()
if (!preg_match($regexp, $entry->getFilename())) {
continue;
}
- $pathName = $this->normalizePath($entry->getPathName());
- $unPharName = $this->unPharPath($pathName);
- foreach ($this->config->exclude as $mask) {
- if (fnmatch($mask, $unPharName, FNM_NOESCAPE)) {
- continue 2;
- }
- }
+ $pathName = $this->normalizePath($entry->getPathName());
$files[$pathName] = $entry->getSize();
if (false !== $entry->getRealPath() && $pathName !== $entry->getRealPath()) {
$this->symlinks[$entry->getRealPath()] = $pathName;
@@ -413,6 +408,8 @@ public function generate()
$template->version = self::VERSION;
$template->config = $this->config;
+ $this->registerCustomTemplateMacros($template);
+
// Common files
$this->generateCommon($template);
@@ -458,6 +455,60 @@ public function generate()
}
/**
+ * Loads template-specific macro and helper libraries.
+ *
+ * @param \ApiGen\Template $template Template instance
+ */
+ private function registerCustomTemplateMacros(Template $template)
+ {
+ $latte = new Nette\Latte\Engine();
+ $macroSet = new Nette\Latte\Macros\MacroSet($latte->compiler);
+ $macroSet->addMacro('try', 'try {', '} catch (\Exception $e) {}');
+
+ if (!empty($this->config->template['options']['extensions'])) {
+ $this->output("Loading custom template macro and helper libraries\n");
+ $broker = new Broker(new Broker\Backend\Memory(), 0);
+
+ $baseDir = dirname($this->config->template['config']);
+ foreach ((array) $this->config->template['options']['extensions'] as $fileName) {
+ $pathName = $baseDir . DIRECTORY_SEPARATOR . $fileName;
+ if (is_file($pathName)) {
+ try {
+ $reflectionFile = $broker->processFile($pathName, true);
+
+ foreach ($reflectionFile->getNamespaces() as $namespace) {
+ foreach ($namespace->getClasses() as $class) {
+ if ($class->isSubclassOf('ApiGen\\MacroSet')) {
+ // Macro set
+
+ include $pathName;
+ call_user_func(array($class->getName(), 'install'), $latte->compiler);
+
+ $this->output(sprintf(" %s (macro set)\n", $class->getName()));
+ } elseif ($class->implementsInterface('ApiGen\\IHelperSet')) {
+ // Helpers set
+
+ include $pathName;
+ $className = $class->getName();
+ $template->registerHelperLoader(callback(new $className($template), 'loader'));
+
+ $this->output(sprintf(" %s (helper set)\n", $class->getName()));
+ }
+ }
+ }
+ } catch (\Exception $e) {
+ throw new \Exception(sprintf('Could not load macros and helpers from file "%s"', $pathName), 0, $e);
+ }
+ } else {
+ throw new \Exception(sprintf('Helper file "%s" does not exist.', $pathName));
+ }
+ }
+ }
+
+ $template->registerFilter($latte);
+ }
+
+ /**
* Categorizes by packages and namespaces.
*
* @return \ApiGen\Generator
@@ -1325,7 +1376,7 @@ private function generateElements(Template $template)
* Creates ZIP archive.
*
* @return \ApiGen\Generator
- * @throws \RuntimeException If something went wront.
+ * @throws \RuntimeException If something went wrong.
*/
private function generateArchive()
{
@@ -1454,6 +1505,8 @@ public function resolveElement($definition, ReflectionElement $context, &$expect
return null;
}
+ $originalContext = $context;
+
if ($context instanceof ReflectionParameter && null === $context->getDeclaringClassName()) {
// Parameter of function in namespace or global space
$context = $this->getFunction($context->getDeclaringFunctionName());
@@ -1465,11 +1518,26 @@ public function resolveElement($definition, ReflectionElement $context, &$expect
$context = $this->getClass($context->getDeclaringClassName());
}
+ if (null === $context) {
+ return null;
+ }
+
+ // self, $this references
+ if ('self' === $definition || '$this' === $definition) {
+ return $context instanceof ReflectionClass ? $context : null;
+ }
+
+ $definitionBase = substr($definition, 0, strcspn($definition, '\\:'));
$namespaceAliases = $context->getNamespaceAliases();
- if (isset($namespaceAliases[$definition]) && $definition !== ($className = \TokenReflection\Resolver::resolveClassFQN($definition, $namespaceAliases, $context->getNamespaceName()))) {
+ if (!empty($definitionBase) && isset($namespaceAliases[$definitionBase]) && $definition !== ($className = \TokenReflection\Resolver::resolveClassFQN($definition, $namespaceAliases, $context->getNamespaceName()))) {
// Aliased class
$expectedName = $className;
- return $this->getClass($className, $context->getNamespaceName());
+
+ if (false === strpos($className, ':')) {
+ return $this->getClass($className, $context->getNamespaceName());
+ } else {
+ $definition = $className;
+ }
} elseif ($class = $this->getClass($definition, $context->getNamespaceName())) {
// Class
return $class;
@@ -1481,7 +1549,9 @@ public function resolveElement($definition, ReflectionElement $context, &$expect
) {
// Function
return $function;
- } elseif (($pos = strpos($definition, '::')) || ($pos = strpos($definition, '->'))) {
+ }
+
+ if (($pos = strpos($definition, '::')) || ($pos = strpos($definition, '->'))) {
// Class::something or Class->something
if (0 === strpos($definition, 'parent::') && ($parentClassName = $context->getParentClassName())) {
$context = $this->getClass($parentClassName);
@@ -1496,6 +1566,8 @@ public function resolveElement($definition, ReflectionElement $context, &$expect
}
$definition = substr($definition, $pos + 2);
+ } elseif ($originalContext instanceof ReflectionParameter) {
+ return null;
}
// No usable context
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
+ *
+ * Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
+ * Copyright (c) 2011-2012 Ondřej Nešpor (https://github.com/Andrewsville)
+ *
+ * For the full copyright and license information, please view
+ * the file LICENSE.md that was distributed with this source code.
+ */
+
+namespace ApiGen;
+
+/**
+ * Helper set interface.
+ */
+interface IHelperSet
+{
+ /**
+ * Tries to load the requested helper.
+ *
+ * @param string $helperName Helper name
+ * @return \Nette\Callback
+ */
+ public function loader($helperName);
+}
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
+ *
+ * Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
+ * Copyright (c) 2011-2012 Ondřej Nešpor (https://github.com/Andrewsville)
+ *
+ * For the full copyright and license information, please view
+ * the file LICENSE.md that was distributed with this source code.
+ */
+
+namespace ApiGen;
+
+use Nette\Latte\Macros\MacroSet as NetteMacroSet;
+
+/**
+ * Macro set base class.
+ */
+abstract class MacroSet extends NetteMacroSet
+{
+}
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -666,14 +666,13 @@ public function getUsedMethods()
{
$usedMethods = array();
foreach ($this->getMethods() as $method) {
- if (null === $method->getDeclaringTraitName()) {
+ if (null === $method->getDeclaringTraitName() || $this->getName() === $method->getDeclaringTraitName()) {
continue;
}
- if (null === $method->getOriginalName() || $method->getName() === $method->getOriginalName()) {
- $usedMethods[$method->getDeclaringTraitName()][$method->getName()]['method'] = $method;
- } else {
- $usedMethods[$method->getDeclaringTraitName()][$method->getOriginalName()]['aliases'][$method->getName()] = $method;
+ $usedMethods[$method->getDeclaringTraitName()][$method->getName()]['method'] = $method;
+ if (null !== $method->getOriginalName() && $method->getName() !== $method->getOriginalName()) {
+ $usedMethods[$method->getDeclaringTraitName()][$method->getName()]['aliases'][$method->getName()] = $method;
}
}
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
@@ -122,9 +122,15 @@ public function getPackageName()
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 (0 === strpos($subpackageName, $packageName)) {
+ if (empty($subpackageName)) {
+ // Do nothing
+ } elseif (0 === strpos($subpackageName, $packageName)) {
$packageName = $subpackageName;
} else {
$packageName .= '\\' . $subpackageName;
@@ -1,7 +1,7 @@
<?php
/**
- * ApiGen 2.6.1 - API documentation generator for PHP 5.3+
+ * ApiGen 2.7.0 - API documentation generator for PHP 5.3+
*
* Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
* Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
Oops, something went wrong.

0 comments on commit 0ba934e

Please sign in to comment.