Download the PHP package orbitale/array-fixture without Composer

On this page you can find all versions of the php package orbitale/array-fixture. 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 array-fixture

Orbitale Array Fixture

A Doctrine Data Fixture service that allow you to write your fixtures as PHP arrays.

Installation

Install the library in your project with Composer:

Why?

Doctrine Fixtures examples across the web mostly look like this:

This example contains two main issues:

This package provides a Fixture class you can use (with or without the DoctrineBundle) that allows you to write PHP arrays instead of objects and manual instructions.

The biggest advantage is that you can easily get a raw PHP export of your database (such as with PhpMyAdmin) and put it inside the fixture (this requires checking fields names, but search/replace will handily help making this fast), or you can also fetch data from any source (Fixtures are registered as services when using them in Symfony, so you could inject any service in their constructor) and return it as a PHP array (such as fetching from an API, a CSV file, a Yaml file, etc.).

There are some specific features that are however only available in pure PHP mode (like getting references and using a Closure to populate the field).

Usage

Here is an example of a standard fixtures class:

Let's explain:

After all entities are hydrated and persisted, the Entity Manager will be flushed, and entities will be saved in your database.

References

Sometimes, an entity depends on another to be populated.

With this Fixture class, it becomes much simpler since a few methods can be overriden in order to simplify the understanding on how our entities are persisted.

ℹ Note: For this, you must determine in which order these fixtures must be executed, by implementing either the Doctrine\Common\DataFixtures\OrderedFixtureInterface or Doctrine\Common\DataFixtures\DependentFixtureInterface interfaces (but not both!).

See the examples:

Thanks to the overrides of getReferencePrefix and getMethodNameForReference, after each Tag is persisted, the Fixture will add a reference of the tag in the memory by calling this:

Then, we can create the PostFixtures and fetch the reference just like we would do with any common Fixture:

Here, we reuse the Some tag tag name and the tags- prefix that were specified in the TagFixtures!

🚀Pro tip: You can also use a class constant in TagFixtures (or any other class) for the tag name ("Some tag" here) and reuse it in your tests, this will allow you to change Some Tag to something else without breaking your tests!

Using a callable to get a self-referenced entity

When you have self-referencing relationships, you may need a reference of an object that may have already been persisted.

For this, first, you should set the flushEveryXIterations option to 1 (view below) to allow flushing every entity. Be careful, because flushing every time is more time-consuming. Don't do this if you have a lot of entities to process in your fixture (like hundreds).

Next, you can set a callable element as the value of your object so you can interact manually with the injected object as 1st argument, and the AbstractFixture object as 2nd argument.

The EntityManagerInterface is also injected as 3rd argument in case you need to do some specific requests or query through another table.

Example here:

This allows perfect synchronicity when dealing with self-referencing relations.

The advantage of closures is that you can also use external references by using a use (...) directive in the closure definition, or you can also call the entity itself, the fixture or the entity manager since they are passed as arguments (as in the example) to the closure at runtime.

Insert primary keys

If you want, you can specify the primary key field of your entity, like this:

If your primary key name is different than id, it's fine: the fixture class uses Doctrine's Metadata in order to detect your primary key.

This is really efficient when using uuid as field type for your entities, as UUIDs can be generated either from the database or from your code itself, and Doctrine will take it in account, contrary to auto-increment-integer fields that need a feedback from the database to generate the ID.

Note that this feature is not yet compatible with composite primary keys (yet, feel free to help if you know some about this!).

ArrayFixture class reference

The ArrayFixture class contains several protected methods you can override for your needs:

License and Copyright

This project is licensed under LGPL-2.1. Check the LICENSE file for more details.


All versions of array-fixture with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
doctrine/data-fixtures Version ^1.4|^2.0
doctrine/instantiator Version ^1.3|^2.0
doctrine/persistence Version ^1.3|^2.0|^3.0|^4.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 orbitale/array-fixture contains the following files

Loading the files please wait ....