Download the PHP package verclam/smart-fetch-bundle without Composer

On this page you can find all versions of the php package verclam/smart-fetch-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smart-fetch-bundle

Intro to Verclam/Smart-Fetch-Bundle

Enhance your project performance by avoiding N+1 queries with Smart Fetch Bundle.

Latest updates

For notes about the latest changes please read CHANGELOG, for required changes in your code please read UPGRADE chapter of the documentation.

Requirements:

Installation :

Pretty simple with Composer, run

Usage :

1 - Configuration

Nothing to do, the bundle is ready to use, you can start using it and implement it directly to you project.

2 - Use in controller's method

To use the bundle in a controller's method, you have to add the #[SmartFetch] attribute to the parameter or the method.

3 - Use in controller's parameter

Entities

Suppose that you have a project when a User can post Article and Comment, a User can also like a Comment, and an Article can belong to many Category. The entities for this project will be like this:

User

Article

Comment

Category

Controller

Now, suppose that you want to get a User with all his Article and Comment and all the Category of each Article and all the User who liked each Comment of each Article, and to show it in a view, the controller and view.

Controller

View

What do you think Symfony and Doctrine will do ?

Explosion, yes because the User in the controller will be fetched with this simple SQL query:

All the relation will be a Proxy and every time you will access to a relation, a new SQL query will be executed to fetch only one entity. It's easy when the view in rendered, if you take a look on the Symfony profiler toolbar, in the Doctrine section , you will see it in Yellow color in other terms, Warning it's probably a N+1 query.

Here is the query metrics:

How to avoid this ?

With Smart Fetch Bundle you can fetch all the relations that you want, and you can also fetch the relations of the relations, and the relations of the relations of the relations, and so on in only ONE QUERY.

How to do it ?

After installing the bundle, the only thing that you have to do is to add the #[SmartFetch] attribute to the property or the methode and indicate what do you want to fetch.

Example:

Controller:
On the method:
On the parameter:

What do you think Symfony and Doctrine will do ?

Nothing bad, the User and all the relations that you want will be fetched in only one query. The query metrics will be like this:

Isn't it amazing ? 😍

Don't waste your time, install the bundle and enjoy it.

PS: If you're thinking of using this bundle to retrieve several hundred entities in a single query, take a pause and think again, because it won't be reasonable, Doctrine will lose his mind when hydrating thousands of rows to the entity, so our advice is to use this bundle to find the right balance between accepting a certain degree of n+1 and making joins.


All versions of smart-fetch-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
symfony/config Version ^5.0|^6.0
symfony/dependency-injection Version ^5.0|^6.0
symfony/framework-bundle Version ^5.0|^6.0
symfony/http-kernel Version ^5.0|^6.0
doctrine/persistence Version ^2.2 || ^3.0
doctrine/doctrine-bundle Version ^2.2 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package verclam/smart-fetch-bundle contains the following files

Loading the files please wait ....