예제 #1
0
파일: manager.php 프로젝트: Blu2z/implsk
 /**
  *
  * @param string $interface
  * @param nc_search_context $context
  * @return nc_search_extension_chain с экземплярами классов расширения, подходящих под данный контекст
  * @throws nc_search_exception
  */
 public static function get($interface, nc_search_context $context)
 {
     $cache_id = $interface . "__" . $context->get_hash();
     if (isset(self::$cache[$cache_id])) {
         return self::$cache[$cache_id];
     }
     $result = new nc_search_extension_chain();
     foreach (self::get_all_extensions() as $rule) {
         if ($rule->get('extension_interface') == $interface && $context->conforms_to($rule)) {
             $extension_class = $rule->get('extension_class');
             $extension_instance = new $extension_class($context);
             if (!$extension_instance instanceof $interface) {
                 // WTF? Implement an interface!
                 throw new nc_search_exception("Extension '{$extension_class}' does not implement the interface '{$interface}'");
             }
             $result->add($extension_instance);
         }
     }
     self::$cache[$cache_id] = $result;
     return $result;
 }