[Beeframework-svn] SF.net SVN: beeframework:[39] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2013-06-12 14:14:15
|
Revision: 39 http://sourceforge.net/p/beeframework/code/39 Author: m_plomer Date: 2013-06-12 14:14:12 +0000 (Wed, 12 Jun 2013) Log Message: ----------- - minor fixes Modified Paths: -------------- trunk/framework/Bee/Context/Xml/BeanDefinitionReader.php trunk/framework/Bee/Utils/Env.php Modified: trunk/framework/Bee/Context/Xml/BeanDefinitionReader.php =================================================================== --- trunk/framework/Bee/Context/Xml/BeanDefinitionReader.php 2013-06-06 14:40:44 UTC (rev 38) +++ trunk/framework/Bee/Context/Xml/BeanDefinitionReader.php 2013-06-12 14:14:12 UTC (rev 39) @@ -63,7 +63,10 @@ try { $document = new DOMDocument(); $document->load($location); - $this->registerBeanDefinitions($document); + if (is_null($document->documentElement)) { + throw new Exception('Failed to load XML document: '.$location); + } + $this->registerBeanDefinitions($document); } catch (Exception $ex) { unset($this->resourcesBeingLoaded[$location]); throw $ex; Modified: trunk/framework/Bee/Utils/Env.php =================================================================== --- trunk/framework/Bee/Utils/Env.php 2013-06-06 14:40:44 UTC (rev 38) +++ trunk/framework/Bee/Utils/Env.php 2013-06-12 14:14:12 UTC (rev 39) @@ -23,25 +23,24 @@ */ class Bee_Utils_Env { - const PATH_INFO = 'PATH_INFO'; - const ORIG_PATH_INFO = 'ORIG_PATH_INFO'; + const PATH_INFO = 'PATH_INFO'; + const ORIG_PATH_INFO = 'ORIG_PATH_INFO'; - public static $USER_AGENTS = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape', 'konqueror', 'gecko'); - + public static $USER_AGENTS = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape', 'konqueror', 'gecko'); + private static $pathInfo; private static $absoluteBasePath; private static $basePath; private static $dispatcher; private static $applicationPath; private static $php_self; - /** - * @var Bee_Utils_UserAgent - */ - private static $userAgent; - - - /** + * @var Bee_Utils_UserAgent + */ + private static $userAgent; + + + /** * The basePath is the path to the root of the webserver. * It is likely to be extended by a customer-id or user- * name. @@ -50,14 +49,14 @@ */ public static final function getAbsoluteBasePath() { if (is_null(self::$absoluteBasePath)) { - self::$absoluteBasePath = self::getWebserverDocumentRoot().'/'; - $basePath = self::getBasePath(); + self::$absoluteBasePath = self::getWebserverDocumentRoot() . '/'; + $basePath = self::getBasePath(); - if (Bee_Utils_Strings::hasText(self::$absoluteBasePath) && Bee_Utils_Strings::hasText($basePath) && !preg_match('#'.DIRECTORY_SEPARATOR.'$#i', self::$absoluteBasePath) && !preg_match('#^'.DIRECTORY_SEPARATOR.'#i', $basePath)) { - echo 'MUST ADD THE THING!!!!<br/>'; - self::$absoluteBasePath .= DIRECTORY_SEPARATOR; - } - self::$absoluteBasePath .= $basePath; + if (Bee_Utils_Strings::hasText(self::$absoluteBasePath) && Bee_Utils_Strings::hasText($basePath) && !preg_match('#' . DIRECTORY_SEPARATOR . '$#i', self::$absoluteBasePath) && !preg_match('#^' . DIRECTORY_SEPARATOR . '#i', $basePath)) { + echo 'MUST ADD THE THING!!!!<br/>'; + self::$absoluteBasePath .= DIRECTORY_SEPARATOR; + } + self::$absoluteBasePath .= $basePath; } return self::$absoluteBasePath; } @@ -72,18 +71,16 @@ public static final function getBasePath() { if (is_null(self::$basePath)) { self::$basePath = dirname(self::getPhpSelf()); - if (self::$basePath[0]==DIRECTORY_SEPARATOR) { + if (self::$basePath[0] == DIRECTORY_SEPARATOR) { self::$basePath = substr(self::$basePath, 1); } - if (self::$basePath==false) { + if (self::$basePath == false) { self::$basePath = ''; } } return self::$basePath; } - - /** * The applicationIndex is the .php file that will be the * entry page for the application @@ -92,31 +89,32 @@ */ public static final function getDispatcher() { if (is_null(self::$dispatcher)) { - self::$dispatcher = pathinfo(self::getPhpSelf(), PATHINFO_FILENAME).'.'.pathinfo(self::getPhpSelf(), PATHINFO_EXTENSION); + self::$dispatcher = pathinfo(self::getPhpSelf(), PATHINFO_FILENAME) . '.' . pathinfo(self::getPhpSelf(), PATHINFO_EXTENSION); } return self::$dispatcher; } - public static final function getApplicationIndex() { - return self::getDispatcher(); - } + public static final function getApplicationIndex() { + return self::getDispatcher(); + } - /** * The applicationPath is the path where the customized * application components and views lie. * + * @param bool $absolute * @return String */ - public static final function getApplicationPath() { + public static final function getApplicationPath($absolute = false) { if (is_null(self::$applicationPath)) { - self::$applicationPath = pathinfo(self::getPhpSelf(), PATHINFO_FILENAME); + self::$applicationPath = pathinfo(self::getPhpSelf(), PATHINFO_DIRNAME); } - return self::$applicationPath; + if (!$absolute) { + return self::$applicationPath; + } + return preg_replace('#' . DIRECTORY_SEPARATOR . '+#', DIRECTORY_SEPARATOR, self::getWebserverDocumentRoot() . DIRECTORY_SEPARATOR . self::$applicationPath); } - - /** * The webserverDocumentRoot is the path to the document * root directory of the webserver. @@ -127,8 +125,6 @@ return $_SERVER['DOCUMENT_ROOT']; } - - /** * The URL to the server * @@ -136,11 +132,11 @@ */ public static final function getProtocol() { $protocol = $_SERVER['HTTP_REFERER']; - $pos = strpos($protocol, '://'); - if ($pos===false) { - return 'http'; - } - return substr($protocol, 0, $pos); + $pos = strpos($protocol, '://'); + if ($pos === false) { + return 'http'; + } + return substr($protocol, 0, $pos); } /** @@ -163,7 +159,7 @@ // strip port number from host name (this should probably only be necessary when HTTP_HOST was used) $colPos = strpos($host, ':'); - if($colPos !== false) { + if ($colPos !== false) { $host = substr($host, 0, $colPos); } @@ -172,19 +168,18 @@ public static function getPhpSelf() { if (is_null(self::$php_self)) { - self::$php_self = substr($_SERVER["PHP_SELF"], 0, stripos($_SERVER["PHP_SELF"], '.php')+4); + self::$php_self = substr($_SERVER["PHP_SELF"], 0, stripos($_SERVER["PHP_SELF"], '.php') + 4); } return self::$php_self; } - - + /** - * Usage of this method is really discouraged, since + * Usage of this method is really discouraged, since * * @return String */ public static function getHtmlBase() { - $base = 'http://'; + $base = 'http://'; $base .= self::getHost(); $base .= '/'; try { @@ -195,8 +190,8 @@ } return $base; } - - + + /** * Returns the PATH_INFO (i.e. any additional path trailing the actual PHP file) * @@ -206,102 +201,101 @@ /** * Original code: * $pathInfo = $_SERVER['PATH_INFO']; - * - * + * + * * On some servers "PATH_INFO" is set in $_SERVER['ORIG_PATH_INFO']. If there is no * extra path set, $_SERVER['ORIG_PATH_INFO'] will contain the script name, which - * is also set in $_SERVER['ORIG_SCRIPT_NAME'] or $_SERVER['SCRIPT_NAME']. + * is also set in $_SERVER['ORIG_SCRIPT_NAME'] or $_SERVER['SCRIPT_NAME']. */ if (is_null(self::$pathInfo)) { - $pathInfo = array_key_exists(self::PATH_INFO, $_SERVER) ? $_SERVER[self::PATH_INFO] : null; - if(Bee_Utils_Strings::hasText($pathInfo)) { + $pathInfo = array_key_exists(self::PATH_INFO, $_SERVER) ? $_SERVER[self::PATH_INFO] : null; + if (Bee_Utils_Strings::hasText($pathInfo)) { self::$pathInfo = $pathInfo; - + } else { - $pathInfo = array_key_exists(self::ORIG_PATH_INFO, $_SERVER) ? $_SERVER[self::ORIG_PATH_INFO] : null; - if(Bee_Utils_Strings::hasText($pathInfo)) { - if ($pathInfo == $_SERVER['ORIG_SCRIPT_NAME']) { - return ''; - } - if ($pathInfo == $_SERVER['SCRIPT_NAME']) { - return ''; - } - self::$pathInfo = $pathInfo; - } - } + $pathInfo = array_key_exists(self::ORIG_PATH_INFO, $_SERVER) ? $_SERVER[self::ORIG_PATH_INFO] : null; + if (Bee_Utils_Strings::hasText($pathInfo)) { + if ($pathInfo == $_SERVER['ORIG_SCRIPT_NAME']) { + return ''; + } + if ($pathInfo == $_SERVER['SCRIPT_NAME']) { + return ''; + } + self::$pathInfo = $pathInfo; + } + } } return self::$pathInfo; } - + public static function getRequestHeaders($uppercaseKeys = false) { - if(function_exists('apache_request_headers')) { + if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { - $phpSupportedHeaders = array ( + $phpSupportedHeaders = array( 'HTTP_ACCEPT' => 'Accept', 'HTTP_ACCEPT_CHARSET' => 'Accept-Charset', 'HTTP_ACCEPT_ENCODING' => 'Accept-Encoding', - 'HTTP_ACCEPT_LANGUAGE' => 'Accept-Language', - 'HTTP_CONNECTION' => 'Connection', - 'HTTP_HOST' => 'Host', - 'HTTP_REFERER' => 'Referer', - 'HTTP_USER_AGENT' => 'User-Agent' + 'HTTP_ACCEPT_LANGUAGE' => 'Accept-Language', + 'HTTP_CONNECTION' => 'Connection', + 'HTTP_HOST' => 'Host', + 'HTTP_REFERER' => 'Referer', + 'HTTP_USER_AGENT' => 'User-Agent' ); $headers = array(); - foreach($phpSupportedHeaders as $key => $val) { - if(array_key_exists($key, $_SERVER)) { + foreach ($phpSupportedHeaders as $key => $val) { + if (array_key_exists($key, $_SERVER)) { $headers[$val] = $_SERVER[$key]; } } } - if($uppercaseKeys) { + if ($uppercaseKeys) { $headers = array_change_key_case($headers, CASE_UPPER); } return $headers; } - /** - * @static - * @return Bee_Utils_UserAgent - */ - public static function getUserAgent() { - if (!self::$userAgent) { - // Clean up agent and build regex that matches phrases for known browsers - // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor - // version numbers. E.g. "2.0.0.6" is parsed as simply "2.0" + /** + * @static + * @return Bee_Utils_UserAgent + */ + public static function getUserAgent() { + if (!self::$userAgent) { + // Clean up agent and build regex that matches phrases for known browsers + // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor + // version numbers. E.g. "2.0.0.6" is parsed as simply "2.0" - self::$userAgent = new Bee_Utils_UserAgent(); + self::$userAgent = new Bee_Utils_UserAgent(); - $userAgents = self::$USER_AGENTS; - $userAgents[] = 'version'; - $agent = ''; + $userAgents = self::$USER_AGENTS; + $userAgents[] = 'version'; + $agent = ''; - $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']); - $pattern = '#(?<browser>'.join('|', $userAgents).')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#'; + $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']); + $pattern = '#(?<browser>' . join('|', $userAgents) . ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#'; - // Find all phrases (or return empty array if none found) - if (!preg_match_all($pattern, $agent, $matches)) { - self::$userAgent->setName('unknown'); - self::$userAgent->setVersion(0); - } else { + // Find all phrases (or return empty array if none found) + if (!preg_match_all($pattern, $agent, $matches)) { + self::$userAgent->setName('unknown'); + self::$userAgent->setVersion(0); + } else { - // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase, - // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one - // in the UA). That's usually the most correct. - $i = count($matches['browser'])-1; + // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase, + // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one + // in the UA). That's usually the most correct. + $i = count($matches['browser']) - 1; - self::$userAgent->setName($matches['browser'][$i]); + self::$userAgent->setName($matches['browser'][$i]); - $version = $matches['version'][$i]; - if (in_array('version', $matches['browser'])) { - $version = $matches['version'][$i-1]; - } + $version = $matches['version'][$i]; + if (in_array('version', $matches['browser'])) { + $version = $matches['version'][$i - 1]; + } - self::$userAgent->setVersion($version); - } - } - return self::$userAgent; - } + self::$userAgent->setVersion($version); + } + } + return self::$userAgent; + } } -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |