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
Business News Technical 5 min read 28.09.2020
Get ready for global sales & operations with the most advanced payment solution from the famous fintech giant, now available in Sylius out of the box. Read More
Business News 5 min read 14.09.2020
We proudly present to you the latest version of the Sylius eCommerce Platform – 1.8, which comes with a brand new, unified API powered by API Platform, Loyalty points system for Sylius Plus, and as you can probably see, a brand new sylius.com website! Numbers This new release is a… Read More
Business Ecosystem News 5 min read 13.08.2020
Read why the French market leader trusted Sylius in a strategic re-platforming process to get a competitive eCommerce advantage. Read More
Comments