Download the PHP package graze/dal without Composer

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

DAL (Data Access Layer)

[Travis branch]() [Scrutinizer]() [Scrutinizer Coverage]() [PHP Version]() [Packagist]() [Packagist]()

DAL is a data access layer for PHP, built to add an additional layer of abstraction between your application and persistence layers. The main goal of this library is to allow use of multiple persistence layers, each potentially employing different abstraction patterns, under a single interface.

The data mapper pattern is great for keeping the particulars of data persistence hidden behind its interfaces. DAL improves upon this abstraction to include multiple persistence layers while providing underlying support for patterns other than data mapper (e.g. active record).

We're using this in-house to move our application towards a more manageable data mapper layer rather than our current active record implementation. This will be our interface into persistence across our PHP applications for the foreseeable future. We will continue to use our active record implementation underneath DAL until we decide to remove it completely, at which point DAL will stay put.

The main interface of DAL mimics the API of Doctrine ORM, with similarly named getRepository(), persist() and flush() methods. The repositories exposed through the getRepository() method even implement Doctrine's ObjectRepository, all with the aim of having a common ground with one of the most feature-complete data mapper libraries for PHP.

It can be installed in whichever way you prefer, but we recommend Composer.

Documentation

Getting started with Eloquent

Using Eloquent with DAL requires the illuminate/eloquent package. You may also find the following resources helpful if you're using Eloquent outside of Laravel: How to use Eloquent outside of Laravel, Using Eloquent outside Laravel.

Setting up the DalManager

We've got a DalManager object setup in our application, now we need to write some configuration for our entities:

Writing the config

Adapters come with two methods of configuration createFromYaml and createFromArray, in this documentation all examples are in YAML, but you can just use an array or anything that can convert into an array.

This is the config for a basic Product entity in our application. It's configured with the following fields:

Generating the classes

With this setup, we don't actually need to write any PHP code for our entity, DAL can generate it all for us. By running this command, DAL will generate an entity class, a repository and the underlying Eloquent model we need to get started.

Using the DalManager

We've now got everything we need to start using our entity, which is done like so:

Getting started with Doctrine

Getting started with Doctrine is very similar to Eloquent. The key differences are that DAL does not currently support generating the underlying Doctrine classes and configurationg for you, so you will need to write that yourself. You will also need the doctrine/orm package.

Setting up the DalManager

Writing the config

You will also need to write the Doctrine config for the underlying Doctrine entity.

Generating the DAL entities and repositories

Note: Generating Doctrine entities is currently not supported. You will have to write those yourself.

Using the DalManager

Getting started with PDO

DAL also has a very plain PdoAdapter if you don't need the features that ORMs come with but you still want a sensible set of interfaces for managing your data. This does rely on the aura/sql package though, so make sure you have that configured as a dependency of your app.

Setting up the DalManager

Writing the config

Notice that there's no record field here, as there is no underlying model or record class with PDO this is unnecessary.

Generating the DAL entities and repositories

There's no records/models to generate, so we just need to generate the DAL entities and repositories by running:

Using the DalManager

Relationships

Relationships between entities should be defined at the DAL level and not in the underlying persistence layers. This is to facilitate entities being managed by different adapters.

This example shows a simple relationship between a Customer and an Order. The Customer owns many Orders and so has a oneToMany type with the Order entity, using the customer_id field on the orders table as a foreign key and we denote that this will be a collection of entities.

On the Order entity configuration, we have a single Customer field defined as manyToOne as an Order belongs to a Customer and this uses the customer_id field on the orders table as the local key for determining which Customer owns this Order.

The localKey and foreignKey refer to fields on the database tables themselves, not the DAL entities or underlying persistence layer entities. For this reason, relationships are currently only supported where on at least one side of the relationship there is an entity using SQL as its underlying storage mechanism.

The example above shows the manyToOne and oneToMany relationship types, there is also manyToMany.

Many to many relationships

Many to many relationships require two entities and a pivot table that stores the relationship between them:

Here we have extended our Order entity to relate to many Products and of course, a single Product can also belong to many Orders.

As with other relationships we define the type and the entity, then we need to define the pivot table and the two keys, localKey and foreignKey that are on the pivot table. The localKey being the field storing the ID for the entity this configuration is for, in this case Order, and the foreignKey being the field storing the ID for the entity that we're relating to, in this case Product.

Using Multiple Adapters

Now that we've got a DalManager setup with two configured adapters, we can write config to setup two entities with different adapters and create relationships between them:

Now we can generate all the entities, repositories and records we need:

And use just like we have in all the previous examples:

This allows us to have different data handled by different adapters and storage mechanisms but create relationships between them through a single interface. How each entity is managed behind the scenes is abstracted away from our high-level code.

This opens up possibilities such as:

Database Support

In theory, DAL supports any database that is supported by the underlying persistence layers, Doctrine, Eloquent etc. However DAL only officially supports MySQL. This is because the code that handles the relationship types does currently rely on SQL queries written within DAL which have only been tested on MySQL.

If you're working with a database that is supported by your persistence layer, do give it a go, in 90% of cases it will probably work great. We will work to officially support other databases in the future.

Contributing & Support

If you have a support query, please open an issue and label it as 'support'. If you'd like to contribute, please open a PR or an issue to discuss it first. Documentation contributions are incredibly welcome.

Development

There's a docker-compose file that you can use to spin up an environment for development and testing:

License

The content of this library is released under the MIT License by Nature Delivered Ltd.
You can find a copy of this license in http://opensource.org/licenses/mit.


All versions of dal with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
graze/standards Version dev-master
doctrine/common Version ^2.5
doctrine/inflector Version ^1.1
ocramius/generated-hydrator Version ^1.2
ocramius/proxy-manager Version ^1.0
symfony/console Version ^2.8
zendframework/zend-hydrator Version ^1.0
zendframework/zend-code Version ^2.6
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 graze/dal contains the following files

Loading the files please wait ....