Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
# laminas-mvc-skeleton
2
 
3
## Introduction
4
 
5
This is a skeleton application using the Laminas MVC layer and module
6
systems. This application is meant to be used as a starting place for those
7
looking to get their feet wet with Laminas MVC.
8
 
9
## Installation using Composer
10
 
11
The easiest way to create a new Laminas MVC project is to use
12
[Composer](https://getcomposer.org/). If you don't have it already installed,
13
then please install as per the [documentation](https://getcomposer.org/doc/00-intro.md).
14
 
15
To create your new Laminas MVC project:
16
 
17
```bash
18
$ composer create-project -sdev laminas/laminas-mvc-skeleton path/to/install
19
```
20
 
21
Once installed, you can test it out immediately using PHP's built-in web server:
22
 
23
```bash
24
$ cd path/to/install
25
$ php -S 0.0.0.0:8080 -t public
26
# OR use the composer alias:
27
$ composer run --timeout 0 serve
28
```
29
 
30
This will start the cli-server on port 8080, and bind it to all network
31
interfaces. You can then visit the site at http://localhost:8080/
32
- which will bring up Zend Framework welcome page.
33
 
34
**Note:** The built-in CLI server is *for development only*.
35
 
36
## Development mode
37
 
38
The skeleton ships with [laminas-development-mode](https://github.com/laminas/laminas-development-mode)
39
by default, and provides three aliases for consuming the script it ships with:
40
 
41
```bash
42
$ composer development-enable  # enable development mode
43
$ composer development-disable # disable development mode
44
$ composer development-status  # whether or not development mode is enabled
45
```
46
 
47
You may provide development-only modules and bootstrap-level configuration in
48
`config/development.config.php.dist`, and development-only application
49
configuration in `config/autoload/development.local.php.dist`. Enabling
50
development mode will copy these files to versions removing the `.dist` suffix,
51
while disabling development mode will remove those copies.
52
 
53
Development mode is automatically enabled as part of the skeleton installation process.
54
After making changes to one of the above-mentioned `.dist` configuration files you will
55
either need to disable then enable development mode for the changes to take effect,
56
or manually make matching updates to the `.dist`-less copies of those files.
57
 
58
## Running Unit Tests
59
 
60
To run the supplied skeleton unit tests, you need to do one of the following:
61
 
62
- During initial project creation, select to install the MVC testing support.
63
- After initial project creation, install [laminas-test](https://docs.laminas.dev/laminas-test/):
64
 
65
  ```bash
66
  $ composer require --dev laminas/laminas-test
67
  ```
68
 
69
Once testing support is present, you can run the tests using:
70
 
71
```bash
72
$ ./vendor/bin/phpunit
73
```
74
 
75
If you need to make local modifications for the PHPUnit test setup, copy
76
`phpunit.xml.dist` to `phpunit.xml` and edit the new file; the latter has
77
precedence over the former when running tests, and is ignored by version
78
control. (If you want to make the modifications permanent, edit the
79
`phpunit.xml.dist` file.)
80
 
81
## Using Vagrant
82
 
83
This skeleton includes a `Vagrantfile` based on ubuntu 18.04 (bento box)
84
with configured Apache2 and PHP 7.3. Start it up using:
85
 
86
```bash
87
$ vagrant up
88
```
89
 
90
Once built, you can also run composer within the box. For example, the following
91
will install dependencies:
92
 
93
```bash
94
$ vagrant ssh -c 'composer install'
95
```
96
 
97
While this will update them:
98
 
99
```bash
100
$ vagrant ssh -c 'composer update'
101
```
102
 
103
While running, Vagrant maps your host port 8080 to port 80 on the virtual
104
machine; you can visit the site at http://localhost:8080/
105
 
106
> ### Vagrant and VirtualBox
107
>
108
> The vagrant image is based on bento/ubuntu-18.04. If you are using VirtualBox as
109
> a provider, you will need:
110
>
111
> - Vagrant 2.2.6 or later
112
> - VirtualBox 6.0.14 or later
113
 
114
For vagrant documentation, please refer to [vagrantup.com](https://www.vagrantup.com/)
115
 
116
## Using docker-compose
117
 
118
This skeleton provides a `docker-compose.yml` for use with
119
[docker-compose](https://docs.docker.com/compose/); it
120
uses the `Dockerfile` provided as its base. Build and start the image using:
121
 
122
```bash
123
$ docker-compose up -d --build
124
```
125
 
126
At this point, you can visit http://localhost:8080 to see the site running.
127
 
128
You can also run composer from the image. The container environment is named
129
"laminas", so you will pass that value to `docker-compose run`:
130
 
131
```bash
132
$ docker-compose run laminas composer install
133
```
134
 
135
## Web server setup
136
 
137
### Apache setup
138
 
139
To setup apache, setup a virtual host to point to the public/ directory of the
140
project and you should be ready to go! It should look something like below:
141
 
142
```apache
143
<VirtualHost *:80>
144
    ServerName laminasapp.localhost
145
    DocumentRoot /path/to/laminasapp/public
146
    <Directory /path/to/laminasapp/public>
147
        DirectoryIndex index.php
148
        AllowOverride All
149
        Order allow,deny
150
        Allow from all
151
        <IfModule mod_authz_core.c>
152
        Require all granted
153
        </IfModule>
154
    </Directory>
155
</VirtualHost>
156
```
157
 
158
### Nginx setup
159
 
160
To setup nginx, open your `/path/to/nginx/nginx.conf` and add an
161
[include directive](http://nginx.org/en/docs/ngx_core_module.html#include) below
162
into `http` block if it does not already exist:
163
 
164
```nginx
165
http {
166
    # ...
167
    include sites-enabled/*.conf;
168
}
169
```
170
 
171
 
172
Create a virtual host configuration file for your project under `/path/to/nginx/sites-enabled/laminasapp.localhost.conf`
173
it should look something like below:
174
 
175
```nginx
176
server {
177
    listen       80;
178
    server_name  laminasapp.localhost;
179
    root         /path/to/laminasapp/public;
180
 
181
    location / {
182
        index index.php;
183
        try_files $uri $uri/ @php;
184
    }
185
 
186
    location @php {
187
        # Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000
188
        fastcgi_pass   127.0.0.1:9000;
189
        fastcgi_param  SCRIPT_FILENAME /path/to/laminasapp/public/index.php;
190
        include fastcgi_params;
191
    }
192
}
193
```
194
 
195
Restart the nginx, now you should be ready to go!
196
 
197
## QA Tools
198
 
199
The skeleton does not come with any QA tooling by default, but does ship with
200
configuration for each of:
201
 
202
- [phpcs](https://github.com/squizlabs/php_codesniffer)
203
- [phpunit](https://phpunit.de)
204
 
205
Additionally, it comes with some basic tests for the shipped
206
`Application\Controller\IndexController`.
207
 
208
If you want to add these QA tools, execute the following:
209
 
210
```bash
211
$ composer require --dev phpunit/phpunit squizlabs/php_codesniffer zendframework/zend-test
212
```
213
 
214
We provide aliases for each of these tools in the Composer configuration:
215
 
216
```bash
217
# Run CS checks:
218
$ composer cs-check
219
# Fix CS errors:
220
$ composer cs-fix
221
# Run PHPUnit tests:
222
$ composer test
223
```