├── .gitignore ├── .travis.yml ├── Dockerfile ├── Dockerfile.remote ├── LICENSE ├── README.md ├── app ├── .htaccess ├── AppCache.php ├── AppKernel.php ├── Resources │ └── views │ │ ├── Tasks │ │ ├── add.html.twig │ │ └── list.html.twig │ │ └── base.html.twig ├── SymfonyRequirements.php ├── autoload.php ├── cache │ └── .gitkeep ├── check.php ├── config │ ├── config.yml │ ├── config_dev.yml │ ├── config_prod.yml │ ├── config_test.yml │ ├── parameters.yml.dist │ ├── routing.yml │ ├── routing_dev.yml │ ├── security.yml │ └── services.yml ├── console ├── logs │ └── .gitkeep └── phpunit.xml.dist ├── build.xml ├── composer.json ├── composer.lock ├── deploy.sh ├── docker-compose-remote.yml ├── docker-compose.yml ├── docker ├── php.ini ├── php.ini.remote └── vhost.conf ├── docs ├── images │ └── xdebug │ │ ├── screen01.png │ │ ├── screen02.png │ │ └── screen03.png └── xdebug.md ├── spec └── Domain │ └── UseCase │ ├── AddTaskSpec.php │ └── ListTasksSpec.php ├── src ├── .htaccess ├── AppBundle │ ├── AppBundle.php │ ├── Command │ │ └── Task │ │ │ └── AddCommand.php │ ├── Controller │ │ ├── REST │ │ │ └── Task │ │ │ │ ├── AddController.php │ │ │ │ └── ListController.php │ │ └── Web │ │ │ └── Task │ │ │ ├── AddController.php │ │ │ └── ListController.php │ ├── DependencyInjection │ │ ├── AppExtension.php │ │ └── Configuration.php │ ├── Form │ │ └── Type │ │ │ └── TaskType.php │ └── Resources │ │ └── config │ │ ├── routing_api.yml │ │ ├── routing_web.yml │ │ └── services.yml ├── Domain │ ├── Entity │ │ └── Task.php │ ├── Repository │ │ └── TaskRepository.php │ └── UseCase │ │ ├── AddTask.php │ │ ├── AddTask │ │ ├── Command.php │ │ └── Responder.php │ │ ├── ListTasks.php │ │ └── ListTasks │ │ ├── Command.php │ │ └── Responder.php └── Infrastructure │ └── ODM │ ├── Mapping │ └── Task.mongodb.yml │ └── ODMTaskRepository.php ├── startup.sh └── web ├── .htaccess ├── app.php ├── app_dev.php ├── apple-touch-icon.png ├── config.php ├── favicon.ico ├── info.php └── robots.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /web/bundles/ 2 | /app/bootstrap.php.cache 3 | /app/cache/* 4 | /app/config/parameters.yml 5 | /app/logs/* 6 | !app/cache/.gitkeep 7 | !app/logs/.gitkeep 8 | /app/phpunit.xml 9 | /build/ 10 | /vendor/ 11 | /bin/ 12 | /composer.phar 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | services: 4 | - docker 5 | 6 | before_install: 7 | - docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" 8 | 9 | before_script: 10 | - rm web/app_dev.php web/config.php web/info.php 11 | 12 | script: 13 | - docker build -f Dockerfile.remote -t sskorc/docker-symfony-dist . 14 | - docker-compose --file=docker-compose-remote.yml up -d 15 | - docker exec -it dockersymfony_php_1 bash -c "bin/phing test" 16 | - docker exec -it dockersymfony_php_1 bash -c "bin/phing quality" 17 | 18 | deploy: 19 | provider: script 20 | script: ./deploy.sh 21 | skip_cleanup: true 22 | on: 23 | branch: master 24 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sskorc/symfony2-mongo:latest 2 | 3 | ADD docker/php.ini /usr/local/etc/php/php.ini 4 | 5 | WORKDIR /var/www/docker-symfony 6 | -------------------------------------------------------------------------------- /Dockerfile.remote: -------------------------------------------------------------------------------- 1 | FROM sskorc/symfony2-mongo:latest 2 | 3 | ADD docker/php.ini.remote /usr/local/etc/php/php.ini 4 | 5 | ADD . /var/www/docker-symfony 6 | 7 | RUN /var/www/docker-symfony/startup.sh 8 | 9 | WORKDIR /var/www/docker-symfony 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2014 Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-symfony 2 | 3 | [![Build Status](https://travis-ci.org/sskorc/docker-symfony.svg?branch=master)](https://travis-ci.org/sskorc/docker-symfony) 4 | 5 | This is a simple To-do list application with GUI and REST API written in [Symfony](http://symfony.com/), running on 6 | multiple [Docker](http://www.docker.com/) containers. [Docker Compose](http://docs.docker.com/compose/) 7 | is used for orchestration. 8 | 9 | ## Previous versions 10 | - If you are looking for products example rather than to-do list, 11 | check the [`products` tag](https://github.com/sskorc/docker-symfony/tree/products). 12 | - If you are looking for a multiple containers example with Apache, 13 | check the [`apache` tag](https://github.com/sskorc/docker-symfony/tree/apache). 14 | - If you are looking for a single container example with supervisor and Vagrant, 15 | check the [`single-container` tag](https://github.com/sskorc/docker-symfony/tree/single-container). 16 | 17 | ## Multiple containers 18 | 19 | This environment uses 3 containers: 20 | 21 | 1. The `php` container with PHP-FPM, being build from `Dockerfile`. It's based on `sskorc/symfony2-mongo` image. You can 22 | find its `Dockerfile` in [this repo](https://github.com/sskorc/symfony2-mongo-dockerimage). This container shares 23 | the application sources with the host machine. 24 | 2. The `nginx` container with nginx, pulled directly from the official nginx image on Docker Hub. This container shares 25 | the application sources with the host machine. 26 | 3. The `db` container with MongoDB, pulled directly from the official MongoDB image on Docker Hub. This container shares 27 | DB data with the Docker Machine VM. 28 | 29 | Containers are managed by Docker Compose. The configuration is in the `docker-compose.yml`. 30 | 31 | ## Requirements 32 | 33 | Basically, you need to have [Docker Compose installed](http://docs.docker.com/compose/#installation-and-set-up). 34 | 35 | If you use Mac OS X or Windows as your host OS, I recommend using [Docker Machine](https://docs.docker.com/machine/) 36 | as the proxy VM to run Docker. 37 | 38 | ## How to use it? 39 | 40 | ### Start the environment 41 | 42 | In the project root directory run the following command: 43 | ``` 44 | docker-compose up -d 45 | ``` 46 | 47 | This command will build the `php` Docker image and run its container together with `nginx` and `db` containers. 48 | 49 | ### Prepare the environment 50 | 51 | 1. Log in to the `php` container by running the following command: 52 | ``` 53 | docker exec -it dockersymfony_php_1 bash 54 | ``` 55 | 56 | 2. Install dependencies by running the following command: 57 | ``` 58 | cd /var/www/docker-symfony && composer install -n 59 | ``` 60 | 61 | 3. Change `/tmp` dir permissions: 62 | ``` 63 | chown -R www-data:www-data /tmp 64 | ``` 65 | 66 | ### Update your hosts 67 | 68 | #### Mac OS X 69 | 70 | 1. Check Docker Machine IP address: `docker-machine ip dev`. 71 | 72 | 2. Assuming it's 192.168.99.100, add the following line to your `/etc/hosts` file: 73 | ``` 74 | 192.168.99.100 docker-symfony.dev 75 | ``` 76 | 77 | #### Linux 78 | 79 | TBA 80 | 81 | #### Windows 82 | 83 | 1. Check Docker Machine IP address: `docker-machine ip dev`. 84 | 85 | 2. Assuming it's 192.168.99.100, add the following line to your `%SystemRoot%\System32\drivers\etc\hosts` file: 86 | ``` 87 | 192.168.99.100 docker-symfony.dev 88 | ``` 89 | 90 | ### Test the application 91 | 92 | #### Web 93 | 94 | You can test the application by following [http://docker-symfony.dev/]() URL in your browser. 95 | 96 | #### REST API 97 | 98 | - You can test the REST API by sending the POST request with the `name` parameter to `http://docker-symfony.dev/api/tasks`. 99 | Example: 100 | ``` 101 | curl -w "\n" -H "Content-Type: application/json" -X POST -d '{"name":"Hello!"}' http://docker-symfony.dev/api/tasks 102 | ``` 103 | 104 | - You can get all products by sending the GET request to `http://docker-symfony.dev/api/tasks`. Example: 105 | ``` 106 | curl -w "\n" -X GET http://docker-symfony.dev/api/tasks 107 | ``` 108 | 109 | #### Debugging 110 | 111 | This application is ready to be debugged by [Xdebug](https://xdebug.org/). If you want to configure your host and 112 | PHPStorm to debug this app, please follow [the instruction](docs/xdebug.md). 113 | 114 | ## Continuous Delivery 115 | 116 | The application is being build on [Travis CI](https://travis-ci.org/sskorc/docker-symfony) and it's being deployed to 117 | [Docker Cloud](https://cloud.docker.com/). 118 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Order deny,allow 6 | Deny from all 7 | 8 | -------------------------------------------------------------------------------- /app/AppCache.php: -------------------------------------------------------------------------------- 1 | getEnvironment(), array('dev', 'test'))) { 23 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 24 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 25 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 26 | $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 27 | } 28 | 29 | return $bundles; 30 | } 31 | 32 | public function registerContainerConfiguration(LoaderInterface $loader) 33 | { 34 | $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); 35 | } 36 | 37 | public function getCacheDir() 38 | { 39 | return '/tmp/sf2/cache/' . $this->environment; 40 | } 41 | 42 | public function getLogDir() 43 | { 44 | return '/tmp/sf2/logs'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/Resources/views/Tasks/add.html.twig: -------------------------------------------------------------------------------- 1 | {% extends '::base.html.twig' %} 2 | 3 | {% block base_content %} 4 |

Add task

5 | {% form_theme form 'bootstrap_3_layout.html.twig' %} 6 | {{ form_start(form) }} 7 | {{ form_row(form.name) }} 8 | 9 |
10 | 11 |
12 | {{ form_end(form) }} 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /app/Resources/views/Tasks/list.html.twig: -------------------------------------------------------------------------------- 1 | {% extends '::base.html.twig' %} 2 | 3 | {% block base_content %} 4 | {% for flashMessage in app.session.flashbag.get('success') %} 5 | 6 | {% endfor %} 7 |
8 | 9 | Add task 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | {% for task in tasks %} 22 | 23 | 24 | 25 | 26 | 27 | {% endfor %} 28 | 29 |
#Created atName
{{ loop.index }}{{ task.createdAt|date("d.m.Y H:i:s") }}{{ task.name }}
30 | {% endblock %} 31 | -------------------------------------------------------------------------------- /app/Resources/views/base.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {% block title %}To-do project{% endblock %} 8 | {% block stylesheets %} 9 | 10 | 11 | {% endblock %} 12 | 13 | 14 |
15 | 18 |
19 | {% block base_content %} 20 | {% endblock %} 21 |
22 |
23 | {% block base_scripts %} 24 | 25 | {% endblock %} 26 | {% block scripts %} 27 | {% endblock %} 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/SymfonyRequirements.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | /* 13 | * Users of PHP 5.2 should be able to run the requirements checks. 14 | * This is why the file and all classes must be compatible with PHP 5.2+ 15 | * (e.g. not using namespaces and closures). 16 | * 17 | * ************** CAUTION ************** 18 | * 19 | * DO NOT EDIT THIS FILE as it will be overridden by Composer as part of 20 | * the installation/update process. The original file resides in the 21 | * SensioDistributionBundle. 22 | * 23 | * ************** CAUTION ************** 24 | */ 25 | 26 | /** 27 | * Represents a single PHP requirement, e.g. an installed extension. 28 | * It can be a mandatory requirement or an optional recommendation. 29 | * There is a special subclass, named PhpIniRequirement, to check a php.ini configuration. 30 | * 31 | * @author Tobias Schultze 32 | */ 33 | class Requirement 34 | { 35 | private $fulfilled; 36 | private $testMessage; 37 | private $helpText; 38 | private $helpHtml; 39 | private $optional; 40 | 41 | /** 42 | * Constructor that initializes the requirement. 43 | * 44 | * @param bool $fulfilled Whether the requirement is fulfilled 45 | * @param string $testMessage The message for testing the requirement 46 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 47 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 48 | * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement 49 | */ 50 | public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false) 51 | { 52 | $this->fulfilled = (bool) $fulfilled; 53 | $this->testMessage = (string) $testMessage; 54 | $this->helpHtml = (string) $helpHtml; 55 | $this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText; 56 | $this->optional = (bool) $optional; 57 | } 58 | 59 | /** 60 | * Returns whether the requirement is fulfilled. 61 | * 62 | * @return bool true if fulfilled, otherwise false 63 | */ 64 | public function isFulfilled() 65 | { 66 | return $this->fulfilled; 67 | } 68 | 69 | /** 70 | * Returns the message for testing the requirement. 71 | * 72 | * @return string The test message 73 | */ 74 | public function getTestMessage() 75 | { 76 | return $this->testMessage; 77 | } 78 | 79 | /** 80 | * Returns the help text for resolving the problem. 81 | * 82 | * @return string The help text 83 | */ 84 | public function getHelpText() 85 | { 86 | return $this->helpText; 87 | } 88 | 89 | /** 90 | * Returns the help text formatted in HTML. 91 | * 92 | * @return string The HTML help 93 | */ 94 | public function getHelpHtml() 95 | { 96 | return $this->helpHtml; 97 | } 98 | 99 | /** 100 | * Returns whether this is only an optional recommendation and not a mandatory requirement. 101 | * 102 | * @return bool true if optional, false if mandatory 103 | */ 104 | public function isOptional() 105 | { 106 | return $this->optional; 107 | } 108 | } 109 | 110 | /** 111 | * Represents a PHP requirement in form of a php.ini configuration. 112 | * 113 | * @author Tobias Schultze 114 | */ 115 | class PhpIniRequirement extends Requirement 116 | { 117 | /** 118 | * Constructor that initializes the requirement. 119 | * 120 | * @param string $cfgName The configuration name used for ini_get() 121 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 122 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 123 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 124 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 125 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 126 | * @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 127 | * @param string|null $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 128 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 129 | * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement 130 | */ 131 | public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false) 132 | { 133 | $cfgValue = ini_get($cfgName); 134 | 135 | if (is_callable($evaluation)) { 136 | if (null === $testMessage || null === $helpHtml) { 137 | throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.'); 138 | } 139 | 140 | $fulfilled = call_user_func($evaluation, $cfgValue); 141 | } else { 142 | if (null === $testMessage) { 143 | $testMessage = sprintf('%s %s be %s in php.ini', 144 | $cfgName, 145 | $optional ? 'should' : 'must', 146 | $evaluation ? 'enabled' : 'disabled' 147 | ); 148 | } 149 | 150 | if (null === $helpHtml) { 151 | $helpHtml = sprintf('Set %s to %s in php.ini*.', 152 | $cfgName, 153 | $evaluation ? 'on' : 'off' 154 | ); 155 | } 156 | 157 | $fulfilled = $evaluation == $cfgValue; 158 | } 159 | 160 | parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional); 161 | } 162 | } 163 | 164 | /** 165 | * A RequirementCollection represents a set of Requirement instances. 166 | * 167 | * @author Tobias Schultze 168 | */ 169 | class RequirementCollection implements IteratorAggregate 170 | { 171 | private $requirements = array(); 172 | 173 | /** 174 | * Gets the current RequirementCollection as an Iterator. 175 | * 176 | * @return Traversable A Traversable interface 177 | */ 178 | public function getIterator() 179 | { 180 | return new ArrayIterator($this->requirements); 181 | } 182 | 183 | /** 184 | * Adds a Requirement. 185 | * 186 | * @param Requirement $requirement A Requirement instance 187 | */ 188 | public function add(Requirement $requirement) 189 | { 190 | $this->requirements[] = $requirement; 191 | } 192 | 193 | /** 194 | * Adds a mandatory requirement. 195 | * 196 | * @param bool $fulfilled Whether the requirement is fulfilled 197 | * @param string $testMessage The message for testing the requirement 198 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 199 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 200 | */ 201 | public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null) 202 | { 203 | $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false)); 204 | } 205 | 206 | /** 207 | * Adds an optional recommendation. 208 | * 209 | * @param bool $fulfilled Whether the recommendation is fulfilled 210 | * @param string $testMessage The message for testing the recommendation 211 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 212 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 213 | */ 214 | public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null) 215 | { 216 | $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true)); 217 | } 218 | 219 | /** 220 | * Adds a mandatory requirement in form of a php.ini configuration. 221 | * 222 | * @param string $cfgName The configuration name used for ini_get() 223 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 224 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 225 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 226 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 227 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 228 | * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 229 | * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 230 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 231 | */ 232 | public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) 233 | { 234 | $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false)); 235 | } 236 | 237 | /** 238 | * Adds an optional recommendation in form of a php.ini configuration. 239 | * 240 | * @param string $cfgName The configuration name used for ini_get() 241 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 242 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 243 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 244 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 245 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 246 | * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 247 | * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 248 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 249 | */ 250 | public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) 251 | { 252 | $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true)); 253 | } 254 | 255 | /** 256 | * Adds a requirement collection to the current set of requirements. 257 | * 258 | * @param RequirementCollection $collection A RequirementCollection instance 259 | */ 260 | public function addCollection(RequirementCollection $collection) 261 | { 262 | $this->requirements = array_merge($this->requirements, $collection->all()); 263 | } 264 | 265 | /** 266 | * Returns both requirements and recommendations. 267 | * 268 | * @return array Array of Requirement instances 269 | */ 270 | public function all() 271 | { 272 | return $this->requirements; 273 | } 274 | 275 | /** 276 | * Returns all mandatory requirements. 277 | * 278 | * @return array Array of Requirement instances 279 | */ 280 | public function getRequirements() 281 | { 282 | $array = array(); 283 | foreach ($this->requirements as $req) { 284 | if (!$req->isOptional()) { 285 | $array[] = $req; 286 | } 287 | } 288 | 289 | return $array; 290 | } 291 | 292 | /** 293 | * Returns the mandatory requirements that were not met. 294 | * 295 | * @return array Array of Requirement instances 296 | */ 297 | public function getFailedRequirements() 298 | { 299 | $array = array(); 300 | foreach ($this->requirements as $req) { 301 | if (!$req->isFulfilled() && !$req->isOptional()) { 302 | $array[] = $req; 303 | } 304 | } 305 | 306 | return $array; 307 | } 308 | 309 | /** 310 | * Returns all optional recommendations. 311 | * 312 | * @return array Array of Requirement instances 313 | */ 314 | public function getRecommendations() 315 | { 316 | $array = array(); 317 | foreach ($this->requirements as $req) { 318 | if ($req->isOptional()) { 319 | $array[] = $req; 320 | } 321 | } 322 | 323 | return $array; 324 | } 325 | 326 | /** 327 | * Returns the recommendations that were not met. 328 | * 329 | * @return array Array of Requirement instances 330 | */ 331 | public function getFailedRecommendations() 332 | { 333 | $array = array(); 334 | foreach ($this->requirements as $req) { 335 | if (!$req->isFulfilled() && $req->isOptional()) { 336 | $array[] = $req; 337 | } 338 | } 339 | 340 | return $array; 341 | } 342 | 343 | /** 344 | * Returns whether a php.ini configuration is not correct. 345 | * 346 | * @return bool php.ini configuration problem? 347 | */ 348 | public function hasPhpIniConfigIssue() 349 | { 350 | foreach ($this->requirements as $req) { 351 | if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) { 352 | return true; 353 | } 354 | } 355 | 356 | return false; 357 | } 358 | 359 | /** 360 | * Returns the PHP configuration file (php.ini) path. 361 | * 362 | * @return string|false php.ini file path 363 | */ 364 | public function getPhpIniConfigPath() 365 | { 366 | return get_cfg_var('cfg_file_path'); 367 | } 368 | } 369 | 370 | /** 371 | * This class specifies all requirements and optional recommendations that 372 | * are necessary to run the Symfony Standard Edition. 373 | * 374 | * @author Tobias Schultze 375 | * @author Fabien Potencier 376 | */ 377 | class SymfonyRequirements extends RequirementCollection 378 | { 379 | const REQUIRED_PHP_VERSION = '5.3.3'; 380 | 381 | /** 382 | * Constructor that initializes the requirements. 383 | */ 384 | public function __construct() 385 | { 386 | /* mandatory requirements follow */ 387 | 388 | $installedPhpVersion = phpversion(); 389 | 390 | $this->addRequirement( 391 | version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='), 392 | sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion), 393 | sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. 394 | Before using Symfony, upgrade your PHP installation, preferably to the latest version.', 395 | $installedPhpVersion, self::REQUIRED_PHP_VERSION), 396 | sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion) 397 | ); 398 | 399 | $this->addRequirement( 400 | version_compare($installedPhpVersion, '5.3.16', '!='), 401 | 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it', 402 | 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)' 403 | ); 404 | 405 | $this->addRequirement( 406 | is_dir(__DIR__.'/../vendor/composer'), 407 | 'Vendor libraries must be installed', 408 | 'Vendor libraries are missing. Install composer following instructions from http://getcomposer.org/. '. 409 | 'Then run "php composer.phar install" to install them.' 410 | ); 411 | 412 | $cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache'; 413 | 414 | $this->addRequirement( 415 | is_writable($cacheDir), 416 | 'app/cache/ or var/cache/ directory must be writable', 417 | 'Change the permissions of either "app/cache/" or "var/cache/" directory so that the web server can write into it.' 418 | ); 419 | 420 | $logsDir = is_dir(__DIR__.'/../var/logs') ? __DIR__.'/../var/logs' : __DIR__.'/logs'; 421 | 422 | $this->addRequirement( 423 | is_writable($logsDir), 424 | 'app/logs/ or var/logs/ directory must be writable', 425 | 'Change the permissions of either "app/logs/" or "var/logs/" directory so that the web server can write into it.' 426 | ); 427 | 428 | $this->addPhpIniRequirement( 429 | 'date.timezone', true, false, 430 | 'date.timezone setting must be set', 431 | 'Set the "date.timezone" setting in php.ini* (like Europe/Paris).' 432 | ); 433 | 434 | if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { 435 | $timezones = array(); 436 | foreach (DateTimeZone::listAbbreviations() as $abbreviations) { 437 | foreach ($abbreviations as $abbreviation) { 438 | $timezones[$abbreviation['timezone_id']] = true; 439 | } 440 | } 441 | 442 | $this->addRequirement( 443 | isset($timezones[@date_default_timezone_get()]), 444 | sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()), 445 | 'Your default timezone is not supported by PHP. Check for typos in your php.ini file and have a look at the list of deprecated timezones at http://php.net/manual/en/timezones.others.php.' 446 | ); 447 | } 448 | 449 | $this->addRequirement( 450 | function_exists('iconv'), 451 | 'iconv() must be available', 452 | 'Install and enable the iconv extension.' 453 | ); 454 | 455 | $this->addRequirement( 456 | function_exists('json_encode'), 457 | 'json_encode() must be available', 458 | 'Install and enable the JSON extension.' 459 | ); 460 | 461 | $this->addRequirement( 462 | function_exists('session_start'), 463 | 'session_start() must be available', 464 | 'Install and enable the session extension.' 465 | ); 466 | 467 | $this->addRequirement( 468 | function_exists('ctype_alpha'), 469 | 'ctype_alpha() must be available', 470 | 'Install and enable the ctype extension.' 471 | ); 472 | 473 | $this->addRequirement( 474 | function_exists('token_get_all'), 475 | 'token_get_all() must be available', 476 | 'Install and enable the Tokenizer extension.' 477 | ); 478 | 479 | $this->addRequirement( 480 | function_exists('simplexml_import_dom'), 481 | 'simplexml_import_dom() must be available', 482 | 'Install and enable the SimpleXML extension.' 483 | ); 484 | 485 | if (function_exists('apc_store') && ini_get('apc.enabled')) { 486 | if (version_compare($installedPhpVersion, '5.4.0', '>=')) { 487 | $this->addRequirement( 488 | version_compare(phpversion('apc'), '3.1.13', '>='), 489 | 'APC version must be at least 3.1.13 when using PHP 5.4', 490 | 'Upgrade your APC extension (3.1.13+).' 491 | ); 492 | } else { 493 | $this->addRequirement( 494 | version_compare(phpversion('apc'), '3.0.17', '>='), 495 | 'APC version must be at least 3.0.17', 496 | 'Upgrade your APC extension (3.0.17+).' 497 | ); 498 | } 499 | } 500 | 501 | $this->addPhpIniRequirement('detect_unicode', false); 502 | 503 | if (extension_loaded('suhosin')) { 504 | $this->addPhpIniRequirement( 505 | 'suhosin.executor.include.whitelist', 506 | create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), 507 | false, 508 | 'suhosin.executor.include.whitelist must be configured correctly in php.ini', 509 | 'Add "phar" to suhosin.executor.include.whitelist in php.ini*.' 510 | ); 511 | } 512 | 513 | if (extension_loaded('xdebug')) { 514 | $this->addPhpIniRequirement( 515 | 'xdebug.show_exception_trace', false, true 516 | ); 517 | 518 | $this->addPhpIniRequirement( 519 | 'xdebug.scream', false, true 520 | ); 521 | 522 | $this->addPhpIniRecommendation( 523 | 'xdebug.max_nesting_level', 524 | create_function('$cfgValue', 'return $cfgValue > 100;'), 525 | true, 526 | 'xdebug.max_nesting_level should be above 100 in php.ini', 527 | 'Set "xdebug.max_nesting_level" to e.g. "250" in php.ini* to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.' 528 | ); 529 | } 530 | 531 | $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null; 532 | 533 | $this->addRequirement( 534 | null !== $pcreVersion, 535 | 'PCRE extension must be available', 536 | 'Install the PCRE extension (version 8.0+).' 537 | ); 538 | 539 | if (extension_loaded('mbstring')) { 540 | $this->addPhpIniRequirement( 541 | 'mbstring.func_overload', 542 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), 543 | true, 544 | 'string functions should not be overloaded', 545 | 'Set "mbstring.func_overload" to 0 in php.ini* to disable function overloading by the mbstring extension.' 546 | ); 547 | } 548 | 549 | /* optional recommendations follow */ 550 | 551 | if (file_exists(__DIR__.'/../vendor/composer')) { 552 | require_once __DIR__.'/../vendor/autoload.php'; 553 | 554 | try { 555 | $r = new ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle'); 556 | 557 | $contents = file_get_contents(dirname($r->getFileName()).'/Resources/skeleton/app/SymfonyRequirements.php'); 558 | } catch (ReflectionException $e) { 559 | $contents = ''; 560 | } 561 | $this->addRecommendation( 562 | file_get_contents(__FILE__) === $contents, 563 | 'Requirements file should be up-to-date', 564 | 'Your requirements file is outdated. Run composer install and re-check your configuration.' 565 | ); 566 | } 567 | 568 | $this->addRecommendation( 569 | version_compare($installedPhpVersion, '5.3.4', '>='), 570 | 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions', 571 | 'Your project might malfunction randomly due to PHP bug #52083 ("Notice: Trying to get property of non-object"). Install PHP 5.3.4 or newer.' 572 | ); 573 | 574 | $this->addRecommendation( 575 | version_compare($installedPhpVersion, '5.3.8', '>='), 576 | 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156', 577 | 'Install PHP 5.3.8 or newer if your project uses annotations.' 578 | ); 579 | 580 | $this->addRecommendation( 581 | version_compare($installedPhpVersion, '5.4.0', '!='), 582 | 'You should not use PHP 5.4.0 due to the PHP bug #61453', 583 | 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.' 584 | ); 585 | 586 | $this->addRecommendation( 587 | version_compare($installedPhpVersion, '5.4.11', '>='), 588 | 'When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)', 589 | 'Install PHP 5.4.11 or newer if your project uses the logout handler from the Symfony Security Component.' 590 | ); 591 | 592 | $this->addRecommendation( 593 | (version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<')) 594 | || 595 | version_compare($installedPhpVersion, '5.4.8', '>='), 596 | 'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909', 597 | 'Install PHP 5.3.18+ or PHP 5.4.8+ if you want nice error messages for all fatal errors in the development environment.' 598 | ); 599 | 600 | if (null !== $pcreVersion) { 601 | $this->addRecommendation( 602 | $pcreVersion >= 8.0, 603 | sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion), 604 | 'PCRE 8.0+ is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.' 605 | ); 606 | } 607 | 608 | $this->addRecommendation( 609 | class_exists('DomDocument'), 610 | 'PHP-DOM and PHP-XML modules should be installed', 611 | 'Install and enable the PHP-DOM and the PHP-XML modules.' 612 | ); 613 | 614 | $this->addRecommendation( 615 | function_exists('mb_strlen'), 616 | 'mb_strlen() should be available', 617 | 'Install and enable the mbstring extension.' 618 | ); 619 | 620 | $this->addRecommendation( 621 | function_exists('iconv'), 622 | 'iconv() should be available', 623 | 'Install and enable the iconv extension.' 624 | ); 625 | 626 | $this->addRecommendation( 627 | function_exists('utf8_decode'), 628 | 'utf8_decode() should be available', 629 | 'Install and enable the XML extension.' 630 | ); 631 | 632 | $this->addRecommendation( 633 | function_exists('filter_var'), 634 | 'filter_var() should be available', 635 | 'Install and enable the filter extension.' 636 | ); 637 | 638 | if (!defined('PHP_WINDOWS_VERSION_BUILD')) { 639 | $this->addRecommendation( 640 | function_exists('posix_isatty'), 641 | 'posix_isatty() should be available', 642 | 'Install and enable the php_posix extension (used to colorize the CLI output).' 643 | ); 644 | } 645 | 646 | $this->addRecommendation( 647 | extension_loaded('intl'), 648 | 'intl extension should be available', 649 | 'Install and enable the intl extension (used for validators).' 650 | ); 651 | 652 | if (extension_loaded('intl')) { 653 | // in some WAMP server installations, new Collator() returns null 654 | $this->addRecommendation( 655 | null !== new Collator('fr_FR'), 656 | 'intl extension should be correctly configured', 657 | 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.' 658 | ); 659 | 660 | // check for compatible ICU versions (only done when you have the intl extension) 661 | if (defined('INTL_ICU_VERSION')) { 662 | $version = INTL_ICU_VERSION; 663 | } else { 664 | $reflector = new ReflectionExtension('intl'); 665 | 666 | ob_start(); 667 | $reflector->info(); 668 | $output = strip_tags(ob_get_clean()); 669 | 670 | preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); 671 | $version = $matches[1]; 672 | } 673 | 674 | $this->addRecommendation( 675 | version_compare($version, '4.0', '>='), 676 | 'intl ICU version should be at least 4+', 677 | 'Upgrade your intl extension with a newer ICU version (4+).' 678 | ); 679 | 680 | $this->addPhpIniRecommendation( 681 | 'intl.error_level', 682 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), 683 | true, 684 | 'intl.error_level should be 0 in php.ini', 685 | 'Set "intl.error_level" to "0" in php.ini* to inhibit the messages when an error occurs in ICU functions.' 686 | ); 687 | } 688 | 689 | $accelerator = 690 | (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable')) 691 | || 692 | (extension_loaded('apc') && ini_get('apc.enabled')) 693 | || 694 | (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable')) 695 | || 696 | (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) 697 | || 698 | (extension_loaded('xcache') && ini_get('xcache.cacher')) 699 | || 700 | (extension_loaded('wincache') && ini_get('wincache.ocenabled')) 701 | ; 702 | 703 | $this->addRecommendation( 704 | $accelerator, 705 | 'a PHP accelerator should be installed', 706 | 'Install and/or enable a PHP accelerator (highly recommended).' 707 | ); 708 | 709 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 710 | $this->addRecommendation( 711 | $this->getRealpathCacheSize() > 1000, 712 | 'realpath_cache_size should be above 1024 in php.ini', 713 | 'Set "realpath_cache_size" to e.g. "1024" in php.ini* to improve performance on windows.' 714 | ); 715 | } 716 | 717 | $this->addPhpIniRecommendation('short_open_tag', false); 718 | 719 | $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); 720 | 721 | $this->addPhpIniRecommendation('register_globals', false, true); 722 | 723 | $this->addPhpIniRecommendation('session.auto_start', false); 724 | 725 | $this->addRecommendation( 726 | class_exists('PDO'), 727 | 'PDO should be installed', 728 | 'Install PDO (mandatory for Doctrine).' 729 | ); 730 | 731 | if (class_exists('PDO')) { 732 | $drivers = PDO::getAvailableDrivers(); 733 | $this->addRecommendation( 734 | count($drivers) > 0, 735 | sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'), 736 | 'Install PDO drivers (mandatory for Doctrine).' 737 | ); 738 | } 739 | } 740 | 741 | /** 742 | * Loads realpath_cache_size from php.ini and converts it to int. 743 | * 744 | * (e.g. 16k is converted to 16384 int) 745 | * 746 | * @return int 747 | */ 748 | protected function getRealpathCacheSize() 749 | { 750 | $size = ini_get('realpath_cache_size'); 751 | $size = trim($size); 752 | $unit = strtolower(substr($size, -1, 1)); 753 | switch ($unit) { 754 | case 'g': 755 | return $size * 1024 * 1024 * 1024; 756 | case 'm': 757 | return $size * 1024 * 1024; 758 | case 'k': 759 | return $size * 1024; 760 | default: 761 | return (int) $size; 762 | } 763 | } 764 | } 765 | -------------------------------------------------------------------------------- /app/autoload.php: -------------------------------------------------------------------------------- 1 | getPhpIniConfigPath(); 8 | 9 | echo_title('Symfony2 Requirements Checker'); 10 | 11 | echo '> PHP is using the following php.ini file:'.PHP_EOL; 12 | if ($iniPath) { 13 | echo_style('green', ' '.$iniPath); 14 | } else { 15 | echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!'); 16 | } 17 | 18 | echo PHP_EOL.PHP_EOL; 19 | 20 | echo '> Checking Symfony requirements:'.PHP_EOL.' '; 21 | 22 | $messages = array(); 23 | foreach ($symfonyRequirements->getRequirements() as $req) { 24 | /** @var $req Requirement */ 25 | if ($helpText = get_error_message($req, $lineSize)) { 26 | echo_style('red', 'E'); 27 | $messages['error'][] = $helpText; 28 | } else { 29 | echo_style('green', '.'); 30 | } 31 | } 32 | 33 | $checkPassed = empty($messages['error']); 34 | 35 | foreach ($symfonyRequirements->getRecommendations() as $req) { 36 | if ($helpText = get_error_message($req, $lineSize)) { 37 | echo_style('yellow', 'W'); 38 | $messages['warning'][] = $helpText; 39 | } else { 40 | echo_style('green', '.'); 41 | } 42 | } 43 | 44 | if ($checkPassed) { 45 | echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects'); 46 | } else { 47 | echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects'); 48 | 49 | echo_title('Fix the following mandatory requirements', 'red'); 50 | 51 | foreach ($messages['error'] as $helpText) { 52 | echo ' * '.$helpText.PHP_EOL; 53 | } 54 | } 55 | 56 | if (!empty($messages['warning'])) { 57 | echo_title('Optional recommendations to improve your setup', 'yellow'); 58 | 59 | foreach ($messages['warning'] as $helpText) { 60 | echo ' * '.$helpText.PHP_EOL; 61 | } 62 | } 63 | 64 | echo PHP_EOL; 65 | echo_style('title', 'Note'); 66 | echo ' The command console could use a different php.ini file'.PHP_EOL; 67 | echo_style('title', '~~~~'); 68 | echo ' than the one used with your web server. To be on the'.PHP_EOL; 69 | echo ' safe side, please check the requirements from your web'.PHP_EOL; 70 | echo ' server using the '; 71 | echo_style('yellow', 'web/config.php'); 72 | echo ' script.'.PHP_EOL; 73 | echo PHP_EOL; 74 | 75 | exit($checkPassed ? 0 : 1); 76 | 77 | function get_error_message(Requirement $requirement, $lineSize) 78 | { 79 | if ($requirement->isFulfilled()) { 80 | return; 81 | } 82 | 83 | $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL; 84 | $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL; 85 | 86 | return $errorMessage; 87 | } 88 | 89 | function echo_title($title, $style = null) 90 | { 91 | $style = $style ?: 'title'; 92 | 93 | echo PHP_EOL; 94 | echo_style($style, $title.PHP_EOL); 95 | echo_style($style, str_repeat('~', strlen($title)).PHP_EOL); 96 | echo PHP_EOL; 97 | } 98 | 99 | function echo_style($style, $message) 100 | { 101 | // ANSI color codes 102 | $styles = array( 103 | 'reset' => "\033[0m", 104 | 'red' => "\033[31m", 105 | 'green' => "\033[32m", 106 | 'yellow' => "\033[33m", 107 | 'error' => "\033[37;41m", 108 | 'success' => "\033[37;42m", 109 | 'title' => "\033[34m", 110 | ); 111 | $supports = has_color_support(); 112 | 113 | echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : ''); 114 | } 115 | 116 | function echo_block($style, $title, $message) 117 | { 118 | $message = ' '.trim($message).' '; 119 | $width = strlen($message); 120 | 121 | echo PHP_EOL.PHP_EOL; 122 | 123 | echo_style($style, str_repeat(' ', $width).PHP_EOL); 124 | echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL); 125 | echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL); 126 | echo_style($style, str_repeat(' ', $width).PHP_EOL); 127 | } 128 | 129 | function has_color_support() 130 | { 131 | static $support; 132 | 133 | if (null === $support) { 134 | if (DIRECTORY_SEPARATOR == '\\') { 135 | $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); 136 | } else { 137 | $support = function_exists('posix_isatty') && @posix_isatty(STDOUT); 138 | } 139 | } 140 | 141 | return $support; 142 | } 143 | -------------------------------------------------------------------------------- /app/config/config.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: parameters.yml } 3 | - { resource: security.yml } 4 | - { resource: services.yml } 5 | 6 | framework: 7 | #esi: ~ 8 | #translator: { fallback: "%locale%" } 9 | secret: "%secret%" 10 | router: 11 | resource: "%kernel.root_dir%/config/routing.yml" 12 | strict_requirements: ~ 13 | form: ~ 14 | csrf_protection: ~ 15 | validation: { enable_annotations: true } 16 | templating: 17 | engines: ['twig'] 18 | #assets_version: SomeVersionScheme 19 | default_locale: "%locale%" 20 | trusted_hosts: ~ 21 | trusted_proxies: ~ 22 | session: 23 | # handler_id set to null will use default session handler from php.ini 24 | handler_id: ~ 25 | fragments: ~ 26 | http_method_override: true 27 | 28 | # Twig Configuration 29 | twig: 30 | debug: "%kernel.debug%" 31 | strict_variables: "%kernel.debug%" 32 | 33 | doctrine_mongodb: 34 | connections: 35 | default: 36 | server: %mongo_database_server% 37 | options: {} 38 | default_database: %mongo_database_name% 39 | document_managers: 40 | default: 41 | auto_mapping: true 42 | mappings: 43 | app: 44 | type: yml 45 | dir: %kernel.root_dir%/../src/Infrastructure/ODM/Mapping/ 46 | prefix: Domain\Entity 47 | is_bundle: false 48 | 49 | 50 | fos_rest: 51 | routing_loader: 52 | default_format: json 53 | exception: 54 | messages: 55 | 'Symfony\Component\HttpKernel\Exception\HttpException': true 56 | -------------------------------------------------------------------------------- /app/config/config_dev.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config.yml } 3 | 4 | framework: 5 | router: 6 | resource: "%kernel.root_dir%/config/routing_dev.yml" 7 | strict_requirements: true 8 | profiler: { only_exceptions: false } 9 | 10 | web_profiler: 11 | toolbar: true 12 | intercept_redirects: false 13 | 14 | monolog: 15 | handlers: 16 | main: 17 | type: stream 18 | path: "%kernel.logs_dir%/%kernel.environment%.log" 19 | level: debug 20 | console: 21 | type: console 22 | bubble: false 23 | verbosity_levels: 24 | VERBOSITY_VERBOSE: INFO 25 | VERBOSITY_VERY_VERBOSE: DEBUG 26 | channels: ["!doctrine"] 27 | console_very_verbose: 28 | type: console 29 | bubble: false 30 | verbosity_levels: 31 | VERBOSITY_VERBOSE: NOTICE 32 | VERBOSITY_VERY_VERBOSE: NOTICE 33 | VERBOSITY_DEBUG: DEBUG 34 | channels: ["doctrine"] 35 | # uncomment to get logging in your browser 36 | # you may have to allow bigger header sizes in your Web server configuration 37 | #firephp: 38 | # type: firephp 39 | # level: info 40 | #chromephp: 41 | # type: chromephp 42 | # level: info 43 | 44 | #swiftmailer: 45 | # delivery_address: me@example.com 46 | -------------------------------------------------------------------------------- /app/config/config_prod.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config.yml } 3 | 4 | #framework: 5 | # validation: 6 | # cache: apc 7 | 8 | monolog: 9 | handlers: 10 | main: 11 | type: fingers_crossed 12 | action_level: error 13 | handler: nested 14 | nested: 15 | type: stream 16 | path: "%kernel.logs_dir%/%kernel.environment%.log" 17 | level: debug 18 | console: 19 | type: console 20 | -------------------------------------------------------------------------------- /app/config/config_test.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config_dev.yml } 3 | 4 | framework: 5 | test: ~ 6 | session: 7 | storage_id: session.storage.mock_file 8 | profiler: 9 | collect: false 10 | 11 | web_profiler: 12 | toolbar: false 13 | intercept_redirects: false 14 | -------------------------------------------------------------------------------- /app/config/parameters.yml.dist: -------------------------------------------------------------------------------- 1 | # This file is a "template" of what your parameters.yml file should look like 2 | parameters: 3 | locale: en 4 | 5 | # A secret key that's used to generate certain security-related tokens 6 | secret: ThisTokenIsNotSoSecretChangeIt 7 | 8 | mongo_database_server: mongodb://db:27017 9 | mongo_database_name: docker-symfony 10 | -------------------------------------------------------------------------------- /app/config/routing.yml: -------------------------------------------------------------------------------- 1 | api: 2 | resource: "@AppBundle/Resources/config/routing_api.yml" 3 | prefix: /api 4 | 5 | web: 6 | resource: "@AppBundle/Resources/config/routing_web.yml" 7 | prefix: / 8 | -------------------------------------------------------------------------------- /app/config/routing_dev.yml: -------------------------------------------------------------------------------- 1 | _wdt: 2 | resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" 3 | prefix: /_wdt 4 | 5 | _profiler: 6 | resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" 7 | prefix: /_profiler 8 | 9 | _configurator: 10 | resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml" 11 | prefix: /_configurator 12 | 13 | _errors: 14 | resource: "@TwigBundle/Resources/config/routing/errors.xml" 15 | prefix: /_error 16 | 17 | _main: 18 | resource: routing.yml 19 | -------------------------------------------------------------------------------- /app/config/security.yml: -------------------------------------------------------------------------------- 1 | security: 2 | providers: 3 | in_memory: 4 | memory: ~ 5 | 6 | firewalls: 7 | dev: 8 | pattern: ^/(_(profiler|wdt)|css|images|js)/ 9 | security: false 10 | 11 | default: 12 | anonymous: ~ 13 | -------------------------------------------------------------------------------- /app/config/services.yml: -------------------------------------------------------------------------------- 1 | # Learn more about services, parameters and containers at 2 | # http://symfony.com/doc/current/book/service_container.html 3 | parameters: 4 | # parameter_name: value 5 | 6 | services: 7 | # service_name: 8 | # class: AppBundle\Directory\ClassName 9 | # arguments: ["@another_service_name", "plain_value", "%parameter_name%"] 10 | -------------------------------------------------------------------------------- /app/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); 19 | $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; 20 | 21 | if ($debug) { 22 | Debug::enable(); 23 | } 24 | 25 | $kernel = new AppKernel($env, $debug); 26 | $application = new Application($kernel); 27 | $application->run($input); 28 | -------------------------------------------------------------------------------- /app/logs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/app/logs/.gitkeep -------------------------------------------------------------------------------- /app/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | ../src/*/*Bundle/Tests 13 | ../src/*/Bundle/*Bundle/Tests 14 | ../src/*Bundle/Tests 15 | 16 | 17 | 18 | 23 | 24 | 25 | 26 | ../src 27 | 28 | ../src/*/*Bundle/Resources 29 | ../src/*/*Bundle/Tests 30 | ../src/*/Bundle/*Bundle/Resources 31 | ../src/*/Bundle/*Bundle/Tests 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "symfony/framework-standard-edition", 3 | "license": "MIT", 4 | "type": "project", 5 | "description": "The \"Symfony Standard Edition\" distribution", 6 | "autoload": { 7 | "psr-0": { "": "src/", "SymfonyStandard": "app/" } 8 | }, 9 | "require": { 10 | "php": ">=5.3.3", 11 | "symfony/symfony": "2.8.*", 12 | "twig/extensions": "~1.0", 13 | "symfony/monolog-bundle": "~2.4", 14 | "sensio/distribution-bundle": "~3.0", 15 | "sensio/framework-extra-bundle": "~3.0", 16 | "incenteev/composer-parameter-handler": "~2.0", 17 | "doctrine/mongodb-odm": "1.0.*@dev", 18 | "doctrine/mongodb-odm-bundle": "3.0.*@dev", 19 | "friendsofsymfony/rest-bundle": "dev-master", 20 | "jms/serializer-bundle": "~1.1" 21 | }, 22 | "require-dev": { 23 | "sensio/generator-bundle": "~2.3", 24 | "phpspec/phpspec": "~2.0", 25 | "squizlabs/php_codesniffer": "1.*", 26 | "phing/phing": "2.*", 27 | "phpmd/phpmd": "dev-master", 28 | "sebastian/phpcpd": "*" 29 | }, 30 | "scripts": { 31 | "post-root-package-install": [ 32 | "SymfonyStandard\\Composer::hookRootPackageInstall" 33 | ], 34 | "post-install-cmd": [ 35 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 36 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 37 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 38 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 39 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 40 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles" 41 | ], 42 | "post-update-cmd": [ 43 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 44 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 45 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 46 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 47 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 48 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles" 49 | ] 50 | }, 51 | "config": { 52 | "bin-dir": "bin" 53 | }, 54 | "extra": { 55 | "symfony-app-dir": "app", 56 | "symfony-web-dir": "web", 57 | "symfony-assets-install": "relative", 58 | "incenteev-parameters": { 59 | "file": "app/config/parameters.yml" 60 | }, 61 | "branch-alias": { 62 | "dev-master": "2.6-dev" 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | docker tag sskorc/docker-symfony-dist:latest sskorc/docker-symfony-dist:$TRAVIS_BUILD_NUMBER 4 | 5 | docker push sskorc/docker-symfony-dist 6 | 7 | curl -u sskorc:$DOCKER_CLOUD_API_KEY -H "Content-Type: application/json" -X POST -d '{"reuse_volumes":false}' https://cloud.docker.com/api/app/v1/service/$PHP_SERVICE_UUID/redeploy/ 8 | -------------------------------------------------------------------------------- /docker-compose-remote.yml: -------------------------------------------------------------------------------- 1 | php: 2 | image: sskorc/docker-symfony-dist:latest 3 | links: 4 | - db 5 | volumes: 6 | - /var/www/docker-symfony 7 | nginx: 8 | image: nginx:1.9.10 9 | links: 10 | - php 11 | volumes_from: 12 | - php 13 | volumes: 14 | - ./docker/vhost.conf:/etc/nginx/conf.d/default.conf 15 | ports: 16 | - "80:80" 17 | db: 18 | image: mongo:3.2.1 19 | volumes: 20 | - /mnt/sda1/var/lib/mongo-data:/data/db 21 | ports: 22 | - "27017:27017" 23 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | php: 2 | build: . 3 | links: 4 | - db 5 | volumes: 6 | - .:/var/www/docker-symfony 7 | environment: 8 | XDEBUG_CONFIG: remote_host=192.168.99.1 9 | PHP_IDE_CONFIG: serverName=docker-symfony 10 | nginx: 11 | image: nginx:1.9.10 12 | links: 13 | - php 14 | volumes_from: 15 | - php 16 | volumes: 17 | - ./docker/vhost.conf:/etc/nginx/conf.d/default.conf 18 | ports: 19 | - "80:80" 20 | db: 21 | image: mongo:3.2.1 22 | volumes: 23 | - /mnt/sda1/var/lib/mongo-data:/data/db 24 | ports: 25 | - "27017:27017" 26 | -------------------------------------------------------------------------------- /docker/php.ini: -------------------------------------------------------------------------------- 1 | date.timezone = Europe/Warsaw 2 | short_open_tag = off 3 | 4 | xdebug.remote_enable = on 5 | xdebug.remote_connect_back = on 6 | xdebug.remote_autostart = on 7 | xdebug.remote_port = 9000 8 | xdebug.idekey = PHPSTORM 9 | -------------------------------------------------------------------------------- /docker/php.ini.remote: -------------------------------------------------------------------------------- 1 | date.timezone = Europe/Warsaw 2 | short_open_tag = off 3 | max_execution_time = 300 4 | memory_limit = 512M 5 | display_errors = off 6 | 7 | xdebug.default_enable = off 8 | xdebug.remote_autostart = off 9 | xdebug.remote_enable = off 10 | xdebug.profiler_enable = off 11 | -------------------------------------------------------------------------------- /docker/vhost.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | client_max_body_size 10M; 5 | client_body_buffer_size 128k; 6 | 7 | root /var/www/docker-symfony/web; 8 | 9 | location / { 10 | # try to serve file directly, fallback to app.php 11 | index app.php; 12 | try_files $uri /app.php$is_args$args; 13 | } 14 | # DEV 15 | # This rule should only be placed on your development environment 16 | # In production, don't include this and don't deploy app_dev.php or config.php 17 | location ~ ^/(app_dev|config)\.php(/|$) { 18 | fastcgi_pass php:9000; 19 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 20 | include fastcgi_params; 21 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 22 | fastcgi_read_timeout 120; 23 | } 24 | 25 | # PROD 26 | location ~ ^/app\.php(/|$) { 27 | fastcgi_pass php:9000; 28 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 29 | include fastcgi_params; 30 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 31 | fastcgi_read_timeout 120; 32 | # Prevents URIs that include the front controller. This will 404: 33 | # http://domain.tld/app.php/some-path 34 | # Remove the internal directive to allow URIs like this 35 | internal; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/images/xdebug/screen01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/docs/images/xdebug/screen01.png -------------------------------------------------------------------------------- /docs/images/xdebug/screen02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/docs/images/xdebug/screen02.png -------------------------------------------------------------------------------- /docs/images/xdebug/screen03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/docs/images/xdebug/screen03.png -------------------------------------------------------------------------------- /docs/xdebug.md: -------------------------------------------------------------------------------- 1 | # Debugging on Docker container with Xdebug in PHPStorm 2 | [Xdebug](https://xdebug.org/) is a very powerful tool to debug PHP applications in the IDE in a professional way. To 3 | make it work you need configure Xdebug extension on the machine (container) you run your PHP app and then configure your 4 | IDE on the host machine. Here's the "step-by-step" instruction that can help you doing it. 5 | 6 | ## Remote configuration 7 | First, you need to configure the `php` Docker container to use Xdebug. This repo has already done and ready 8 | configuration of the container to run Xdebug. It consists of: 9 | 10 | 1. Xdebug installation in the `Dockerfile`. 11 | 2. Xdebug configuration in the `php.ini` file. 12 | 3. Further Xdebug configuration in the `docker-compose.yml` file (two environment variables for `php` container). 13 | 14 | ## Local configuration 15 | Disclaimer: this instruction was tested on Mac OS X with Docker Machine, VirtualBox and PHPStorm 10. 16 | 17 | ### 1. Set the IP address of your host 18 | 19 | First, you need to set the IP address of your host machine in the `docker-compose.yml` file: 20 | 21 | ``` 22 | XDEBUG_CONFIG: remote_host=192.168.99.1 23 | ``` 24 | 25 | You need to restart the environment (`docker-compose restart -d`) to apply the change. 26 | 27 | This IP should be visible from the container. The actual IP and the way to retrieve it depends on the OS you use as the 28 | host as well as a type virtualization you use to run Docker Engine (if you use any). 29 | 30 | Assuming you use Mac OS X and you have Docker Machine with VirtualBox to run Docker Engine, you can check the IP using 31 | `ifconfig` command. The IP you're looking for is define in one of the `vboxnet` interfaces. If you're not sure which 32 | interface is used by the virtual machine, you can find it out in VirtualBox GUI: 33 | 34 | 1. Select "Setting" (⌘S on Mac OS X) your Docker Machine 35 | 2. Go to "Network" 36 | 3. On the list of adapters, look for "Host-only adapter" 37 | 4. The name of the interface should be right below: 38 | ![VirtualBox screenshot](images/xdebug/screen01.png) 39 | 40 | ### 2. Adjust remote server configuration in PHPStorm 41 | 42 | In PHPStorm go to Preferences (⌘, on Mac OS X), open "Languages & Frameworks > PHP > Servers" and add new server 43 | configuration. The name of the server should be "docker-symfony" (you can set any name you want, but remember to use the 44 | same name in the `docker-compose.yml` file) and the host should be `docker-symfony.dev`. You need to also prepare valid 45 | file mappings configuration. The directory of the repo should map `/var/www/docker-symfony` directory on the server. 46 | 47 | ![PHPStorm screenshot](images/xdebug/screen02.png) 48 | 49 | ### 3. Enable PHP debug connection in PHPStorm 50 | 51 | In PHPStorm click the icon with a phone handset - this starts/stops listening for PHP debug connections. This should be 52 | in "started" status: 53 | 54 | ![Handset icon](images/xdebug/screen03.png) 55 | 56 | ### 4. Debug! 57 | Place a breakpoint somewhere in the code and then use the app. You can open it in the browser, call REST API, use 58 | Symfony CLI command or run PHPSpec - Xdebug should work for any of the app's endpoints. 59 | -------------------------------------------------------------------------------- /spec/Domain/UseCase/AddTaskSpec.php: -------------------------------------------------------------------------------- 1 | beConstructedWith($taskRepository); 17 | } 18 | 19 | function it_should_add_task(TaskRepository $taskRepository, Responder $responder) 20 | { 21 | $name = 'Dummy task'; 22 | 23 | $this->execute(new Command($name), $responder); 24 | 25 | $taskRepository->add(Argument::type(Task::class))->shouldHaveBeenCalled(); 26 | $responder->taskSuccessfullyAdded(Argument::type(Task::class))->shouldHaveBeenCalled(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spec/Domain/UseCase/ListTasksSpec.php: -------------------------------------------------------------------------------- 1 | beConstructedWith($taskRepository); 17 | } 18 | 19 | function it_should_list_tasks(TaskRepository $taskRepository, Task $task, Responder $responder) 20 | { 21 | $tasks = array($task); 22 | $taskRepository->findAll()->willReturn($tasks); 23 | 24 | $this->execute(new Command(), $responder); 25 | 26 | $responder->tasksSuccessfullyFound($tasks)->shouldHaveBeenCalled(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Order deny,allow 6 | Deny from all 7 | 8 | -------------------------------------------------------------------------------- /src/AppBundle/AppBundle.php: -------------------------------------------------------------------------------- 1 | setName('task:add') 22 | ->setDescription('Add new task') 23 | ->addArgument( 24 | 'name', 25 | InputArgument::REQUIRED, 26 | 'What\'s the task?' 27 | ) 28 | ; 29 | } 30 | 31 | /** {@inheritdoc} */ 32 | protected function execute(InputInterface $input, OutputInterface $output) 33 | { 34 | $name = $input->getArgument('name'); 35 | 36 | $useCase = $this->getContainer()->get('use_case.add_task'); 37 | 38 | $useCase->execute(new AddTask\Command($name), $this); 39 | 40 | if (!empty($this->task)) { 41 | $message = sprintf('Task "%s" was added', $this->task->getName()); 42 | } else { 43 | $message = 'Task wasn\'t added'; 44 | } 45 | 46 | $output->writeln($message); 47 | } 48 | 49 | /** {@inheritdoc} */ 50 | public function taskSuccessfullyAdded(Task $task) 51 | { 52 | $this->task = $task; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/REST/Task/AddController.php: -------------------------------------------------------------------------------- 1 | get('name'); 24 | 25 | if (empty($name)) { 26 | throw new HttpException(400, 'Missing required parameters'); 27 | } 28 | 29 | $useCase = $this->get('use_case.add_task'); 30 | 31 | $useCase->execute(new AddTask\Command($name), $this); 32 | 33 | $view = $this->view($this->task, 201); 34 | 35 | return $this->handleView($view); 36 | } 37 | 38 | /** {@inheritdoc} */ 39 | public function taskSuccessfullyAdded(Task $task) 40 | { 41 | $this->task = $task; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/REST/Task/ListController.php: -------------------------------------------------------------------------------- 1 | tasks = array(); 17 | } 18 | 19 | /** 20 | * @return \Symfony\Component\HttpFoundation\Response 21 | */ 22 | public function executeAction() 23 | { 24 | $useCase = $this->get('use_case.list_tasks'); 25 | 26 | $useCase->execute(new ListTasks\Command(), $this); 27 | 28 | $view = $this->view($this->tasks, 200); 29 | 30 | return $this->handleView($view); 31 | } 32 | 33 | /** {@inheritdoc} */ 34 | public function tasksSuccessfullyFound($tasks) 35 | { 36 | $this->tasks = $tasks; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/Web/Task/AddController.php: -------------------------------------------------------------------------------- 1 | createForm(TaskType::class); 27 | 28 | $form->handleRequest($request); 29 | 30 | $this->request = $request; 31 | $this->response = $this->render(':Tasks:add.html.twig', ['form' => $form->createView()]); 32 | 33 | if ($form->isValid()) { 34 | $data = $form->getData(); 35 | $name = $data['name']; 36 | 37 | $useCase = $this->get('use_case.add_task'); 38 | 39 | $useCase->execute(new AddTask\Command($name), $this); 40 | } 41 | 42 | return $this->response; 43 | } 44 | 45 | /** {@inheritdoc} */ 46 | public function taskSuccessfullyAdded(Task $task) 47 | { 48 | $this->request->getSession()->getFlashbag()->add( 49 | 'success', 50 | sprintf('Task "%s" successfully created', $task->getName()) 51 | ); 52 | $this->response = $this->redirectToRoute('web_tasks_list'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/Web/Task/ListController.php: -------------------------------------------------------------------------------- 1 | tasks = array(); 17 | } 18 | 19 | /** 20 | * @return \Symfony\Component\HttpFoundation\Response 21 | */ 22 | public function executeAction() 23 | { 24 | $useCase = $this->get('use_case.list_tasks'); 25 | 26 | $useCase->execute(new ListTasks\Command(), $this); 27 | 28 | return $this->render(':Tasks:list.html.twig', ['tasks' => $this->tasks]); 29 | } 30 | 31 | /** {@inheritdoc} */ 32 | public function tasksSuccessfullyFound($tasks) 33 | { 34 | $this->tasks = $tasks; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/AppBundle/DependencyInjection/AppExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 24 | 25 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 26 | $loader->load('services.yml'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/AppBundle/DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('app'); 17 | 18 | // Here you should define the parameters that are allowed to 19 | // configure your bundle. See the documentation linked above for 20 | // more information on that topic. 21 | 22 | return $treeBuilder; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/AppBundle/Form/Type/TaskType.php: -------------------------------------------------------------------------------- 1 | add('name'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/AppBundle/Resources/config/routing_api.yml: -------------------------------------------------------------------------------- 1 | api_tasks_list: 2 | path: /tasks.{_format} 3 | methods: [GET] 4 | requirements: 5 | _format: json|xml 6 | defaults: 7 | _format: json 8 | _controller: AppBundle:REST/Task/List:execute 9 | 10 | api_tasks_add: 11 | path: /tasks.{_format} 12 | methods: [POST] 13 | requirements: 14 | _format: json|xml 15 | defaults: 16 | _format: json 17 | _controller: AppBundle:REST/Task/Add:execute 18 | -------------------------------------------------------------------------------- /src/AppBundle/Resources/config/routing_web.yml: -------------------------------------------------------------------------------- 1 | web_homepage: 2 | path: / 3 | defaults: 4 | _controller: FrameworkBundle:Redirect:redirect 5 | route: web_tasks_list 6 | permanent: true 7 | 8 | web_tasks_list: 9 | path: /tasks 10 | defaults: { _controller: AppBundle:Web/Task/List:execute } 11 | 12 | web_tasks_add: 13 | path: /tasks/add 14 | defaults: { _controller: AppBundle:Web/Task/Add:execute } 15 | -------------------------------------------------------------------------------- /src/AppBundle/Resources/config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | repository.task: 3 | class: Infrastructure\ODM\ODMTaskRepository 4 | arguments: [@doctrine.odm.mongodb.document_manager] 5 | use_case.add_task: 6 | class: Domain\UseCase\AddTask 7 | arguments: [@repository.task] 8 | use_case.list_tasks: 9 | class: Domain\UseCase\ListTasks 10 | arguments: [@repository.task] 11 | -------------------------------------------------------------------------------- /src/Domain/Entity/Task.php: -------------------------------------------------------------------------------- 1 | name = $name; 22 | $this->createdAt = new \DateTime(); 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getId() 29 | { 30 | return $this->id; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getName() 37 | { 38 | return $this->name; 39 | } 40 | 41 | /** 42 | * @return \DateTime 43 | */ 44 | public function getCreatedAt() 45 | { 46 | return $this->createdAt; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Domain/Repository/TaskRepository.php: -------------------------------------------------------------------------------- 1 | taskRepository = $taskRepository; 21 | } 22 | 23 | /** 24 | * @param \Domain\UseCase\AddTask\Command $command 25 | * @param \Domain\UseCase\AddTask\Responder $responder 26 | */ 27 | public function execute(Command $command, Responder $responder) 28 | { 29 | $task = new Task($command->name); 30 | 31 | $this->taskRepository->add($task); 32 | 33 | $responder->taskSuccessfullyAdded($task); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Domain/UseCase/AddTask/Command.php: -------------------------------------------------------------------------------- 1 | name = $name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Domain/UseCase/AddTask/Responder.php: -------------------------------------------------------------------------------- 1 | taskRepository = $taskRepository; 20 | } 21 | 22 | /** 23 | * @param \Domain\UseCase\ListTasks\Command $command 24 | * @param \Domain\UseCase\ListTasks\Responder $responder 25 | */ 26 | public function execute(Command $command, Responder $responder) 27 | { 28 | $buyers = $this->taskRepository->findAll(); 29 | 30 | $responder->tasksSuccessfullyFound($buyers); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Domain/UseCase/ListTasks/Command.php: -------------------------------------------------------------------------------- 1 | manager = $manager; 20 | } 21 | 22 | /** {@inheritdoc} */ 23 | public function findAll() 24 | { 25 | return $this->manager->getRepository(Task::class)->findAll(); 26 | } 27 | 28 | /** {@inheritdoc} */ 29 | public function add(Task $task) 30 | { 31 | $this->manager->persist($task); 32 | $this->manager->flush(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /startup.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cd /var/www/docker-symfony 4 | 5 | composer install -n --optimize-autoloader 6 | 7 | php app/console cache:clear --env=prod --no-debug 8 | 9 | chown -R www-data:www-data /tmp/sf2 && chmod -R 770 /tmp/sf2 10 | -------------------------------------------------------------------------------- /web/.htaccess: -------------------------------------------------------------------------------- 1 | # Use the front controller as index file. It serves as a fallback solution when 2 | # every other rewrite/redirect fails (e.g. in an aliased environment without 3 | # mod_rewrite). Additionally, this reduces the matching process for the 4 | # start page (path "/") because otherwise Apache will apply the rewriting rules 5 | # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). 6 | DirectoryIndex app.php 7 | 8 | 9 | RewriteEngine On 10 | 11 | # Determine the RewriteBase automatically and set it as environment variable. 12 | # If you are using Apache aliases to do mass virtual hosting or installed the 13 | # project in a subdirectory, the base path will be prepended to allow proper 14 | # resolution of the app.php file and to redirect to the correct URI. It will 15 | # work in environments without path prefix as well, providing a safe, one-size 16 | # fits all solution. But as you do not need it in this case, you can comment 17 | # the following 2 lines to eliminate the overhead. 18 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 19 | RewriteRule ^(.*) - [E=BASE:%1] 20 | 21 | # Sets the HTTP_AUTHORIZATION header removed by apache 22 | RewriteCond %{HTTP:Authorization} . 23 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 24 | 25 | # Redirect to URI without front controller to prevent duplicate content 26 | # (with and without `/app.php`). Only do this redirect on the initial 27 | # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 28 | # endless redirect loop (request -> rewrite to front controller -> 29 | # redirect -> request -> ...). 30 | # So in case you get a "too many redirects" error or you always get redirected 31 | # to the start page because your Apache does not expose the REDIRECT_STATUS 32 | # environment variable, you have 2 choices: 33 | # - disable this feature by commenting the following 2 lines or 34 | # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 35 | # following RewriteCond (best solution) 36 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ 37 | RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 38 | 39 | # If the requested filename exists, simply serve it. 40 | # We only want to let Apache serve files and not directories. 41 | RewriteCond %{REQUEST_FILENAME} -f 42 | RewriteRule .? - [L] 43 | 44 | # Rewrite all other queries to the front controller. 45 | RewriteRule .? %{ENV:BASE}/app.php [L] 46 | 47 | 48 | 49 | 50 | # When mod_rewrite is not available, we instruct a temporary redirect of 51 | # the start page to the front controller explicitly so that the website 52 | # and the generated links can still be used. 53 | RedirectMatch 302 ^/$ /app.php/ 54 | # RedirectTemp cannot be used instead 55 | 56 | 57 | -------------------------------------------------------------------------------- /web/app.php: -------------------------------------------------------------------------------- 1 | unregister(); 15 | $apcLoader->register(true); 16 | */ 17 | 18 | require_once __DIR__.'/../app/AppKernel.php'; 19 | //require_once __DIR__.'/../app/AppCache.php'; 20 | 21 | $kernel = new AppKernel('prod', false); 22 | $kernel->loadClassCache(); 23 | //$kernel = new AppCache($kernel); 24 | 25 | // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter 26 | //Request::enableHttpMethodParameterOverride(); 27 | $request = Request::createFromGlobals(); 28 | $response = $kernel->handle($request); 29 | $response->send(); 30 | $kernel->terminate($request, $response); 31 | -------------------------------------------------------------------------------- /web/app_dev.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 17 | $request = Request::createFromGlobals(); 18 | $response = $kernel->handle($request); 19 | $response->send(); 20 | $kernel->terminate($request, $response); 21 | -------------------------------------------------------------------------------- /web/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/web/apple-touch-icon.png -------------------------------------------------------------------------------- /web/config.php: -------------------------------------------------------------------------------- 1 | getFailedRequirements(); 20 | $minorProblems = $symfonyRequirements->getFailedRecommendations(); 21 | 22 | ?> 23 | 24 | 25 | 26 | 27 | 28 | Symfony Configuration 29 | 30 | 31 | 32 | 33 | 34 |
35 |
36 | 39 | 40 | 60 |
61 | 62 |
63 |
64 |
65 |

Welcome!

66 |

Welcome to your new Symfony project.

67 |

68 | This script will guide you through the basic configuration of your project. 69 | You can also do the same by editing the ‘app/config/parameters.yml’ file directly. 70 |

71 | 72 | 73 |

Major problems

74 |

Major problems have been detected and must be fixed before continuing:

75 |
    76 | 77 |
  1. getHelpHtml() ?>
  2. 78 | 79 |
80 | 81 | 82 | 83 |

Recommendations

84 |

85 | Additionally, toTo enhance your Symfony experience, 86 | it’s recommended that you fix the following: 87 |

88 |
    89 | 90 |
  1. getHelpHtml() ?>
  2. 91 | 92 |
93 | 94 | 95 | hasPhpIniConfigIssue()): ?> 96 |

* 97 | getPhpIniConfigPath()): ?> 98 | Changes to the php.ini file must be done in "getPhpIniConfigPath() ?>". 99 | 100 | To change settings, create a "php.ini". 101 | 102 |

103 | 104 | 105 | 106 |

Your configuration looks good to run Symfony.

107 | 108 | 109 | 118 |
119 |
120 |
121 |
Symfony Standard Edition
122 |
123 | 124 | 125 | -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sskorc/docker-symfony/b2ab5d22ea260fff8a5d2159a6c3a8564fb2722a/web/favicon.ico -------------------------------------------------------------------------------- /web/info.php: -------------------------------------------------------------------------------- 1 |