<?php
namespace Moto\Website; use Moto; use Moto\Application\Pages\PagesTable; class Pages { protected static $_repository = []; public static function getRelativeUrl($id) { $page = static::find($id); if (!$page) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_NOT_FOUND_MESSAGE, Moto\System\Exception::ERROR_NOT_FOUND_CODE); } return $page->getRelativeUrl(); } public static function getAbsoluteUrl($id) { $page = static::find($id); if (!$page) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_NOT_FOUND_MESSAGE, Moto\System\Exception::ERROR_NOT_FOUND_CODE); } return $page->getAbsoluteUrl(); } public static function getInnerUrl($id) { $page = static::find($id); if (!$page) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_NOT_FOUND_MESSAGE, Moto\System\Exception::ERROR_NOT_FOUND_CODE); } return $page->getInnerUrl(); } public static function find($id) { $id = (int) $id; if (array_key_exists($id, static::$_repository)) { return static::$_repository[$id]; } $table = Moto\System::getDbTable('pages'); $table->useResultAsModel(true); $page = $table->getById($id); static::$_repository[$id] = $page; return $page; } public static function remember($target) { if ($target instanceof Moto\Application\Pages\PageModel) { if (!array_key_exists($target->id, static::$_repository)) { static::$_repository[$target->id] = $target; } return true; } return false; } public static function forgot($target) { if ($target instanceof Moto\Application\Pages\PageModel) { unset(static::$_repository[$target->id]); } elseif ($target > 0) { unset(static::$_repository[(int) $target]); } } } 