File hierarchy
We now have a freshly installed Vitya application template. A bunch of directories and files
have been created during the installation process. Your my-new-project/
directory should
look like this:
|
+-- cli/
| |
| +-- post-create-project/
| +-- router.php
| +-- server
| +-- server.php
| +-- vitya
| +-- vitya.php
|
+-- private/
| |
| +-- app/
| | |
| | +-- config/
| | +-- src/
| | +-- views/
| | +-- bootstrap.php
| | +-- routes.json
| |
| +-- cache/
| +-- data/
| +-- log/
| +-- sessions/
| +-- tmp/
|
+-- web/
| |
| +-- index.php
|
+-- .gitignore
+-- composer.json
+-- composer.lock
That’s a lot of stuff! Let’s explore the top level first:
cli/
mostly contains executable files. As you probably guessed, this is where you’ll find all the command line utilities, such as theserver
command which you have just used to start the built-in web server.private/
contains… well, basically, your whole application. All your classes, controllers, views, PHP dependencies, config files will sit somewhere inside this directory.web/
is the web root directory. This is the location you’ll pass to theroot
directive in your Nginx config file, or theDirectoryRoot
directive if you use Apache. It containsindex.php
, aka the front controller, aka the script to which every URL must be redirected.The
.gitignore
file specifies which files can be ignored when versioning your application. So, once your application template is installed, just typegit init
and relax. We tried to make the versioning process as effortless as possible. Everything that needs to be present in your repository will be there, and the rest will be excluded.The
composer.json
andcomposer.lock
files are used by the composer utility to describe all your application dependencies.
cli/
(the command line stuff)
cli/post-create-project/
is only used by composer during the installation process. In fact, you can safely delete this directory once the installation is completed.The
server
command will start the built-in web server. It requires theserver.php
androuter.php
files to work properly.vitya
is the main utility command. Don’t worry too much about it now, we shall see how to use it really soon!
private/
(99% of your app probably reside here)
The private/
directory really contains most of the files that compose your application. This could be
a good way to think about the top-level directories:
private/
is the application.cli/
is an entry point when using the application with the command line.web/
is an entry point when using the application with a web browser.
app/
This is where your own code will reside. As a rule of thumb, if you find yourself writing code outside of this directory, you are probably doing something wrong.
config/
: your config files. Yup.src/
: your PHP classes. Your mdels and controllers will go there.views/
: your views (probably Twig templates).bootstrap.php
: this file will instantiate and return aVitya\Application\Application
object, the service container that constitutes the very heart of your application.routes.json
: a file describing the routes of your application.
cache/
, data/
, log/
, sessions/
, tmp/
You can probably guess what these are used for. Later in this tutorial, we’ll explain more precisely how they work.
web/
(the entry point for your web server)
Your web server (Nginx, Apache or the built-in server) will use this as a root directory. In other words, you can put there static assets such as images or CSS files, and they will be served directly by the web server.
It also contains the essential index.php
file. Every URL that do not correspond to a static file should be
redirected to this script so that it’s handled by Vitya.