HosipLan

Untitled

Aug 11th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This file is part of the Kdyby (http://www.kdyby.org)
  5.  *
  6.  * Copyright (c) 2008, 2011 Filip Procházka ([email protected])
  7.  *
  8.  * @license http://www.kdyby.org/license
  9.  */
  10.  
  11. namespace Kdyby\Iterators;
  12.  
  13. use Kdyby;
  14. use Nette;
  15. use Nette\Reflection\ClassType;
  16.  
  17.  
  18.  
  19. /**
  20.  * @author Filip Procházka
  21.  */
  22. class TypeIterator extends SelectIterator
  23. {
  24.  
  25.     /** @var array */
  26.     private $types = array();
  27.  
  28.  
  29.  
  30.     /**
  31.      * @return TypeIterator
  32.      */
  33.     public function isAbstract()
  34.     {
  35.         $this->select(function (TypeIterator $iterator) {
  36.             return $iterator->current()->isAbstract();
  37.         });
  38.  
  39.         return $this;
  40.     }
  41.  
  42.  
  43.  
  44.     /**
  45.      * @return TypeIterator
  46.      */
  47.     public function isSubclassOf($class)
  48.     {
  49.         $this->select(function (TypeIterator $iterator) use ($class) {
  50.             if ($iterator->current()->isInterface()) {
  51.                 return FALSE;
  52.             }
  53.  
  54.             return $iterator->current()->isSubclassOf($class);
  55.         });
  56.  
  57.         return $this;
  58.     }
  59.  
  60.  
  61.  
  62.     /**
  63.      * @param string $interface
  64.      * @return TypeIterator
  65.      */
  66.     public function implementsInterface($interface)
  67.     {
  68.         $this->select(function (TypeIterator $iterator) use ($interface) {
  69.             return $iterator->current()->implementsInterface($interface);
  70.         });
  71.  
  72.         return $this;
  73.     }
  74.  
  75.  
  76.  
  77.     /**
  78.      * @return ClassType
  79.      */
  80.     public function current()
  81.     {
  82.         $type = parent::current();
  83.  
  84.         if (!isset($this->types[$type])) {
  85.             $this->types[$type] = ClassType::from($type);
  86.         }
  87.  
  88.         return $this->types[$type];
  89.     }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment