Lexinek

Untitled

Sep 12th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.  
  3. class ActivityLogFactory extends Nette\Object implements IControlFactory {
  4.  
  5.     public function setTranslator(Nette\Localization\ITranslator $translator) {
  6.         echo "TEST";
  7.         die();
  8.     }
  9.  
  10.     public function create(array $activities)
  11.     {
  12.         return new Components\ActivityLog($activities);
  13.     }
  14.  
  15. }
  16.  
  17. ?>
  18.  
  19.  
  20. <?php
  21.  
  22. use
  23.     Nette\DI\Compiler,
  24.     Nette\DI\ContainerBuilde;
  25.  
  26.  
  27. class ControlFactoryExtension extends Nette\Config\CompilerExtension {
  28.  
  29.     public function afterCompile(Nette\Utils\PhpGenerator\ClassType $class)
  30.     {
  31.         $builder = $this->getContainerBuilder();
  32.         $definitions = $builder->getDefinitions();
  33.        
  34.         $translatorType = $builder->getByType("Nette\Localization\ITranslator");
  35.         $translator = $builder->getDefinition($translatorType);
  36.        
  37.         foreach ($definitions as $definition) {
  38.  
  39.             $classReflection = new Nette\Reflection\ClassType($definition->class);
  40.             if ($classReflection->implementsInterface("IControlFactory")) {
  41.                 $definition->addSetup("setTranslator", array($translator));
  42.             }
  43.         }
  44.  
  45.     }
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment