/** * Constructor * * This shouldn't be called directly * * @see DatabaseObject::meta * * @param class string */ function __construct($class) { $members = array(); $refcls = new ReflectionClass($class); foreach ($refcls->getProperties() as $prop) { $name = $prop->getName(); switch ($name) { case 'table': case 'key': if (!$prop->isStatic() && Site::Site()->isDebugMode()) { trigger_error("{$class}->{$name} should be {$class}::\${$name}"); } $this->{$name} = $prop->getValue(); break; default: if (!$prop->isStatic()) { array_push($members, $name); } break; } } if (!isset($this->key)) { throw new RuntimeException("Cannot determine database key for {$class}"); } parent::__construct($class, $members); }
public function __construct($class) { $refcls = new ReflectionClass($class); $members = array(); foreach ($refcls->getProperties() as $prop) { $name = $prop->getName(); switch ($name) { case 'table': case 'FromClass': case 'ToClass': case 'LinkOrderClause': case 'AdditionalKey': if (!$prop->isStatic() && Site::Site()->isDebugMode()) { throw new RuntimeException("{$class}->{$name} should be {$class}::\${$name}"); } $m = strtolower($name[0]) . substr($name, 1); $v = $prop->getValue(); if ($name == 'FromClass' || $name == 'ToClass') { if (!class_exists($v) || !is_subclass_of($v, 'DatabaseObject')) { throw new RuntimeException("{$v} is not a DatabaseObject class"); } } $this->{$m} = $v; break; default: if (!$prop->isStatic()) { array_push($members, $name); } break; } } if (!isset($this->fromClass)) { throw new RuntimeException("Cannot determine database fromClass for {$class}"); } if (!isset($this->toClass)) { throw new RuntimeException("Cannot determine database toClass for {$class}"); } parent::__construct($class, $members); $this->inspectColumn($this->getFromKey()); $this->inspectColumn($this->getToKey()); if (isset($this->additionalKey)) { $man = isset($this->manualColumns) ? $this->manualColumns : array(); $this->manualColumns = array_unique(array_merge($man, $this->additionalKey)); foreach ($this->additionalKey as $col) { $this->inspectColumn($col); } } }
public function __construct(PHPSTLTemplateProvider $provider, $resource, $identifier) { parent::__construct($provider, $resource, $identifier); $this->path = new StupidPath(Site::Site()->url); if (substr($identifier, 0, 7) == 'file://') { $path = dirname(substr($identifier, 7)); $pl = strlen($path); foreach (array(Loader::$FrameworkPath . '/', Loader::$Base . '/') as $p) { $l = strlen($p); if ($pl > $l && substr($path, 0, $l) == $p) { $this->path = $this->path->down(substr($path, $l)); break; } } } }
/** * Builds a standardized directory structure given an object code and action. * This takes the values of $_GET and $_POST into account for a truly unique * cache per request. * * @static * @access private * @param ICacheable $obj the object that implements ICacheable * @return string a directory in which to cache for the current request or false if it couldn't */ private static function getCacheDirectory(ICacheable &$obj) { $params = get_class($obj); $request = array_merge($_GET, $_POST); foreach ($request as $name => $value) { $params .= is_array($name) ? implode(',', $name) : $name; $params .= is_array($value) ? implode(',', $value) : $value; } // TODO allow other parts of the system to params, used by a Login // module to make cache specific per user here $site = Site::Site(); $cacheDir = $site->layout->getCacheArea('objects'); $path = "{$cacheDir}/objects/" . md5($params); if (!file_exists($path)) { if (!@mkdir($path, 0775, true)) { Site::getLog()->error("unable to make dir {$path}"); return false; } } return $path; }
/** * Returns text in href form suitable for linking to other actions within the framework. * * @access public * @param string a component class name * @param int $action the action id you want to link to, defaults to the current action * @param array $options an associative array of parameters to pass to the action. You may set * -textalize to true if you are using the text directly (ie not in an href). This * option will be removed from the final link, but does not do encoding transformations * such as & => &. * * -popup indicates a popup window * -secure indicates a secure link * * @param int $stage the stage you want to link to, default Stage::VIEW * @return string text to use in an href upon success; null upon failure */ public function getActionURI($action = null, $options = array(), $stage = Stage::VIEW) { if (!isset($action)) { $action = $this->action->id; } if (!isset($stage)) { $stage = $this->stage; } // TODO this is a historical conversion, it won't work at all currently $component = urlencode(get_class($this)); $site = Site::Site(); $link = $site->serverUrl . $site->url; $a = $this->getAction($action); if (!$a) { throw new InvalidArgumentException("unknown action {$component}.{$action}"); } if (!$a instanceof ActionDescription) { throw new InvalidArgumentException("bad action {$component}.{$action}"); } $link = $this->replaceProto($link, (bool) $a->requiresSSL); $path = array(); array_push($path, self::$ComponentKey, $component); if ($action) { array_push($path, self::$ActionKey, $action); } if ($stage) { array_push($path, self::$StageKey, $stage); } $link .= '/' . implode('/', $path); return $link; /* TODO rewrite, this, just use http_build_query, needs secure page handling * to be reimplemented, and also depends on the currently nebulous idea of a * "page form factor". * * // if we're a popup, other links should be popups * if (!array_key_exists('-popup', $options) && Params::request(AppConstants::POPUP_KEY)) { * $options[AppConstants::POPUP_KEY] = 1; * } * * $qs = ''; * foreach ($options as $kw => $val) { * if ($kw[0] == '-') { * switch ($kw) { * case '-popup': * $kw = AppConstants::POPUP_KEY; * break; * case '-secure': * $kw = AppConstants::SECURE_KEY; * break; * } * } * if ($val === null) { * continue; * } * // -secure takes precendence over The Action Rule * if ($kw == AppConstants::SECURE_KEY) { * $link = $this->replaceProto($link, (bool) $val); * } * $kw = urlencode($kw); * $val = urlencode($val); * // the query string rule: apache will freak out if %2F is part of the url * if (false !== strpos($val, '%2F')) { * $qs .= "&$kw=$val"; * } * else { * $link .= "/$kw/$val"; * } * } * *if ($qs) { * $qs[0] = '?'; *} */ }
public function __construct($url) { $url = Site::Site()->rel2abs($url); $this->url = $url; parent::__construct("Redirect to {$url}"); }
/** * Constructs a new curent url * * @param path string */ public function __construct($path, $url = null) { if ($path instanceof StupidPath) { $this->path = $path; } else { $path = realpath($path); // Strip trailing slash if ($path[strlen($path) - 1] == '/') { $path = substr($path, 0, strlen($path) - 1); } $this->path = new StupidPath(explode('/', $path)); } if ($url instanceof StupidPath) { $this->url = $url; } else { if (!isset($url)) { $url = (string) $this->path; } $bl = strlen(Loader::$Base); if (substr($url, 0, $bl) == Loader::$Base) { $url = substr($url, $bl); $url = explode('/', $url); // TODO Intropsect Loader variables and the site's url base, and // determine the framework path thusly if (count($url) >= 1 && $url[0] == 'framework') { $url = array_slice($url, 1); } elseif (count($url) >= 2 && $url[0] == '' && $url[1] == 'framework') { $url = array_slice($url, 2); } if ($url[0] == '') { array_shift($url); } $this->url = new StupidPath(array_merge(explode('/', Site::Site()->url), $url)); } } }