1. Go to this page and download the library: Download rroek/entity-manager-bundle 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/ */
rroek / entity-manager-bundle example snippets
/**
* @return array
*/
public function registerBundles()
{
$bundles = [
[...]
new Rroek\EntityManagerBundle\RroekEntityManagerBundle(),
[...]
namespace Acme\MyBundle\Manager;
use Rroek\EntityManagerBundle\Model\Manager\AbstractBaseEntityManager;
use Rroek\EntityManagerBundle\Model\Manager\EntityManagerInterface as PersonalEntityManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Acme\MyBundle\Entity\MyPersonalEntity;
/**
* Class MyPersonalEntityManager.
*/
class MyPersonalEntityManager extends AbstractBaseEntityManager implements PersonalEntityManagerInterface
{
/**
* MyPersonalEntityManager constructor.
*
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
parent::__construct($entityManager);
$this->setEntityClass(MyPersonalEntity::class);//Use your Entity ClassName
$this->setEntityClassNamespace('Acme\MyBundle\Entity\MyPersonalEntity');//Use Namespace of your Entity
}
/**
* Bind data array to the given entity.
*
* @param MyPersonalEntityManager $entity
* @param array $data
*
* @return MyPersonalEntityManager
*/
protected function bind(MyPersonalEntity $entity, array $data)
{
/*this function get an existing instance of our Entity, or a new instance (see create & update method on abstraction)
All the data to set/update are stocked on $data array.
*/
$entity->setLabel($this->getValue($data, 'label'));//We call the entity property setter and give "label" key of $data as value
$entity->setLinkToAnotherEntity($this->getValue($data, 'anotherEntity', null));//Here the same but for a joined Entity like ManyToOne or OneToOne (if you set no data for key 'anotherEntity' '' will be placed instead so for a join precise null to default value)
return $entity;
}
}
[...]
/**
* Returns entity-item with given id.
*
* @param int $id
*
* @return object
*/
public function read($id){...}
/**
* Returns all entity-items.
*
* @return object[]
*/
public function readAll(){...}
/**
* Creates a new item and set the data which are passed.
*
* @param array $data
* @param bool $persist
* @param bool $flush
*
* @return object
*/
public function create(array $data, $persist = true, $flush = false){...}
/**
* Update the entity-item with given id.
*
* @param int $id
* @param array $data
* @param bool $flush
* @param bool $validate
*
* @return object
*/
public function update($id, array $data, $flush = false, $validate = false){...}
/**
* Delete the entity-item with given id.
*
* @param int $id
* @param bool $flush
*
* @return null
*
* @throws EntityNotFoundException
*/
public function delete($id, $flush = false){...}
[...]
/**
* Return dynamically the entity repository whithout needing to specify class.
*
* @return ObjectRepository Related repository
*/
public function getRepository(){...}
/**
* @param object $entity
* @param bool $flush
*/
public function persist($entity, $flush = false){...}
/**
* Flush.
*/
public function flush(){...}
/**
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
public function getClassMetadata(){...}
/**
* @return array
*/
public function getFieldNames(){...}
/**
* @return array
*/
public function getAssociationNames(){...}
[...]
use Rroek\EntityManagerBundle\Model\Entity\IdTrait;
use Rroek\EntityManagerBundle\Model\Entity\LabelTrait;
[...]
/**
* @var int
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=true)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* JMS\Expose
*/
private $id;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* @param int $id
*
* @return object
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @var string
*
* @ORM\Column(name="label", type="string", length=255)
*/
private $label;
/**
* Set label.
*
* @param string $label
*
* @return mixed
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* Get label.
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.