/**
  * Returns whether the given file name ends with the file extension
  * configured for the storage.
  *
  * @param string $fileName The file name to check
  * @return bool TRUE if the given file name matches the file extension configured for the storage, FALSE otherwise
  */
 private function hasStorageFileExtension(string $fileName)
 {
     return $this->fileExtension === '' || StringUtil::endsWith($fileName, $this->fileExtension);
 }
Example #2
0
 /**
  * Returns the environment variable SCRIPT_FILENAME which represents the
  * absolute pathname of the currently executing script.
  *
  * @see http://stackoverflow.com/questions/5001326/php-strange-document-root
  * @return mixed
  */
 public static function getScriptFileName()
 {
     return CacheUtil::getFromCache(self::getCache(), __FUNCTION__, function () {
         if (self::isCliRequest()) {
             return self::getScriptName();
         }
         $scriptName = FileUtil::normalizePath(dirname(self::getScriptName()));
         while (!StringUtil::endsWith(ABLERON_ROOT_DIR, $scriptName) && $scriptName !== '/') {
             $scriptName = FileUtil::normalizePath(dirname($scriptName));
         }
         return ($scriptName === '/' ? ABLERON_ROOT_DIR : StringUtil::getSubstring(ABLERON_ROOT_DIR, 0, StringUtil::getLastIndexOf(ABLERON_ROOT_DIR, $scriptName))) . self::getScriptName();
     });
 }
Example #3
0
 /**
  * Removes the given enclosing characters from the start and the end of the given input string
  * in case the string is enclosed by the given characters.
  *
  * E.g. removeEnclosingCharacter('{{foo}}', '{{', '}}') will return 'foo';
  *
  * Returns the input string without any modification in case the given input string
  * is not enclosed by the given characters.
  *
  * @param string $inputString The input string to remove the enclosing characters from
  * @param string $enclosingStartCharactersToRemove The start characters to remove from the start of the string if string is enclosed by the given characters
  * @param string $enclosingEndCharactersToRemove The end characters to remove from the end of the string if string is enclosed by the given characters
  * @return string
  */
 public static function removeEnclosingCharacters(string $inputString, string $enclosingStartCharactersToRemove, string $enclosingEndCharactersToRemove)
 {
     // return input string with removed given enclosing characters
     if (StringUtil::startsWith($inputString, $enclosingStartCharactersToRemove) && StringUtil::endsWith($inputString, $enclosingEndCharactersToRemove)) {
         return StringUtil::getSubstring($inputString, self::getLength($enclosingStartCharactersToRemove), -self::getLength($enclosingEndCharactersToRemove));
     }
     // return unmodified input string if not enclosed by the given characters
     return $inputString;
 }
Example #4
0
 /**
  * Sets up this object by parsing the given string representation of a URI.
  *
  * Throws an exception in case the given string could not be parsed correctly.
  *
  * @param string $uri The URI to parse
  * @throws \Ableron\Core\Exception\SystemException
  * @return void
  */
 private function parseUri($uri)
 {
     if (($uriComponents = parse_url(StringUtil::startsWith($uri, '//') ? 'http:' . $uri : $uri)) !== false) {
         // set scheme
         if (isset($uriComponents['scheme']) && !StringUtil::startsWith($uri, '//')) {
             $this->setScheme($uriComponents['scheme']);
         }
         // set user info
         $isUsernameSet = isset($uriComponents['user']) && $uriComponents['user'] !== '';
         $isPasswordSet = isset($uriComponents['pass']) && $uriComponents['pass'] !== '';
         if ($isUsernameSet || $isPasswordSet) {
             $this->setUserInfo(($isUsernameSet ? $uriComponents['user'] : '') . ($isPasswordSet ? ':' . $uriComponents['pass'] : ''));
         }
         // set host
         if (isset($uriComponents['host'])) {
             $this->setHost($uriComponents['host']);
         }
         // set port
         if (isset($uriComponents['port'])) {
             $this->setPort($uriComponents['port']);
         }
         // set path
         if (isset($uriComponents['path'])) {
             $this->setPath($uriComponents['path']);
         }
         // set fragment
         if (isset($uriComponents['fragment'])) {
             $this->setFragment($uriComponents['fragment']);
         } elseif (StringUtil::endsWith($uri, '#')) {
             $this->setFragment('', true);
         }
         // set query (it is necessary to set the query after the fragment as we need the fragment part here)
         if (isset($uriComponents['query'])) {
             $this->setQuery($uriComponents['query']);
         } elseif (StringUtil::endsWith($uri, '?' . ($this->fragment !== null ? '#' . $this->fragment : ''))) {
             $this->setQuery('', true);
         }
     } else {
         throw new SystemException(sprintf('Unable to parse URI: %s', $uri), 0, E_USER_NOTICE, __FILE__, __LINE__);
     }
 }
 /**
  * Checks whether the given request data matches the given base URL data.
  *
  * Returns TRUE in case the given request data matches the given base URL
  * data.
  * Otherwise returns FALSE.
  *
  * @param string $baseUrlHost Host name of the base URL
  * @param string $baseUrlPath Path of the base URL
  * @param string $requestHost Host name of the request to check
  * @param string $requestPath Path of the request to check
  * @return bool
  */
 private function requestMatchesBaseUrl($baseUrlHost, $baseUrlPath, $requestHost, $requestPath)
 {
     // check whether host matches
     if ($requestHost !== $baseUrlHost && !StringUtil::endsWith($requestHost, '.' . $baseUrlHost)) {
         return false;
     }
     // check whether path matches
     if ($requestPath !== $baseUrlPath && !StringUtil::startsWith($requestPath, $baseUrlPath . '/')) {
         return false;
     }
     // given request data matches given base URL data
     return true;
 }