| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
|
|---|
| 4 | * @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | use Zend\Stdlib\ArrayUtils;
|
|---|
| 8 | use ZF\Apigility\Application;
|
|---|
| 9 |
|
|---|
| 10 | /**
|
|---|
| 11 | * This makes our life easier when dealing with paths. Everything is relative
|
|---|
| 12 | * to the application root now.
|
|---|
| 13 | */
|
|---|
| 14 | chdir(dirname(__DIR__));
|
|---|
| 15 |
|
|---|
| 16 | // Redirect legacy requests to enable/disable development mode to new tool
|
|---|
| 17 | if (php_sapi_name() === 'cli'
|
|---|
| 18 | && $argc > 2
|
|---|
| 19 | && 'development' == $argv[1]
|
|---|
| 20 | && in_array($argv[2], ['disable', 'enable'])
|
|---|
| 21 | ) {
|
|---|
| 22 | // Windows needs to execute the batch scripts that Composer generates,
|
|---|
| 23 | // and not the Unix shell version.
|
|---|
| 24 | $script = defined('PHP_WINDOWS_VERSION_BUILD') && constant('PHP_WINDOWS_VERSION_BUILD')
|
|---|
| 25 | ? '.\\vendor\\bin\\zf-development-mode.bat'
|
|---|
| 26 | : './vendor/bin/zf-development-mode';
|
|---|
| 27 | system(sprintf('%s %s', $script, $argv[2]), $return);
|
|---|
| 28 | exit($return);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | // Decline static file requests back to the PHP built-in webserver
|
|---|
| 32 | if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
|
|---|
| 33 | return false;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | if (! file_exists('vendor/autoload.php')) {
|
|---|
| 37 | throw new RuntimeException(
|
|---|
| 38 | 'Unable to load application.' . PHP_EOL
|
|---|
| 39 | . '- Type `composer install` if you are developing locally.' . PHP_EOL
|
|---|
| 40 | . '- Type `vagrant ssh -c \'composer install\'` if you are using Vagrant.' . PHP_EOL
|
|---|
| 41 | . '- Type `docker-compose run apigility composer install` if you are using Docker.'
|
|---|
| 42 | );
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | // Setup autoloading
|
|---|
| 46 | include 'vendor/autoload.php';
|
|---|
| 47 |
|
|---|
| 48 | $appConfig = include 'config/application.config.php';
|
|---|
| 49 |
|
|---|
| 50 | if (file_exists('config/development.config.php')) {
|
|---|
| 51 | $appConfig = ArrayUtils::merge(
|
|---|
| 52 | $appConfig,
|
|---|
| 53 | include 'config/development.config.php'
|
|---|
| 54 | );
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | // Run the application!
|
|---|
| 58 | Application::init($appConfig)->run();
|
|---|