5 min. read
Categories: Ecosystem Technical
Monofony, a Symfony booster based on Sylius internals
This article assumes that you already have Sylius knowledge. To learn more, read the docs.
Monofony, a Symfony booster based on Sylius internals

This is the first of the series of guest posts we would like to share with you on our blog. We have an amazing Community of active Sylius users who can describe the power of our technology in live cases. Our product’s decoupled architecture allows for not only standard eCommerce implementations but also provides a framework for various Symfony projects based on Sylius standalone components.

So, for starters – read about “Monofony” – Symfony starter developed by Loïc Frémont!

This article assumes that you already have Sylius knowledge. To learn more, read the docs.

Project concept

Used to start projects from scratch and add all dependencies step by step? If yes, you probably spend a lot of time setting everything up.

Within this starter, you have a pretty similar development environment to Sylius, but without the e-commerce part.

This project has a branch “example/managing-articles”  as an example for all usages of this starter. All examples in this blog post can also be found in this branch.

Monofony also contains basic features like customer login, customer registration, forgotten password, user’s profile, customers and administrators management…

 

You can fork the whole project starter on github or just copy parts of it.

Project birth

Monofony was called “Polyfony” at first. It was a Symfony starter for all projects in my company Mobizel when I joined it in 2015.

My co-worker Laurent Bay discovered this amazing e-commerce framework on Symfony years ago (around 2014). He started to use it for an e-commerce project when Sylius was in the pre-alpha development phase. He was very enthusiastic about it and even made some contributions.

Enjoying so much the ResourceBundle, we started to include it in all of our Symfony projects.

During this period, I forked our project starter and wrote only one bundle following best practices of Symfony in this period and re-called this project “Monofony” cause it has one “Mono Bundle”.

With our Sylius experience during developments and contributions, we added some Sylius features step by step in our projects.

We added the User Bundle to handle users and customers (it was in Sylius/UserBundle at the beginning).

At December 2016, I tried the Grid Bundle in a project and started to use it on our Symfony starter. Coupling it with the Ui Bundle (which is part of Sylius stack now), you can have an awesome administration.

Make it as an open-source Symfony starter

In order to share this Symfony starter with ex-coworkers, I have moved it to a public repository to GitHub.

It’s now an open-source project with MIT license (same as Sylius). But it’s only the beginning and you can contribute to improve this starter!

Architecture

Sylius bundles

Monofony uses:

Sylius BDD methodology

With Monofony/SymfonyStarter, you can use the Behaviour-Driven-Development methodology with:

Datafixtures

Monofony uses Sylius/FixturesBundle to write your datafixtures. It contains a yaml file to configure all your data fixtures. You just have to write two services in Fixture folder.

Travis CI

It contains a copy of the Sylius Travis configuration but you can easily switch to another CI.

Monofony validates composer file, phpspec, behat, infection etc…

Documentation

Like Sylius, it has a docs folder which contains the first step to build your whole project documentation. It uses sphinx-doc and the Sylius theme.

If you have contributed to Sylius documentation, you’ll enjoy this part.

Starting your project

Installation step

You can follow installation on its readme.

Configure your first resource

To manage an entity with Sylius/ResourceBundle, you just have to:

 

Let’s configure an article entity as an example.

src/Entity/Article.php

You now have to add it on Sylius Resource configuration.

 

config/packages/sylius_resources.yml

You can learn more from Sylius Resource Bundle documentation.

Manage your new entity on the admin panel

To have an administration like this, you just have to configure a new grid and configure its routes.

Configure a new grid

To add a new grid, create a new grid configuration file in this grids folder and import this to sylius_grid configuration file.

 

So, let’s configure “Article” grid!

 

config/packages/grids/backend/article.yml

config/packages/sylius_grid.yaml

You can learn more about configuring a grid in Sylius documentation.

Configure backend routes

To configure backend routes for your entity, you have to create a new file on backend routes folder.

 

Let’s configure our “Article” routes as an example.

 

config/routes/backend/article.yml

And add it on backend routes configuration.

And that’s all!

 

You can learn more about configuring routes in Sylius documentation.

Showcase

As an example of a project started with Monofony, let me introduce the Jedisjeux project.

It’s a French website about board games. It uses more Sylius bundles than Monofony, such as product bundle (a board game is a product resource). This project is also open-source and you can explore its source code on GitHub. Just have a look at its composer file to see the impressive list of Sylius bundles it uses.

Advantages

  • Starting a new project is much faster
  • It includes some ready to use features like login, registration, customer account
  • Following best practices with a strong Behaviour-Driven Development pre-configured

Disadvantages

  • A starter comes with its own best practices (here it uses annotations for Doctrine, serialization and assertions and it uses translations in yaml files).
  • Removing some parts you don’t need could take much time and you often keep useless code.

 

Thanks

Thanks to everybody at Mobizel who contributed or helped to this project: Laurent Baey, Corentin Nicole, Kevin Regnier and Pierre Brun.

Thanks to Tymoteusz Stengert and Łukasz Chruściel starting this promising series of guest posts.

 

Creating your own Sylius-based OS project?

If you like this article and you are also working on some Sylius-based project, contact us! We will be glad to share any article about live use cases of Sylius bundles in your Symfony apps.

 

Cheers!

Share:
More from our blog
Technical 5 min read 04.12.2024
Here’s everything you had to know about the first major release since 2017! Over 7 years after the first major release, on Nov 12, 2024, we have released Sylius 2.0.0. We had a great opportunity to announce it first at SyliusCon in Lyon, but now, as we are back to… Read More
5 min read 22.11.2024
The emotions start to settle after SyliusCon, and it’s time to reflect on this incredible milestone in our journey. Why a milestone? Because SyliusCon exceeded our expectations in every possible way. We broke attendance records and brought together the key figures of our community, numerous partners, freelancers, and simply all… Read More
Cloud 5 min read 17.06.2024
We are thrilled to announce that we just signed a strategic partnership with Platform.sh, and as a result, we are extending our offer with Sylius Cloud powered by Platform.sh. Platform.sh is a modern Platform-as-a-Service (PaaS) solution that allows businesses to leverage the cloud environment without losing access to the code… Read More
Comments