Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b0df44f

Browse files
author
Thomas Rabaix
committedApr 10, 2011
add more Interfaces, add ModelManager to abstract the persistency layer
1 parent f81802b commit b0df44f

37 files changed

+1239
-756
lines changed
 

‎Admin/Admin.php

Lines changed: 83 additions & 139 deletions
Large diffs are not rendered by default.

‎Admin/AdminInterface.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use Sonata\AdminBundle\Builder\FormBuilderInterface;
1616
use Sonata\AdminBundle\Builder\ListBuilderInterface;
1717
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
18-
18+
1919
use Symfony\Component\Routing\RouterInterface;
2020
use Symfony\Component\Translation\TranslatorInterface;
2121
use Symfony\Component\HttpFoundation\Request;
22-
22+
2323
interface AdminInterface
2424
{
2525

@@ -65,18 +65,25 @@ function setRequest(Request $request);
6565
*/
6666
function setConfigurationPool(Pool $pool);
6767

68+
/**
69+
* @abstract
70+
* @param \Symfony\Component\Routing\RouterInterface $router
71+
* @return void
72+
*/
73+
function setRouter(RouterInterface $router);
6874

6975
/**
76+
* Returns the class name managed
77+
*
7078
* @abstract
71-
* @param Doctrine\ORM\EntityManager|Doctrine\ODM\MongoDB\DocumentManager
7279
* @return void
7380
*/
74-
function setModelManager($manager);
81+
function getClass();
7582

7683
/**
7784
* @abstract
78-
* @param \Symfony\Component\Routing\RouterInterface $router
85+
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
7986
* @return void
8087
*/
81-
function setRouter(RouterInterface $router);
88+
function attachAdminClass(FieldDescriptionInterface $fieldDescription);
8289
}

‎Admin/FieldDescription.php renamed to ‎Admin/BaseFieldDescription.php

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*
4848
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
4949
*/
50-
class FieldDescription
50+
abstract class BaseFieldDescription implements FieldDescriptionInterface
5151
{
5252

5353
/**
@@ -99,7 +99,7 @@ class FieldDescription
9999
* @var Admin the related admin instance
100100
*/
101101
protected $admin;
102-
102+
103103
/**
104104
* @var Admin the associated admin class if the object is associated to another entity
105105
*/
@@ -127,7 +127,7 @@ public function getFieldName()
127127
}
128128

129129
/**
130-
* Set the name
130+
* Set the name
131131
*
132132
* @param string $name
133133
* @return void
@@ -248,7 +248,7 @@ public function setType($type)
248248

249249
/**
250250
* return the type
251-
*
251+
*
252252
* @return int|string
253253
*/
254254
public function getType()
@@ -259,7 +259,7 @@ public function getType()
259259
/**
260260
* set the parent Admin (only used in nested admin)
261261
*
262-
* @param Admin $parent
262+
* @param \Sonata\AdminBundle\Admin\Admin $parent
263263
* @return void
264264
*/
265265
public function setParent(Admin $parent)
@@ -270,28 +270,13 @@ public function setParent(Admin $parent)
270270
/**
271271
* return the parent Admin (only used in nested admin)
272272
*
273-
* @return Admin
273+
* @return \Sonata\AdminBundle\Admin\Admin
274274
*/
275275
public function getParent()
276276
{
277277
return $this->parent;
278278
}
279279

280-
/**
281-
* Define the association mapping definition
282-
*
283-
* @param array $associationMapping
284-
* @return void
285-
*/
286-
public function setAssociationMapping(array $associationMapping)
287-
{
288-
$this->associationMapping = $associationMapping;
289-
290-
$this->type = $this->type ?: $associationMapping['type'];
291-
$this->mappingType = $this->mappingType ?: $associationMapping['type'];
292-
$this->fieldName = $associationMapping['fieldName'];
293-
}
294-
295280
/**
296281
* return the association mapping definition
297282
*
@@ -302,35 +287,6 @@ public function getAssociationMapping()
302287
return $this->associationMapping;
303288
}
304289

305-
/**
306-
* return the related Target Entity
307-
*
308-
* @return string|null
309-
*/
310-
public function getTargetEntity()
311-
{
312-
if ($this->associationMapping) {
313-
return $this->associationMapping['targetEntity'];
314-
}
315-
316-
return null;
317-
}
318-
319-
/**
320-
* set the field mapping information
321-
*
322-
* @param array $fieldMapping
323-
* @return void
324-
*/
325-
public function setFieldMapping(array $fieldMapping)
326-
{
327-
$this->fieldMapping = $fieldMapping;
328-
329-
$this->type = $this->type ?: $fieldMapping['type'];
330-
$this->mappingType = $this->mappingType ?: $fieldMapping['type'];
331-
$this->fieldName = $this->fieldName ?: $fieldMapping['fieldName'];
332-
}
333-
334290
/**
335291
* return the field mapping definition
336292
*
@@ -344,7 +300,7 @@ public function getFieldMapping()
344300
/**
345301
* set the association admin instance (only used if the field is linked to an Admin)
346302
*
347-
* @param Admin $associationAdmin the associated admin
303+
* @param \Sonata\AdminBundle\Admin\Admin $associationAdmin the associated admin
348304
*/
349305
public function setAssociationAdmin(Admin $associationAdmin)
350306
{
@@ -354,23 +310,13 @@ public function setAssociationAdmin(Admin $associationAdmin)
354310

355311
/**
356312
* return the associated Admin instance (only used if the field is linked to an Admin)
357-
* @return Admin
313+
* @return \Sonata\AdminBundle\Admin\Admin
358314
*/
359315
public function getAssociationAdmin()
360316
{
361317
return $this->associationAdmin;
362318
}
363319

364-
/**
365-
* return true if the FieldDescription is linked to an identifier field
366-
*
367-
* @return bool
368-
*/
369-
public function isIdentifier()
370-
{
371-
372-
return isset($this->fieldMapping['id']) ? $this->fieldMapping['id'] : false;
373-
}
374320

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

391337
$value = call_user_func(array($object, $getter));
392-
338+
393339
} else if ($this->getOption('code') && method_exists($object, $this->getOption('code'))) {
394340

395341
$value = call_user_func(array($object, $this->getOption('code')));
@@ -401,7 +347,7 @@ public function getValue($object)
401347
/**
402348
* set the admin class linked to this FieldDescription
403349
*
404-
* @param Admin $admin
350+
* @param \Sonata\AdminBundle\Admin\Admin $admin
405351
* @return void
406352
*/
407353
public function setAdmin(Admin $admin)
@@ -410,7 +356,7 @@ public function setAdmin(Admin $admin)
410356
}
411357

412358
/**
413-
* @return Admin the admin class linked to this FieldDescription
359+
* @return \Sonata\AdminBundle\Admin\Admin the admin class linked to this FieldDescription
414360
*/
415361
public function getAdmin()
416362
{
@@ -453,7 +399,7 @@ public function mergeOption($name, array $options = array())
453399

454400
/**
455401
* merge options values
456-
*
402+
*
457403
* @param array $options
458404
* @return void
459405
*/

0 commit comments

Comments
 (0)