Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit cefe38f

Browse files
committed
Better error handling
- use env to find php - do not throw exceptions; instead: - write to STDERR - exit 1 - test for each of: - config file exists - config file returns an array - class name exists
1 parent ee6d285 commit cefe38f

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

bin/dump-config.php

100644100755
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1+
#!/usr/bin/env php
12
<?php
23
/**
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)
76
* @license http://framework.zend.com/license/new-bsd New BSD License
87
*/
98

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+
}
1220

1321
$configPath = isset($argv[1]) ? $argv[1] : '';
1422
$className = isset($argv[2]) ? $argv[2] : '';
1523

1624
// 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);
1928
}
2029

2130
$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+
}
2240

23-
\Zend\ServiceManager\Tool\CliTool::createDependencyConfig($appConfig, $className);
41+
Tool\CliTool::createDependencyConfig($appConfig, $className);

0 commit comments

Comments
 (0)