setAlias($invokableClass, $name); } return $this; } /** * Validate the plugin. * * Checks that the filter loaded is either a valid callback or an instance * of FilterInterface. * * @param mixed $plugin * @return void * @throws Exception\RuntimeException if invalid */ public function validatePlugin($plugin) { if ($plugin instanceof RouteInterface) { // we're okay return; } throw new Exception\RuntimeException(sprintf( 'Plugin of type %s is invalid; must implement %s\RouteInterface', (is_object($plugin) ? get_class($plugin) : gettype($plugin)), __NAMESPACE__ )); } /** * Attempt to create an instance via an invokable class. * * Overrides parent implementation by invoking the route factory, * passing $creationOptions as the argument. * * @param string $canonicalName * @param string $requestedName * @return null|\stdClass * @throws Exception\RuntimeException If resolved class does not exist, or does not implement RouteInterface */ protected function createFromInvokable($canonicalName, $requestedName) { $invokable = $this->invokableClasses[$canonicalName]; if (!class_exists($invokable)) { throw new Exception\RuntimeException(sprintf( '%s: failed retrieving "%s%s" via invokable class "%s"; class does not exist', __METHOD__, $canonicalName, ($requestedName ? '(alias: ' . $requestedName . ')' : ''), $invokable )); } if (!static::isSubclassOf($invokable, __NAMESPACE__ . '\RouteInterface')) { throw new Exception\RuntimeException(sprintf( '%s: failed retrieving "%s%s" via invokable class "%s"; class does not implement %s\RouteInterface', __METHOD__, $canonicalName, ($requestedName ? '(alias: ' . $requestedName . ')' : ''), $invokable, __NAMESPACE__ )); } return $invokable::factory($this->creationOptions); } }