/** * returns the parameter map of the given callback, it filters out entries typed as Dwoo and Compiler and turns the rest parameter into a "*" * * @param callback $callback the function/method to reflect on * * @return array processed parameter map */ protected function getParamMap($callback) { if (is_null($callback)) { return array(array('*', true)); } if (is_array($callback)) { $ref = new \ReflectionMethod(Core::underscoreToCamel($callback[0]), $callback[1]); } else { $ref = new \ReflectionFunction($callback); } $out = array(); foreach ($ref->getParameters() as $param) { if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\\Core') { continue; } if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\\Compiler') { continue; } if ($param->getName() === 'rest' && $param->isArray() === true) { $out[] = array('*', $param->isOptional(), null); continue; } $out[] = array($param->getName(), $param->isOptional(), $param->isOptional() ? $param->getDefaultValue() : null); } return $out; }
/** * loads a plugin file * * @param string $class the plugin name, without the prefix (Block|block|Function|function) * @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it has just been added, defaults to true * * @return bool * @throws Exception\PluginException */ public function loadPlugin($class, $forceRehash = true) { // An unknown class was requested (maybe newly added) or the // include failed so we rebuild the cache. include() will fail // with an uncatchable error if the file doesn't exist, which // usually means that the cache is stale and must be rebuilt, // so we check for that before trying to include() the plugin. // Convert class name to CamelCase $class = Core::underscoreToCamel($class); // Check entry exist in $this->classPath $match = preg_grep('/^(Block|block|Function|function)?(' . $class . '+)/i', array_keys($this->classPath)); $index = array_values($match); // Entry doesn't exist, try to rebuild cache $included_files = get_included_files(); if (!isset($index[0]) || !isset($this->classPath[$index[0]]) || !is_readable($this->classPath[$index[0]]) || !in_array($this->classPath[$index[0]], $included_files)) { if ($forceRehash) { // Rebuild cache $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php'); foreach ($this->paths as $path => $file) { $this->rebuildClassPathCache($path, $file); } // Check entry exist after rebuilding cache $match = preg_grep('/^(Block|block|Function|function)?(' . $class . '+)/i', array_keys($this->classPath)); $index = array_values($match); if (isset($index[0])) { if (isset($this->classPath[$index[0]])) { include $this->classPath[$index[0]]; return true; } } } throw new PluginException(sprintf(PluginException::FORGOT_BIND, $class), E_USER_NOTICE); return false; } return false; }