/** * Assemble a new Request object by parsing the data in the $_SERVER array * * @return \Hynage\HTTP\Request */ public static function getCurrent() { $scheme = isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; $port = (int) $_SERVER['SERVER_PORT']; $path = $_SERVER['REQUEST_URI']; $url = sprintf('%s://%s%s%s', $scheme, $host, 80 == $port ? '' : ':' . $port, $path); $url = new self($url); foreach ($_GET as $key => $value) { $url->setParam($key, $value, self::METHOD_GET); } foreach ($_POST as $key => $value) { $url->setParam($key, $value, self::METHOD_POST); } return $url; }
/** * @param $name * @param $subject * @param Configuration $configuration * @param array $params * * @return FormEvent */ public static function create($name, $subject, $configuration, $params = array()) { $event = new self($name, $subject); $event->setConfiguration($configuration); foreach ($params as $key => $value) { $event->setParam($key, $value); } return $event; }
static function filename($filename = "") { global $tikilib; $id = $tikilib->getOne("SELECT fileId FROM tiki_files WHERE filename = ? AND archiveId < 1", array($filename)); if (!empty($id)) { return FileGallery_File::id($id); } //always use ->exists() to check if the file was found, if the above is returned, a file was found, if below, there wasent $me = new self(); $me->setParam('filename', $filename); return $me; }
/** * Static method to parse a docblock string and return a new * docblock generator object. * * @param string $docblock * @param string $forceIndent * @throws Exception * @return DocblockGenerator */ public static function parse($docblock, $forceIndent = null) { if (strpos($docblock, '/*') === false || strpos($docblock, '*/') === false) { throw new Exception('The docblock is not in the correct format.'); } $desc = null; $formattedDesc = null; $indent = null; $tags = null; // Parse the description, if any if (strpos($docblock, '@') !== false) { $desc = substr($docblock, 0, strpos($docblock, '@')); $desc = str_replace('/*', '', $desc); $desc = str_replace('*/', '', $desc); $desc = str_replace(PHP_EOL . ' * ', ' ', $desc); $desc = trim(str_replace('*', '', $desc)); $descAry = explode("\n", $desc); $formattedDesc = null; foreach ($descAry as $line) { $formattedDesc .= ' ' . trim($line); } $formattedDesc = trim($formattedDesc); } // Get the indentation, if any, and create docblock object $indent = null === $forceIndent ? substr($docblock, 0, strpos($docblock, '/')) : $forceIndent; $newDocblock = new self($formattedDesc, $indent); // Get the tags, if any if (strpos($docblock, '@') !== false) { $tags = substr($docblock, strpos($docblock, '@')); $tags = substr($tags, 0, strpos($tags, '*/')); $tags = str_replace('*', '', $tags); $tagsAry = explode("\n", $tags); foreach ($tagsAry as $key => $value) { $value = trim(str_replace('@', '', $value)); // Param tags if (stripos($value, 'param') !== false) { $paramtag = trim(str_replace('param', '', $value)); $paramtype = trim(substr($paramtag, 0, strpos($paramtag, ' '))); $varname = null; $paramdesc = null; if (strpos($paramtag, ' ') !== false) { $varname = trim(substr($paramtag, strpos($paramtag, ' '))); if (strpos($varname, ' ') !== false) { $paramdesc = trim(substr($varname, strpos($varname, ' '))); } } else { $paramtype = $paramtag; } $newDocblock->setParam($paramtype, $varname, $paramdesc); // Else, return tags } else { if (stripos($value, 'return') !== false) { $returntag = trim(str_replace('return', '', $value)); if (strpos($returntag, ' ') !== false) { $returntype = substr($returntag, 0, strpos($returntag, ' ')); $returndesc = trim(str_replace($returntype, '', $returntag)); } else { $returntype = $returntag; $returndesc = null; } $newDocblock->setReturn($returntype, $returndesc); // Else, all other tags } else { $tagname = trim(substr($value, 0, strpos($value, ' '))); $tagdesc = trim(str_replace($tagname, '', $value)); if (!empty($tagname) && !empty($tagdesc)) { $newDocblock->setTag($tagname, $tagdesc); } else { unset($tagsAry[$key]); } } } } } return $newDocblock; }