Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added composer.json and improved installation ways

  • Loading branch information...
commit 3c23ae775071a87e00c2a8589f67d388190bf195 1 parent 9a90fc4
@kukulich kukulich authored
View
8 .gitattributes
@@ -0,0 +1,8 @@
+build export-ignore
+libs export-ignore
+release export-ignore
+.gitattributes export-ignore
+.gitignore export-ignore
+.gitmodules export-ignore
+build.xml export-ignore
+package.xml export-ignore
View
95 ApiGen/Environment.php
@@ -40,11 +40,19 @@ public static function getApplicationVersion()
return '3.0dev';
}
+ /**
+ * Returns root directory.
+ *
+ * @return string
+ */
public static function getRootDir()
{
return realpath(__DIR__ . '/..');
}
+ /**
+ * Initializes ApiGen environment.
+ */
public static function init()
{
// Safe locale and timezone
@@ -53,28 +61,36 @@ public static function init()
date_default_timezone_set('UTC');
}
- $rootDir = static::getRootDir();
-
- spl_autoload_register(function($className) use ($rootDir) {
- if ('ApiGen\\' === substr($className, 0, 7) && is_file($fileName = $rootDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'))) {
- LimitedScope::load($fileName);
- } else {
- @LimitedScope::load(str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'));
- }
- });
-
+ // Check required extensions
foreach (array('json', 'iconv', 'mbstring', 'tokenizer') as $extension) {
if (!extension_loaded($extension)) {
throw new Exception(sprintf("Required extension missing: %s\n", $extension), 1);
}
}
- if (Environment::isPearPackage()) {
+ if (static::isPearPackage()) {
// PEAR package
@include 'Nette/loader.php';
@include 'Texy/texy.php';
- } else {
- // Standalone package
+ } elseif (static::isComposerPackage()) {
+ // Composer package
+
+ $vendorDir = realpath(static::getRootDir() . '/../..');
+
+ @include $vendorDir . '/nette/nette/Nette/loader.php';
+ @include $vendorDir . '/dg/texy/texy/texy.php';
+
+ set_include_path(
+ $vendorDir . '/kukulich/fshl' . PATH_SEPARATOR .
+ $vendorDir . '/andrewsville/php-token-reflection' . PATH_SEPARATOR .
+ get_include_path()
+ );
+
+ } elseif (static::isStandalonePackage() || static::isGitRepository()) {
+ // Standalone package or Git repository
+
+ $rootDir = static::getRootDir();
+
@include $rootDir . '/libs/Nette/Nette/loader.php';
@include $rootDir . '/libs/Texy/texy/texy.php';
@@ -83,19 +99,34 @@ public static function init()
$rootDir . '/libs/TokenReflection' . PATH_SEPARATOR .
get_include_path()
);
+ } else {
+ throw new Exception('Unsupported installation way', 2);
}
+ // Autoload
+ spl_autoload_register(function($className) {
+ $className = trim($className, '\\');
+ $classFileName = str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
+
+ if (0 === strpos($className, 'ApiGen\\') && is_file($fileName = static::getRootDir() . DIRECTORY_SEPARATOR . $classFileName)) {
@milo
milo added a note

Can't be static:: in this context.

@kukulich Owner
kukulich added a note

You're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ include $fileName;
+ } else {
+ @include $classFileName;
+ }
+ });
+
+ // Check required libraries
if (!class_exists('Nette\\Diagnostics\\Debugger')) {
- throw new Exception('Could not find Nette framework', 2);
+ throw new Exception('Could not find Nette framework', 3);
}
if (!class_exists('Texy')) {
- throw new Exception('Could not find Texy! library', 2);
+ throw new Exception('Could not find Texy! library', 3);
}
if (!class_exists('FSHL\\Highlighter')) {
- throw new Exception('Could not find FSHL library', 2);
+ throw new Exception('Could not find FSHL library', 3);
}
if (!class_exists('TokenReflection\\Broker')) {
- throw new Exception('Could not find TokenReflection library', 2);
+ throw new Exception('Could not find TokenReflection library', 3);
}
}
@@ -108,4 +139,34 @@ public static function isPearPackage()
{
return false === strpos('@php_dir@', '@php_dir');
}
+
+ /**
+ * Returns if ApiGen is installed as a Composer package.
+ *
+ * @return boolean
+ */
+ public static function isComposerPackage()
+ {
+ return is_file(__DIR__ . '/../../../autoload.php');
+ }
+
+ /**
+ * Returns if ApiGen is installed as a standalone package.
+ *
+ * @return boolean
+ */
+ public static function isStandalonePackage()
+ {
+ return is_dir(__DIR__ . '/../libs') && !static::isGitRepository();
+ }
+
+ /**
+ * Returns if ApiGen is installed as Git repository.
+ *
+ * @return boolean
+ */
+ public static function isGitRepository()
+ {
+ return is_file(__DIR__ . '/../.gitmodules');
+ }
}
View
2  apigen.php
@@ -18,7 +18,7 @@
// Check environment
try {
- require __DIR__ . '/ApiGen/Environment.php';
+ require 'ApiGen/Environment.php';
Environment::init();
} catch (\Exception $e) {
fputs(STDERR, $e->getMessage() . "\n");
View
54 composer.json
@@ -0,0 +1,54 @@
+{
+ "name": "apigen/apigen",
+ "description": "API documentation generator for PHP 5.3+",
+ "type": "library",
+ "keywords": ["documentation", "docblock", "phpdoc", "phpdocumentor", "generator", "api"],
+ "homepage": "http://apigen.org/",
+ "license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Jaroslav Hanslík",
+ "homepage": "https://github.com/kukulich"
+ },
+ {
+ "name": "Ondřej Nešpor",
+ "homepage": "https://github.com/andrewsville"
+ },
+ {
+ "name": "David Grudl",
+ "homepage": "http://davidgrudl.com"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/apigen/apigen/issues",
+ "forum": "https://groups.google.com/group/apigen",
+ "source": "https://github.com/apigen/apigen"
+ },
+ "require": {
+ "php": ">=5.3.0",
+ "nette/nette": ">=2.0.5",
+ "dg/texy": ">=2.1.0",
+ "kukulich/fshl": ">=2.1.0",
+ "andrewsville/php-token-reflection": ">=1.3.1"
+ },
+ "suggest": {
+ "ext-bz2": "*",
+ "ext-phar": "*",
+ "ext-zip": "*",
+ "ext-zlib": "*"
+ },
+ "autoload": {
+ "psr-0": {
+ "ApiGen": "./"
+ }
+ },
+ "bin": [
+ "apigen.php"
+ ],
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8.0",
+ "dev-develop": "3.0.0-dev"
+ }
+ }
+}

1 comment on commit 3c23ae7

Please sign in to comment.
Something went wrong with that request. Please try again.