PHP code example of porkchopsandwiches / doctrine-utilities

1. Go to this page and download the library: Download porkchopsandwiches/doctrine-utilities library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

porkchopsandwiches / doctrine-utilities example snippets


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"
);

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
		);
	}
}

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);


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)