phparchitect-2019-08

(Rick Simeone) #1
6 \ August 2019 \ http://www.phparch.com

Symfony 4: A New Way to Develop Applications

Once you complete the installation of the Symfony client,
you can run it by typing symfony in a terminal or console. You
should see something like Figure 3.
You can use symfony new project_name to start a new
project with a skeleton version, or you can use the following
command to start the Symfony demo version.

symfony new --demo project_name

Here you can do research and play around to get familiar
with best practices and concepts in Symfony 4. If you want to
start the traditional web app previously known as Symfony
Standard distribution, you can use:

symfony new --full project_name

I suggest you start with the skeleton version, even if you
are building a traditional web application—remember, you
want to use composition, not inheritance. As a developer, you
should care about your stack/framework and the components
you are using. You should know them well and be aware of
their existence. I am sure if you go with the traditional web
edition you will never check what you have in the vendors
folder.
Type in a terminal:

symfony new phparc_project

As you can see in Figure 4, the Symfony client uses
Composer to start a new project and sets up a Git repository
inside your project automatically. You get 19 packages inside
this version, that includes only basic things you need to start
any type of project (console application, microservices, APIs,
etc.) If we compare this to the Symfony 2 or 3 standard distri-
bution which had more than 70 components, we can see a
huge step forward.
The next thing we want to use is the built-in server^13 in
the Symfony client. Go to your project folder and type in a
terminal:

symfony serve

As you can see from Figure 5, we started the webserver
(also note that you can use the Symfony client for running
server with TLS support, but we don’t need it for this article)
listening on http://127.0.0.1:8000.
Go to the address, and you should see a basic landing page
(Figure 6), as we don’t have any other action configured for
homepage route.
Also, if you check the console, you can see an error listed in
the log. It is one more handy feature from the Symfony client.
It parses logs and shows well-formatted messages saving you
a lot of time. Even if you are using another web server, you
can use this feature to get pretty Symfony logs; in the terminal
write:


13 built-in server: https://phpa.me/symfony-web-server


symfony server:log \--file=/path+to/var/log/dev.log

Even this small and handy feature is a good reason to down-
load and install Symfony client. Keep in mind that Symfony
Client is a potent tool, and be sure to take some time to
research it a little bit. There is an amazing video on this topic
from SymfonyCon in Lisbon^14 delivered by Fabien Potencier.
Also, if you run bin/console debug:container, notice that
the number of existing services in the container is much
lower than in previous versions.

14 SymfonyCon in Lisbon: https://phpa.me/symfonycasts-basics

Figure 3

Figure 4

Figure 5

Figure 6
Free download pdf