diff --git a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/DefaultTimezone.php b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/DefaultTimezone.php new file mode 100644 index 0000000..5f20e5a --- /dev/null +++ b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/DefaultTimezone.php @@ -0,0 +1,22 @@ +get( 'php', '7.0' ); + $advancedConfig = is_array($phpVersionString); + if( $advancedConfig ) + $phpVersionString = $config->get('php.version', '7.0'); + if ( !array_key_exists( $phpVersionString, $this->phpVersions ) ) throw new PhpVersionNotAvailableException( $phpVersionString ); $phpVersion = $this->phpVersions[$phpVersionString]; $this->setAppSource( $phpVersion ); + $this->setConfig($phpVersion, $config); + return $phpVersion; } + + /** + * @param PhpVersion $phpVersion + * @param $config + */ + private function setConfig( PhpVersion $phpVersion, Configuration $config ) { + + if( !is_array($config->get('php') ) ) + return; + + $phpConfig = new PrefixConfigurationDecorator($config, 'php.'); + if( $phpVersion instanceof MemoryLimit && $phpConfig->has('memory-limit') ) + $phpVersion->setMemoryLimit( $phpConfig->get('memory-limit') ); + + if( $phpVersion instanceof PostLimit && $phpConfig->has('post-limit') ) + $phpVersion->setPostLimit( $phpConfig->get('post-limit') ); + + if( $phpVersion instanceof UploadFileLimit && $phpConfig->has('upload-file-limit') ) + $phpVersion->setUploadFileLimit( $phpConfig->get('upload-file-limit') ); + + if( $phpVersion instanceof DefaultTimezone && $phpConfig->has('default-timezone') ) + $phpVersion->setDefaultTimezone( $phpConfig->get('default-timezone') ); + } } \ No newline at end of file diff --git a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP53.php b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP53.php index d446602..9198a25 100644 --- a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP53.php +++ b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP53.php @@ -1,6 +1,10 @@ setImage( self::PHP_IMAGE ); $phpFpmService->setRestart(Service::RESTART_UNLESS_STOPPED); + $memoryLimit = $this->memoryLimit; + if( $memoryLimit !== self::DEFAULT_MEMORY_LIMIT ) + $phpFpmService->setEnvironmentVariable('PHP_MEMORY_LIMIT', $memoryLimit); + $postLimit = $this->postLimit; + if( $postLimit !== self::DEFAULT_POST_LIMIT ) + $phpFpmService->setEnvironmentVariable('PHP_POST_MAX_SIZE', $postLimit); + $uploadFileLimit = $this->uploadFileLimit; + if( $uploadFileLimit !== self::DEFAULT_UPLOAD_FILE_LIMIT ) + $phpFpmService->setEnvironmentVariable('PHP_UPLOAD_MAX_FILESIZE', $uploadFileLimit); + $defaultTimezone = $this->defaultTimezone; + if( $defaultTimezone !== self::DEFAULT_TIMEZONE) + $phpFpmService->setEnvironmentVariable('DEFAULT_TIMEZONE', $defaultTimezone); + $this->addAppSource($phpFpmService); /** @@ -41,6 +78,11 @@ public function make(Configuration $config, Service $mainService, Infrastructure foreach( $mainService->getEnvironmentVariables() as $name => $value ) $phpFpmService->setEnvironmentVariable($name, $value); + /** + * Copy links from the main service so databases etc are available + */ + $phpFpmService->addLinksFrom($mainService); + $mainService->addSidekick($phpFpmService); $mainService->addVolumeFrom($phpFpmService); $infrastructure->addService($phpFpmService); @@ -111,4 +153,39 @@ public function makeCommand( $commandName, $command, Service $mainService ) { $mainService->addSidekick($phpCommandService); return $phpCommandService; } + + /** + * @return $this + */ + public function setMemoryLimit( $limit ) { + $this->memoryLimit = $limit; + return $this; + } + + /** + * @return $this + */ + public function setPostLimit( $limit ) { + $this->postLimit = $limit; + return $this; + } + + /** + * @return $this + */ + public function setUploadFileLimit( $limit ) { + $this->uploadFileLimit = $limit; + return $this; + } + + /** + * Set the default php timezone + * + * @param $defaultTimezone + * @return $this + */ + public function setDefaultTimezone( $defaultTimezone ) { + $this->defaultTimezone = $defaultTimezone; + return $this; + } } \ No newline at end of file diff --git a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP70.php b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP70.php index 2dd8fa7..8e30086 100644 --- a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP70.php +++ b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PhpVersions/PHP70.php @@ -1,6 +1,9 @@ memoryLimit; + if( $memoryLimit !== self::DEFAULT_MEMORY_LIMIT) + $mainService->setEnvironmentVariable('PHP_MEMORY_LIMIT', $memoryLimit); + + $postLimit = $this->postLimit; + if( $postLimit !== self::DEFAULT_POST_LIMIT) + $mainService->setEnvironmentVariable('PHP_POST_MAX_SIZE', $postLimit); + + $uploadFileLimit = $this->uploadFileLimit; + if( $uploadFileLimit !== self::DEFAULT_UPLOAD_FILE_LIMIT) + $mainService->setEnvironmentVariable('PHP_UPLOAD_MAX_FILESIZE', $uploadFileLimit); } /** @@ -55,4 +85,28 @@ public function setAppService(Service $appService) { public function makeCommand( $commandName, $command, Service $mainService) { die('Error: PHP Commands not Yet implemented for PHP7'); } + + /** + * @return $this + */ + public function setMemoryLimit( $limit ) { + $this->memoryLimit = $limit; + return $this; + } + + /** + * @return $this + */ + public function setPostLimit( $limit ) { + $this->postLimit = $limit; + return $this; + } + + /** + * @return $this + */ + public function setUploadFileLimit( $limit ) { + $this->uploadFileLimit = $limit; + return $this; + } } \ No newline at end of file diff --git a/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PostLimit.php b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PostLimit.php new file mode 100644 index 0000000..838f4f2 --- /dev/null +++ b/app/Blueprint/Infrastructure/Service/Maker/PhpFpm/PostLimit.php @@ -0,0 +1,15 @@ +init( $fallbackConfigurable, $initializer ); } - $initializer->init($fallbackConfigurable, 'php', "7.0"); + $initializer->init($fallbackConfigurable, 'php', [ + 'version' => "7.0" + ]); $initializer->init($fallbackConfigurable, 'queues', []); $initializer->init($fallbackConfigurable, 'docker.repository', 'repo/name', $projectConfigurable); $initializer->init($fallbackConfigurable, 'docker.version-prefix', '', $projectConfigurable);