apidoc 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env php
<?php
/**
 * Yii Framework 2.0 API documentation generator
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

defined('YII_DEBUG') or define('YII_DEBUG', false);

$composerAutoload = [
	__DIR__ . '/vendor/autoload.php', // standalone with "composer install" run
15
	__DIR__ . '/../../autoload.php', // script is installed as a composer binary
16
];
17
$vendorPath = null;
18 19 20
foreach($composerAutoload as $autoload) {
	if (file_exists($autoload)) {
		require($autoload);
21
		$vendorPath = dirname($autoload);
22 23 24 25
		break;
	}
}
$yiiDirs = [
26
	__DIR__ . '/../../framework', // in yii2-dev repo
27
	__DIR__ . '/vendor/yiisoft/yii2', // standalone with "composer install" run
28
	__DIR__ . '/../../yiisoft/yii2', // script is installed as a composer binary
29 30
];
foreach($yiiDirs as $dir) {
Qiang Xue committed
31 32
	if (file_exists($dir . '/Yii.php')) {
		require($dir . '/Yii.php');
33 34 35 36
		break;
	}
}
if (!class_exists('Yii')) {
37
	echo PHP_EOL . "The Yii Framework 2.0 does not seem to be installed. Try running composer install." . PHP_EOL . PHP_EOL;
38 39 40 41 42 43 44 45 46 47 48 49
	exit(1);
}

Yii::setAlias('@yii/apidoc', __DIR__);

$application = new yii\console\Application([
	'id' => 'yii2-apidoc',
	'basePath' => __DIR__,
	'enableCoreCommands' => false,
	'controllerNamespace' => 'yii\\apidoc\\commands',
	'controllerPath' => '@yii/apidoc/commands',
]);
50 51 52
if ($vendorPath !== null) {
	$application->setVendorPath($vendorPath);
}
53 54
$exitCode = $application->run();
exit($exitCode);