for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Majora\Framework\Loader\Bridge\Form;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* Trait which provides a bridge between majora loader and symfony forms
*
* @see DataTransformerInterface
* @property entityClass
* @method retrieve($id) : CollectionableInterface
*/
trait DataTransformerLoaderTrait
{
* Model -> View
* @see DataTransformerInterface::transform()
public function transform($entity)
if (null === $entity) {
return '';
}
if (!is_subclass_of($entity, $this->entityClass)) {
entityClass
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
is_subclass_of
$this->entityClass
ReflectionClass::implementsInterface
throw new \InvalidArgumentException(sprintf(
'Unsupported entity "%s" into "%s" loader.',
get_class($entity),
__CLASS__
));
return $entity->getId();
* View -> Model
* @see DataTransformerInterface::reverseTransform()
public function reverseTransform($id)
if (!$id) {
return null;
if (!$entity = $this->retrieve($id)) {
throw new TransformationFailedException(sprintf(
'%s#%s cannot be found.',
$this->entityClass,
$id
return $entity;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: