public static function getPath($templateName) { if (self::$paths === false) { self::init(); } $filePath = self::$paths->find($templateName . self::$ext); if ($filePath === false) { throw new Exception('Could not locate template: ' . $templateName); } return $filePath; }
/** * Returns a multi-dimensional array that describes the inputs * of an assertive template. Data available: * array[$inputName]['required'] = boolean * array[$inputName]['type'] = string type representation * array[$inputName]['default'] = string default value * * @param string Part name relative to AssertiveTemplate's paths. * @param string The class name to look for, i.e. for Part::input 'Part', Layout::input 'Layout' * @returns array Representation of required inputs. */ public static function getInputs($template, $class = 'AssertiveTemplate') { if (!isset(self::$loaded[$template])) { $cacheKey = 'AssertiveTemplate::inputs::' . $template; if (($inputs = Cache::get($cacheKey)) !== false) { self::$loaded[$template] = $inputs; } else { if (self::$paths === false) { self::init(); } $templateFile = self::$paths->find($template); if ($templateFile === false) { throw new RecessFrameworkException("The file \"{$template}\" does not exist.", 1); } $file = file_get_contents($templateFile); $pattern = self::getInputRegex($class); preg_match_all($pattern, $file, $matches); $inputs = array(); foreach ($matches[0] as $key => $value) { $input = array(); $name = $matches[1][$key]; $input['type'] = $matches[2][$key]; $input['required'] = !isset($matches[3][$key]) || $matches[3][$key] === ''; if (!$input['required']) { $input['default'] = $matches[3][$key]; } else { $input['default'] = null; } $inputs[$name] = $input; } self::$loaded[$template] = $inputs; Cache::set($cacheKey, $inputs); } } return self::$loaded[$template]; }