Download the PHP package andanteproject/shared-query-builder without Composer

On this page you can find all versions of the php package andanteproject/shared-query-builder. 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 shared-query-builder

Andante Project Logo

Shared Query Builder

Doctrine 2 Query Builder decorator - AndanteProject

Latest Version Github actions Php8 PhpStan

A Doctrine 2 Query Builder decorator that makes easier to build your query in shared contexts.

Why do I need this?

When your query business logic is big and complex you are probably going to split its building process to different places/classes.

Without SharedQueryBuilder there is no way to do that unless guessing Entity aliases and messing up with join statements.

This query builder decorator addresses some problems you can find in a real world situation you usually solve with workarounds and business conventions.

Features

Requirements

Doctrine 2 and PHP 7.4.

Install

Via Composer:

Set up

After creating your query builder, wrap it inside our SharedQueryBuilder.

From now on, you can use $sqb exactly as you usually do with query builder (every single method of QueryBuilder is available on SharedQueryBuilder), but with some useful extra methods ๐Ÿคซ.

When you're done building your query, just unwrap your SharedQueryBuilder.

Please note:

Which additional methods do I have?

Entity methods

You can ask the SharedQueryBuilder if it has and entity in the from statement or some join statements.

You can ask which is the alias of an Entity inside the query you're building (no matter if it is used in a from statement or a join statement).

You can use withAlias method to smoothly add a condition for that entity property:

Given an alias, you can retrieve its entity class:

QueryBuilder::getAllAliases is extended to have an optional bool argument $includeLazy (default:false) to include lazy joins aliases.

Lazy Join

All query builder join methods can be used as usually, but you can also use them with "lazy" prefix.

By doing this, you are defining a join statement without actually adding it to your DQL query. It is going to be added to your DQL query only when you add another condition/dql part which refers to it. Automagically โœจ.

Based on how much confused you are right now, you can check for why you should need this or some examples to achieve your "OMG" revelation moment.

Examples

Let's suppose we need to list User entities but we also have an optional filter to search an user by it's address Building name.

There is no need to perform any join until we decide to use that filter. We can use Laxy Join to achieve this.

You are probably thinking: why don't we achieve the same result with the following, more common, way? (keep in mind that avoid to perform unecessary joins is still a requirement)

The code above is perfectly fine if you build this whole query in the same context:

But you have problems:

A real world case

If your query structure grows with lots of joins and filtering criteria, you are probably going to split all that business logic in different classes.

For instance, in a backoffice Users list, you are probably going to define your main query to list entities in your controller and handle optional filters in some other classes.

Filter classes may look like this:

We are committing some multiple sins here! ๐Ÿ’€ The context is changed.

This's why SharedQueryBuilder is going to save your ass in these situations

Let's see how we can solve all these problems with SharedQueryBuilder (you can now guess why it is named like this).

Using SharedQueryBuilder you can:

Filter classes will look like this:

Immutable Parameters

Shared query builder has Immutable Parameters. Once defined, they cannot be changed otherwise and Exception will be raised.

Set parameter and use it in expression at the same moment

If you are sure you are not going to use a parameter in multiple places inside your query, you can write the following code ๐Ÿ™Œ

this way ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

Unique parameters

Beside immutable parameters, you can also demand query builder the generation of a parameter name. Using the following methods, query builder will decorate names to avoid conflicts with already declared ones ( which cannot even happen with immutable parameters).

Conclusion

The world is a happier place ๐Ÿ’.

Give us a โญ๏ธ if your world is now a happier place too! ๐Ÿ’ƒ๐Ÿป

Built with love โค๏ธ by AndanteProject team.


All versions of shared-query-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
doctrine/orm Version ^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 andanteproject/shared-query-builder contains the following files

Loading the files please wait ....