/** * Return cached object if exists * * @param string $page The name of the page. * @param string $prefix Prefix to use in class structure. * * @return mixed */ public static function create_or_null($page, $prefix) { static $cache = array(); if (!isset($cache[$prefix])) { $cache[$prefix] = array(); } if (!isset($cache[$prefix][$page])) { $cache[$prefix][$page] = parent::create_or_null($page, $prefix); } return $cache[$prefix][$page]; }
/** * Unified setter function * * @param string $type Type of object. * @param string $page Page name. * @param mixed|null $handler Handler to apply. * * @throws InvalidArgumentException For invalid argument types. */ private static function set_settable_handler($type, $page, $handler = null) { // Create NullObject for empty handler, i.e. remove functionality. if (empty($handler)) { $handler = Stencil_Subclass_Factory::create_null(sprintf(self::CLASS_FORMAT, $type)); } switch ($type) { case 'Hierarchy': if (!is_array($handler) && !$handler instanceof Traversable) { throw new InvalidArgumentException('Expected $handler to be array or Traversable.'); } break; default: if (!is_callable($handler)) { throw new InvalidArgumentException('Expected $handler to be callable.'); } break; } self::$handlers[$type][$page] = $handler; }