From 9535c4eaaa2afc2da58b1d474fbf7d7cbfb447bb Mon Sep 17 00:00:00 2001 From: Stephan Maximilian Huber Date: Tue, 11 Sep 2018 23:12:14 +0200 Subject: [PATCH] some smaller enhancements --- .env | 3 + .env.dist | 3 + bin/pha | 33 +++++++++-- composer.json | 11 +++- composer.lock | 106 +++++++++++++++++++++++++++++++++++- src/AppKernel.php | 7 +-- src/Method/ScriptMethod.php | 14 ++++- 7 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 .env create mode 100644 .env.dist diff --git a/.env b/.env new file mode 100644 index 00000000..2148dfc4 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +# This file is a "template" of which env vars need to be defined for your application +# Copy this file to .env file for development, create environment variables when deploying to production +# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration diff --git a/.env.dist b/.env.dist new file mode 100644 index 00000000..2148dfc4 --- /dev/null +++ b/.env.dist @@ -0,0 +1,3 @@ +# This file is a "template" of which env vars need to be defined for your application +# Copy this file to .env file for development, create environment variables when deploying to production +# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration diff --git a/bin/pha b/bin/pha index dbb6c988..7c8d71c3 100755 --- a/bin/pha +++ b/bin/pha @@ -1,14 +1,37 @@ #!/usr/bin/env php load(__DIR__.'/../.env'); +} + +$input = new ArgvInput(); +$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true); +$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true); + +if ($debug) { + umask(0000); + + if (class_exists(Debug::class)) { + Debug::enable(); + } +} + +$kernel = new AppKernel($env, $debug); $kernel->boot(); $container = $kernel->getContainer(); @@ -17,4 +40,4 @@ $application = $container->get(Application::class); $application->setVersion('3.0.0'); $application->setName('phabalicious'); -$application->run(null, $container->get(ConsoleOutput::class)); +$application->run($input, $container->get(ConsoleOutput::class)); diff --git a/composer.json b/composer.json index ff9b8ccc..88c6865e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,9 @@ "symfony/yaml": "^4.1", "wikimedia/composer-merge-plugin": "^1.4", "composer/semver": "^1.4", - "symfony/process": "^4.1" + "symfony/process": "^4.1", + "symfony/flex": "^1.1", + "symfony/dotenv": "^4.1" }, "require-dev": { "symfony/phpunit-bridge": "^4.1", @@ -26,5 +28,10 @@ "name": "Stephan Maximilian Huber", "email": "stephan@factorial.io" } - ] + ], + "scripts": { + "auto-scripts": { + + } + } } diff --git a/composer.lock b/composer.lock index b08f513a..85427f01 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fa789aa04029f85aebae373ac04754e6", + "content-hash": "a2506f80a9361d11a04d9a727551b349", "packages": [ { "name": "composer/semver", @@ -422,6 +422,63 @@ "homepage": "https://symfony.com", "time": "2018-08-08T11:48:58+00:00" }, + { + "name": "symfony/dotenv", + "version": "v4.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "22ca63c46e252b8a8f37b8f9e6da66bff5b3d3e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/22ca63c46e252b8a8f37b8f9e6da66bff5b3d3e7", + "reference": "22ca63c46e252b8a8f37b8f9e6da66bff5b3d3e7", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "symfony/process": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2018-07-26T11:24:31+00:00" + }, { "name": "symfony/event-dispatcher", "version": "v4.1.4", @@ -535,6 +592,53 @@ "homepage": "https://symfony.com", "time": "2018-08-18T16:52:46+00:00" }, + { + "name": "symfony/flex", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/flex.git", + "reference": "9fb60f232af0764d58002e7872acb43a74506d25" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/flex/zipball/9fb60f232af0764d58002e7872acb43a74506d25", + "reference": "9fb60f232af0764d58002e7872acb43a74506d25", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0", + "php": "^7.0" + }, + "require-dev": { + "composer/composer": "^1.0.2", + "symfony/phpunit-bridge": "^3.2.8" + }, + "type": "composer-plugin", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + }, + "class": "Symfony\\Flex\\Flex" + }, + "autoload": { + "psr-4": { + "Symfony\\Flex\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien.potencier@gmail.com" + } + ], + "description": "Composer plugin for Symfony", + "time": "2018-09-03T08:17:12+00:00" + }, { "name": "symfony/http-foundation", "version": "v4.1.4", diff --git a/src/AppKernel.php b/src/AppKernel.php index d9c10646..10af7b3b 100644 --- a/src/AppKernel.php +++ b/src/AppKernel.php @@ -10,11 +10,6 @@ class AppKernel extends Kernel { - public function __construct() - { - // these values allows container rebuild when config changes - parent::__construct('dev', true); - } /** * @return BundleInterface[] */ @@ -41,7 +36,7 @@ public function getLogDir(): string return sys_get_temp_dir() . '/phabalicious' . md5(self::class); } - protected function build(ContainerBuilder $containerBuilder): void + protected function build(ContainerBuilder $containerBuilder) { $containerBuilder->addCompilerPass(new CollectCommandsToApplicationCompilerPass()); $containerBuilder->addCompilerPass(new CollectMethodsToFactoryCompilerPass()); diff --git a/src/Method/ScriptMethod.php b/src/Method/ScriptMethod.php index 839a3ed6..e1bd7cc3 100644 --- a/src/Method/ScriptMethod.php +++ b/src/Method/ScriptMethod.php @@ -39,13 +39,20 @@ public function runScript(HostConfig $host_config, TaskContext $context) $variables = $context->get('variables', []); $callbacks = $context->get('callbacks', []); $environment = $context->get('environment', []); - $root_folder = isset($host_config['siteFolder']) ? $host_config['siteFolder'] ? $host_config['rootFolder'] : '.'; + $root_folder = isset($host_config['siteFolder']) + ? $host_config['siteFolder'] + : isset($host_config['rootFolder']) + ? $host_config['rootFolder'] + : '.'; if (!empty($host_config['environment'])) { $environment = Utilities::mergeData($environment, $host_config['environment']); } - $variables['host'] = $host_config->raw(); - $variables['settings'] = $context->getConfigurationService()->getAllSettings(['hosts', 'dockerHosts']); + $variables = [ + 'variables' => $variables, + 'host' => $host_config->raw(), + 'settings' => $context->getConfigurationService()->getAllSettings(['hosts', 'dockerHosts']), + ]; $replacements = Utilities::expandVariables($variables); $commands = Utilities::expandStrings($commands, $replacements); @@ -63,6 +70,7 @@ private function runScriptImpl( array $callbacks = [], array $environment = [], array $replacements = [] + ) { }