/** * Get a page type by file path. * * @param string $file_path * * @return Papi_Page_Type */ function papi_get_page_type($file_path) { if (!is_file($file_path) || !is_string($file_path)) { return; } $class_name = papi_get_class_name($file_path); if (empty($class_name)) { return; } // Try to add the page type to the container. if (!papi()->exists($class_name)) { // @codeCoverageIgnoreStart if (!class_exists($class_name)) { require_once $file_path; } // @codeCoverageIgnoreEnd $rc = new ReflectionClass($class_name); $page_type = $rc->newInstanceArgs([$file_path]); // If the page type don't have a name we can't use it. if (!$page_type->has_name()) { return; } papi()->singleton($class_name, $page_type); } return papi()->make($class_name); }
/** * Load the file and setup file path, file name and class name properties. * * @param string $file_path */ private function setup_file($file_path) { $this->_file_path = $file_path; $this->_class_name = papi_get_class_name($this->_file_path); }
/** * Get a entry type by file path. * * @param string $file_path * * @return Papi_Entry_Type */ function papi_get_entry_type($file_path) { if (!is_file($file_path) || !is_string($file_path)) { return; } $id = papi_get_core_type_base_path($file_path); // Check if file path is changed. if ($id === $file_path) { return; } if (!papi()->exists($id)) { $class_name = papi_get_class_name($file_path); // @codeCoverageIgnoreStart if (!class_exists($class_name)) { require_once $file_path; } if (!class_exists($class_name)) { return; } // @codeCoverageIgnoreEnd $rc = new ReflectionClass($class_name); // Bail if not instantiable. if (!$rc->isInstantiable()) { return; } $entry_type = $rc->newInstanceArgs([$file_path]); // If the entry type don't have a name we can't use it. if (!$entry_type->has_name()) { return; } papi()->singleton($id, $entry_type); } return papi()->make($id); }