2017 © Pedro Peláez
 

library doctrine-utilities

Some general utility classes suitable for use with Doctrine.

image

porkchopsandwiches/doctrine-utilities

Some general utility classes suitable for use with Doctrine.

  • Wednesday, March 11, 2015
  • by PorkChopSandwiches
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

doctrine-utilities

Common utilities for Doctrine-based projects, including a UTCDateTime column type and basic Entity classes., (*1)

Entity Manager Generator

Convenience generator for Doctrine Entity Manager, useful in both cli-config.php and in the app proper., (*2)

Automatically registers the utcdatetime column type which stores a DateTime in UTC regardless of the timezone of the MySQL server or PHP environment., (*3)

use PorkChopSandwiches\Doctrine\Utilities\EntityManager\Generator;

$entity_manager = Generator::manufacture(

    # The \Doctrine\DBAL\Connection instance or array
    $database_config, 

    # A \Doctrine\Common\Cache instance, for Query and MetaData caching
    $cache,

    # A \Doctrine\Common\Annotations\AnnotationReader instance
    $annotation_reader,

    # An array of directories to read Entity annotations from
    $entity_paths,

    # The proxy autogeneration behaviour
    AbstractProxyFactory::AUTOGENERATE_ALWAYS,

    # Whether to ensure production settings are on
    false,

    # Absolute path to Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php file
    ROOT_PATH . Generator::DOCTRINE_ANNOTATIONS_FILE_PATH,

    # PHP namespace for proxies
    "App\\Proxies",

    # Absolute path to directory where proxies will be generated
    ROOT_PATH . "/App/Proxies"
);

Entity classes

Includes a basic Entity class, plus 3 extending utility classes:, (*4)

  1. DatedEntity, with date_created and date_updated UTC DateTime columns,
  2. AutoIncrementedIDEntity with an auto-incrementing UNSIGNED INT id column, and
  3. DatedAutoIncrementedIDEntity with both of the above.

Basic entity

use PorkChopSandwiches\Doctrine\Utilities\Entities\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(
 *  name="sample_entities",
 *  uniqueConstraints={
 *  }
 * )
 */
class SampleEntity extends Entity {

    /**
     * @ORM\Column(type="string", length=100, options={"default"=""})
     * @ORM\Id
     */
    private $label = "";

    /**
     * @param array [$args]
     * 
     * @return array
     */
    public function preserialise (array $args = array()) {
        return array(
            "label" => $this -> label
        );
    }
}

Dated entity

use PorkChopSandwiches\Doctrine\Utilities\Entities\DatedEntity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(
 *  name="sample_dated_entities",
 *  uniqueConstraints={
 *  }
 * )
 */
class SampleDatedEntity extends DatedEntity {

    /**
     * @ORM\Column(type="string", length=100, options={"default"=""})
     * @ORM\Id
     */
    private $label = "";

    /**
     * @param array [$args]
     * 
     * @return array
     */
    public function preserialise (array $args = array()) {
        return array_merge(parent::preserialise($args), array(
            "label" => $this -> label
        ));
    }
}

...

$instance = new SampleDatedEntity;
$instance -> getDateCreated(); // => DateTime
$instance -> getDateUpdated(); // => DateTime
$instance -> setDateUpdated(new \DateTime);

Produces Doctrine SQL:, (*5)

CREATE TABLE sample_dated_entities (`label` VARCHAR(100) DEFAULT '' NOT NULL, date_created DATETIME NOT NULL, date_updated DATETIME NOT NULL, PRIMARY KEY(`label`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

Auto-incrementing ID entity

An entity with an auto-incrementing id UNSIGNED INT column., (*6)

use PorkChopSandwiches\Doctrine\Utilities\Entities\AutoIncrementedIDEntity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(
 *  name="sample_aiid_entities",
 *  uniqueConstraints={
 *  }
 * )
 */
class SampleAutoIncrementedIDEntity extends AutoIncrementedIDEntity {

    /**
     * @ORM\Column(type="string", length=100, options={"default"=""})
     */
    private $label = "";

    public function preserialise (array $args = array()) {
        return array_merge(parent::preserialise($args), array(
            "label" => $this -> label
        ));
    }
}

...

$instance = new SampleAutoIncrementedIDEntity;
$instance -> getID(); // int (or null if not yet flushed)

Produces Doctrine SQL:, (*7)

CREATE TABLE sample_aiid_entities (id INT UNSIGNED AUTO_INCREMENT NOT NULL, `label` VARCHAR(100) DEFAULT '' NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

The Versions

11/03 2015

dev-master

9999999-dev

Some general utility classes suitable for use with Doctrine.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine

11/03 2015

1.1.1

1.1.1.0

Some general utility classes suitable for use with Doctrine.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine

11/03 2015

1.1.0

1.1.0.0

Some general utility classes suitable for use with Doctrine.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine

10/03 2015

1.0.1

1.0.1.0

Some general utility classes suitable for use with Doctrine.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine

09/03 2015

1.0.0

1.0.0.0

Some general utility classes suitable for use with Doctrine.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine