Skip to content

Commit

Permalink
add more Interfaces, add ModelManager to abstract the persistency layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Apr 10, 2011
1 parent f81802b commit b0df44f
Show file tree
Hide file tree
Showing 37 changed files with 1,239 additions and 756 deletions.
222 changes: 83 additions & 139 deletions Admin/Admin.php

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Sonata\AdminBundle\Builder\FormBuilderInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;

use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;

interface AdminInterface
{

Expand Down Expand Up @@ -65,18 +65,25 @@ function setRequest(Request $request);
*/
function setConfigurationPool(Pool $pool);

/**
* @abstract
* @param \Symfony\Component\Routing\RouterInterface $router
* @return void
*/
function setRouter(RouterInterface $router);

/**
* Returns the class name managed
*
* @abstract
* @param Doctrine\ORM\EntityManager|Doctrine\ODM\MongoDB\DocumentManager
* @return void
*/
function setModelManager($manager);
function getClass();

/**
* @abstract
* @param \Symfony\Component\Routing\RouterInterface $router
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return void
*/
function setRouter(RouterInterface $router);
function attachAdminClass(FieldDescriptionInterface $fieldDescription);
}
78 changes: 12 additions & 66 deletions Admin/FieldDescription.php → Admin/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* @author Thomas Rabaix <[email protected]>
*/
class FieldDescription
abstract class BaseFieldDescription implements FieldDescriptionInterface
{

/**
Expand Down Expand Up @@ -99,7 +99,7 @@ class FieldDescription
* @var Admin the related admin instance
*/
protected $admin;

/**
* @var Admin the associated admin class if the object is associated to another entity
*/
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getFieldName()
}

/**
* Set the name
* Set the name
*
* @param string $name
* @return void
Expand Down Expand Up @@ -248,7 +248,7 @@ public function setType($type)

/**
* return the type
*
*
* @return int|string
*/
public function getType()
Expand All @@ -259,7 +259,7 @@ public function getType()
/**
* set the parent Admin (only used in nested admin)
*
* @param Admin $parent
* @param \Sonata\AdminBundle\Admin\Admin $parent
* @return void
*/
public function setParent(Admin $parent)
Expand All @@ -270,28 +270,13 @@ public function setParent(Admin $parent)
/**
* return the parent Admin (only used in nested admin)
*
* @return Admin
* @return \Sonata\AdminBundle\Admin\Admin
*/
public function getParent()
{
return $this->parent;
}

/**
* Define the association mapping definition
*
* @param array $associationMapping
* @return void
*/
public function setAssociationMapping(array $associationMapping)
{
$this->associationMapping = $associationMapping;

$this->type = $this->type ?: $associationMapping['type'];
$this->mappingType = $this->mappingType ?: $associationMapping['type'];
$this->fieldName = $associationMapping['fieldName'];
}

/**
* return the association mapping definition
*
Expand All @@ -302,35 +287,6 @@ public function getAssociationMapping()
return $this->associationMapping;
}

/**
* return the related Target Entity
*
* @return string|null
*/
public function getTargetEntity()
{
if ($this->associationMapping) {
return $this->associationMapping['targetEntity'];
}

return null;
}

/**
* set the field mapping information
*
* @param array $fieldMapping
* @return void
*/
public function setFieldMapping(array $fieldMapping)
{
$this->fieldMapping = $fieldMapping;

$this->type = $this->type ?: $fieldMapping['type'];
$this->mappingType = $this->mappingType ?: $fieldMapping['type'];
$this->fieldName = $this->fieldName ?: $fieldMapping['fieldName'];
}

/**
* return the field mapping definition
*
Expand All @@ -344,7 +300,7 @@ public function getFieldMapping()
/**
* set the association admin instance (only used if the field is linked to an Admin)
*
* @param Admin $associationAdmin the associated admin
* @param \Sonata\AdminBundle\Admin\Admin $associationAdmin the associated admin
*/
public function setAssociationAdmin(Admin $associationAdmin)
{
Expand All @@ -354,23 +310,13 @@ public function setAssociationAdmin(Admin $associationAdmin)

/**
* return the associated Admin instance (only used if the field is linked to an Admin)
* @return Admin
* @return \Sonata\AdminBundle\Admin\Admin
*/
public function getAssociationAdmin()
{
return $this->associationAdmin;
}

/**
* return true if the FieldDescription is linked to an identifier field
*
* @return bool
*/
public function isIdentifier()
{

return isset($this->fieldMapping['id']) ? $this->fieldMapping['id'] : false;
}

/**
* return the value linked to the description
Expand All @@ -389,7 +335,7 @@ public function getValue($object)
if (method_exists($object, $getter)) {

$value = call_user_func(array($object, $getter));

} else if ($this->getOption('code') && method_exists($object, $this->getOption('code'))) {

$value = call_user_func(array($object, $this->getOption('code')));
Expand All @@ -401,7 +347,7 @@ public function getValue($object)
/**
* set the admin class linked to this FieldDescription
*
* @param Admin $admin
* @param \Sonata\AdminBundle\Admin\Admin $admin
* @return void
*/
public function setAdmin(Admin $admin)
Expand All @@ -410,7 +356,7 @@ public function setAdmin(Admin $admin)
}

/**
* @return Admin the admin class linked to this FieldDescription
* @return \Sonata\AdminBundle\Admin\Admin the admin class linked to this FieldDescription
*/
public function getAdmin()
{
Expand Down Expand Up @@ -453,7 +399,7 @@ public function mergeOption($name, array $options = array())

/**
* merge options values
*
*
* @param array $options
* @return void
*/
Expand Down
Loading

0 comments on commit b0df44f

Please sign in to comment.