2017 © Pedro Peláez
 

library propel-provider-behavior

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

image

emiliomg/propel-provider-behavior

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  • Monday, August 24, 2015
  • by emiliomg
  • Repository
  • 0 Watchers
  • 1 Stars
  • 65 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Propel Provider Behavior

A Propel ORM Behavior that provides you with Providers for Query/Model/Peer Objects., (*1)

Requirements

  • Propel > 1.6.0

Install

Add this behavior to your project via your composer.json file, (*2)

"require": {
    "emiliomg/propel-provider-behavior": "~1.0"
}

Or simply run composer require emiliomg/propel-provider-behavior., (*3)

Then, add the following configuration to your build.properties:, (*4)

propel.behavior.providerBase.behavior = vendor.emiliomg.propel-provider-behavior.src.ProviderBaseBehavior.ProviderBaseBehavior
propel.behavior.providerFassade.behavior = vendor.emiliomg.propel-provider-behavior.src.ProviderFassadeBehavior.ProviderFassadeBehavior
propel.behavior.default = providerBase, providerFassade

The propel.behavior.default makes sure every one of your models uses this behavior., (*5)

Finally, rebuild your models. The provider classes will be generated alongside you Models and Query-Classes., (*6)

Configuration

You can use the propel.behavior.provider.cachefile = true switch. This will generate a providerCache.json file inside the outputDir which contains a list of all generated Providers. This can be useful, e.g. for automatically generating factories (which the Symfony2 Bundle does for you automatically)., (*7)

Generated code

The generated provider code is quite simple. We use a simple schema.xml like this, (*8)

<?xml version="1.0" encoding="utf-8"?>
<database name="bookstore" defaultIdMethod="native" namespace="Foo\Bar\Model">
    <table name="Author" idMethod="native">
        <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
        <column name="name" type="VARCHAR" size="255" required="false"/>
        <vendor type="mysql">
            <parameter name="Engine" value="InnoDB"/>
        </vendor>
    </table>
</database>

A sample output for a ficional Author-Model then looks like this:, (*9)

BaseAuthorProvider

<?php

namespace Foo\Bar\Model\om;

use \Propel;
use Foo\Bar\Model\Author;
use Foo\Bar\Model\AuthorPeer;
use Foo\Bar\Model\AuthorQuery;

/**
 * This is a provider base class for the 'Author' table.
 * It provides query, model, peer and connection instances.
 * You can use Dependency Injection to inject this provider into services who need
 * 'Author'-queries or -models and fetch them via this provider.
 * There is no need to access the models or queries directly, since this provider can be mocked.
 */
abstract class BaseAuthorProvider
{
    /**
     * Returns a new query instance.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param   AuthorQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return AuthorQuery
     */
    public function getQuery($modelAlias = null, $criteria = null)
    {
        $query = AuthorQuery::create($modelAlias, $criteria);

        return $query;
    }

    /**
     * Returns a new Model instance.
     *
     * @return Author
     */
    public function getModel()
    {
        $model = new Author();

        return $model;
    }

    /**
     * Returns a new Peer Instance;
     *
     * @return AuthorPeer
     */
    public function getPeer()
    {
        $peer = new AuthorPeer();

        return $peer;
    }

    /**
     * Returns the connection for this table.
     *
     * @return \PropelPDO
     */
    public function getConnection()
    {
        $peer = $this->getPeer();
        $connection = Propel::getConnection($peer::DATABASE_NAME);

        return $connection;
    }

}

AuthorProvider

The behaviors also generate fassade classes, which will be generated if and only if there is no fassade class already present. A fassade class looks like this:, (*10)

<?php

namespace Foo\Bar\Model;

use Foo\Bar\Model\om\BaseAuthorProvider;

/**
 * This is a provider fassade class for the 'Author' table.
 * It provides query, model, peer and connection instances.
 * You can use Dependency Injection to inject this provider into services who need
 * 'Author'-queries or -models and fetch them via this provider.
 * There is no need to access the models or queries directly, since this provider can be mocked.
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 */
class AuthorProvider extends BaseAuthorProvider
{

}

The Versions

24/08 2015

dev-master

9999999-dev

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

24/08 2015

1.1.2

1.1.2.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

09/08 2015

1.1.1

1.1.1.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

09/08 2015

1.1.0

1.1.0.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

09/08 2015

dev-feature/tests

dev-feature/tests

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

02/08 2015

1.0.4

1.0.4.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

02/08 2015

1.0.3

1.0.3.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

02/08 2015

1.0.2

1.0.2.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

The Development Requires

by Emilio Markgraf

behavior factory factories provider propel propelorm

31/07 2015

1.0.1

1.0.1.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

by Emilio Markgraf

behavior factory factories provider propel propelorm

31/07 2015

1.0.0

1.0.0.0

A Propel ORM behavior that adds non-static providers to fetch new query-objects, new models, peers and connections.

  Sources   Download

The Requires

 

by Emilio Markgraf

behavior factory factories provider propel propelorm