HosipLan

Untitled

May 22nd, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. class Konfiguration
  2. {
  3.     public function __construct($entityManager)
  4.     {
  5.         $this->em = $entityManager;
  6.     }
  7.  
  8.     public function getAll()
  9.     {
  10.         $config = $this->getCached();
  11.         if ($config === NULL) {
  12.             $config = $this->em->getRepository('Config')->getAll();
  13.             $this->cache($config);
  14.         }
  15.  
  16.         return $config;
  17.     }
  18. }
  19.  
  20.  
  21. // službu zaregistruju do Containeru ...
  22.  
  23. // pracuju se službou, nezajímá mě, že pracuji s nějakými entitami
  24. $container->konfiguration->getAll();
  25.  
  26.  
  27.  
  28. # kdežto podle tvého postupu
  29.  
  30. class Konfiguration extends Model\Service
  31. {
  32.     function __construct($entityManager, $entity)
  33.     {
  34.         // ...
  35.     }
  36.  
  37.     public function getAll()
  38.     {
  39.         $config = $this->getCached();
  40.         if ($config === NULL) {
  41.             $config = $this->em->getRepository($this->entity)->getAll();
  42.             $this->cache($config);
  43.         }
  44.  
  45.         return $config;
  46.     }
  47. }
  48.  
  49. // zaregistruju ...
  50.  
  51. $container->doctrine->setEntityServiceClass('Config', 'Konfiguration');
  52. $container->doctrine->getEntityService('config')->getAll();
  53.  
  54. // pracuji s entitami, které mají přidělené služby. Služba ztrácí svůj původní význam obalení několika (n repozitářů a n entit) do voňavého API, se kterým bude radost pracovat.
Advertisement
Add Comment
Please, Sign In to add comment