/** * 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); }
/** * Get the page type identifier. * * @return string */ public function get_id() { return papi_get_core_type_base_path($this->_file_path); }
/** * 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->_file_name = papi_get_core_type_base_path($this->_file_path); $this->_class_name = papi_get_class_name($this->_file_path); }