|
| 1 | +#!/usr/bin/env php |
1 | 2 | <?php |
2 | 3 | /** |
3 | | - * Zend Framework (http://framework.zend.com/) |
4 | | - * |
5 | | - * @link http://github.com/zendframework/zf2 for the canonical source repository |
6 | | - * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
| 4 | + * @link http://github.com/zendframework/zend-servicemanager for the canonical source repository |
| 5 | + * @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) |
7 | 6 | * @license http://framework.zend.com/license/new-bsd New BSD License |
8 | 7 | */ |
9 | 8 |
|
10 | | -require_once(__DIR__ . '/../vendor/autoload.php'); |
11 | | -chdir(__DIR__ . '/../'); |
| 9 | +namespace Zend\ServiceManager; |
| 10 | + |
| 11 | +// Setup/verify autoloading |
| 12 | +if (file_exists($a = __DIR__ . '/../../../autoload.php')) { |
| 13 | + require $a; |
| 14 | +} elseif (file_exists($a = __DIR__ . '/../vendor/autoload.php')) { |
| 15 | + require $a; |
| 16 | +} else { |
| 17 | + fwrite(STDERR, 'Cannot locate autoloader; please run "composer install"' . PHP_EOL); |
| 18 | + exit(1); |
| 19 | +} |
12 | 20 |
|
13 | 21 | $configPath = isset($argv[1]) ? $argv[1] : ''; |
14 | 22 | $className = isset($argv[2]) ? $argv[2] : ''; |
15 | 23 |
|
16 | 24 | // Retrieve configuration |
17 | | -if (!file_exists($configPath)) { |
18 | | - throw new InvalidArgumentException('Cannot find any config at ' . $configPath); |
| 25 | +if (! file_exists($configPath)) { |
| 26 | + fwrite(STDERR, sprintf('Cannot find configuration file at path "%s"%s', $configPath, PHP_EOL)); |
| 27 | + exit(1); |
19 | 28 | } |
20 | 29 |
|
21 | 30 | $appConfig = require $configPath; |
| 31 | +if (! is_array($appConfig)) { |
| 32 | + fwrite(STDERR, sprintf('Configuration file at path "%s" does not return an array%s', $configPath, PHP_EOL)); |
| 33 | + exit(1); |
| 34 | +} |
| 35 | + |
| 36 | +if (! class_exists($className)) { |
| 37 | + fwrite(STDERR, sprintf('Class "%s" does not exist%s', $className, PHP_EOL)); |
| 38 | + exit(1); |
| 39 | +} |
22 | 40 |
|
23 | | -\Zend\ServiceManager\Tool\CliTool::createDependencyConfig($appConfig, $className); |
| 41 | +Tool\CliTool::createDependencyConfig($appConfig, $className); |
0 commit comments