Пример #1
0
 /**
  * Initializes the manager
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function initializeObject()
 {
     $this->lockPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'FLOW3.lock';
     if (file_exists($this->lockPathAndFilename)) {
         if (filemtime($this->lockPathAndFilename) < time() - self::LOCKFILE_MAXIMUM_AGE) {
             unlink($this->lockPathAndFilename);
         } else {
             $this->siteLocked = TRUE;
         }
     }
 }
Пример #2
0
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \F3\FLOW3\Cache\Frontend\FrontendInterface $cache
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function setCache(\F3\FLOW3\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
     $pathHash = substr(md5(FLOW3_PATH_WEB . $this->environment->getSAPIName() . $processUser['name'] . $this->context), 0, 12);
     $this->identifierPrefix = 'FLOW3_' . $pathHash;
 }
 /**
  * Takes the raw request data and - depending on the request method
  * maps them into the request object. Afterwards all mapped arguments
  * can be retrieved by the getArgument(s) method, no matter if they
  * have been GET, POST or PUT arguments before.
  *
  * @param \F3\FLOW3\MVC\Web\Request $request The web request which will contain the arguments
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function setArgumentsFromRawRequestData(\F3\FLOW3\MVC\Web\Request $request)
 {
     foreach ($request->getRequestUri()->getArguments() as $argumentName => $argumentValue) {
         $request->setArgument($argumentName, $argumentValue);
     }
     switch ($request->getMethod()) {
         case 'POST':
             foreach ($this->environment->getRawPostArguments() as $argumentName => $argumentValue) {
                 $request->setArgument($argumentName, $argumentValue);
             }
             foreach ($this->environment->getUploadedFiles() as $argumentName => $argumentValue) {
                 if ($request->hasArgument($argumentName)) {
                     $existingArgumentValue = $request->getArgument($argumentName);
                     if (is_array($existingArgumentValue)) {
                         $request->setArgument($argumentName, \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($existingArgumentValue, $argumentValue));
                     }
                 } else {
                     $request->setArgument($argumentName, $argumentValue);
                 }
             }
             break;
             #			case 'PUT' :
             #				$putArguments = array();
             #				parse_str(file_get_contents("php://input"), $putArguments);
             #				foreach ($putArguments as $argumentName => $argumentValue) {
             #					$request->setArgument($argumentName, $argumentValue);
             #				}
             #			break;
     }
 }
Пример #4
0
 /**
  * Saves data in a cache file.
  *
  * @param string $entryIdentifier An identifier for this specific cache entry
  * @param string $data The data to be stored
  * @param array $tags Tags to associate with this cache entry
  * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
  * @return void
  * @throws \F3\FLOW3\Cache\Exception if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL)
 {
     if (!$this->cache instanceof \F3\FLOW3\Cache\Frontend\FrontendInterface) {
         throw new \F3\FLOW3\Cache\Exception('No cache frontend has been set yet via setCache().', 1204111375);
     }
     if (!is_string($data)) {
         throw new \F3\FLOW3\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1204481674);
     }
     $this->remove($entryIdentifier);
     $temporaryCacheEntryPathAndFilename = $this->cacheDirectory . uniqid() . '.temp';
     if (strlen($temporaryCacheEntryPathAndFilename) > $this->environment->getMaximumPathLength()) {
         throw new \F3\FLOW3\Cache\Exception('The length of the temporary cache file path "' . $temporaryCacheEntryPathAndFilename . '" is ' . strlen($temporaryCacheEntryPathAndFilename) . ' characters long and exceeds the maximum path length of ' . $this->environment->getMaximumPathLength() . '. Please consider setting the temporaryDirectoryBase option to a shorter path. ', 1248710426);
     }
     $expiryTime = $lifetime === NULL ? 0 : time() + $lifetime;
     $metaData = str_pad($expiryTime, self::EXPIRYTIME_LENGTH) . implode(' ', $tags) . str_pad(strlen($data), self::DATASIZE_DIGITS);
     $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data . $metaData);
     if ($result === FALSE) {
         throw new \F3\FLOW3\Cache\Exception('The temporary cache file "' . $temporaryCacheEntryPathAndFilename . '" could not be written.', 1204026251);
     }
     $i = 0;
     $cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier;
     while (!rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename) && $i < 5) {
         $i++;
     }
     if ($result === FALSE) {
         throw new \F3\FLOW3\Cache\Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1222361632);
     }
     $this->systemLogger->log(sprintf('Cache %s: set entry "%s".', $this->cacheIdentifier, $entryIdentifier), LOG_DEBUG);
 }
 /**
  * Builds a CLI request object from the raw command call
  *
  * @return \F3\FLOW3\MVC\CLI\Request The CLI request as an object
  * @author Karsten Dambekalns <*****@*****.**>
  * @author Robert Lemke <*****@*****.**>
  * @author Andreas Förthner <*****@*****.**>
  */
 public function build()
 {
     $request = $this->objectFactory->create('F3\\FLOW3\\MVC\\CLI\\Request');
     if ($this->environment->getCommandLineArgumentCount() < 2) {
         $request->setControllerPackageKey('FLOW3');
         $request->setControllerSubpackageKey('MVC');
         $request->setControllerName('Standard');
         return $request;
     }
     $rawCommandLineArguments = $this->environment->getCommandLineArguments();
     array_shift($rawCommandLineArguments);
     $commandLineArguments = $this->parseRawCommandLineArguments($rawCommandLineArguments);
     $this->setControllerOptions($request, $commandLineArguments['command']);
     $request->setArguments($commandLineArguments['options']);
     $request->setCommandLineArguments($commandLineArguments['arguments']);
     return $request;
 }
 /**
  * Updates the username and password credentials from the POST vars, if the POST parameters
  * are available. Sets the authentication status to REAUTHENTICATION_NEEDED, if credentials have been sent.
  *
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 public function updateCredentials()
 {
     $postArguments = $this->environment->getRawPostArguments();
     if (isset($postArguments['F3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::username']) && isset($postArguments['F3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::password'])) {
         $this->credentials['username'] = $postArguments['F3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::username'];
         $this->credentials['password'] = $postArguments['F3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::password'];
         $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
     }
 }
Пример #7
0
 /**
  * Tries to detect the base URI of this request and returns it.
  *
  * @param \F3\FLOW3\Property\DataType\Uri $requestUri URI of this web request
  * @return \F3\FLOW3\Property\DataType\Uri The detected base URI
  * @author Robert Lemke <*****@*****.**>
  */
 protected function detectBaseUri(\F3\FLOW3\Property\DataType\Uri $requestUri)
 {
     $baseUri = clone $requestUri;
     $baseUri->setQuery(NULL);
     $baseUri->setFragment(NULL);
     $requestPathSegments = explode('/', $this->environment->getScriptRequestPathAndName());
     array_pop($requestPathSegments);
     $baseUri->setPath(implode('/', $requestPathSegments) . '/');
     return $baseUri;
 }
 /**
  * Detects the (resources) base URI and stores it as a protected
  * class variable.
  *
  * This functionality somewhat duplicates the detection used in the Web
  * Request Builder but for the time being this should be good enough.
  *
  * $this->resourcesPublishingPath must be set prior to calling this method.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function detectResourcesBaseUri()
 {
     $uri = $this->environment->getRequestUri();
     if ($uri === FALSE) {
         return;
     }
     $uri->setQuery(NULL);
     $uri->setFragment(NULL);
     $requestPathSegments = explode('/', $this->environment->getScriptRequestPathAndName());
     array_pop($requestPathSegments);
     $uri->setPath(implode('/', $requestPathSegments) . '/');
     $this->resourcesBaseUri = $uri . substr($this->resourcesPublishingPath, strlen(FLOW3_PATH_WEB));
 }
Пример #9
0
 /**
  * Starts the session, if is has not been already started
  *
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 public function start()
 {
     if ($this->started === FALSE) {
         if (empty($this->settings['PHPSession']['savePath'])) {
             $sessionsPath = \F3\FLOW3\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Sessions'));
         } else {
             $sessionsPath = $this->settings['PHPSession']['savePath'];
         }
         if (!file_exists($sessionsPath)) {
             mkdir($sessionsPath);
         }
         session_save_path($sessionsPath);
         session_start();
         $this->sessionId = session_id();
         $this->started = TRUE;
     }
 }
 /**
  * @test
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function buildSetsPOSTArgumentsFromRequest()
 {
     $this->setUpRequestBuilder();
     $argument = NULL;
     $setArgumentCallback = function () use(&$argument) {
         $args = func_get_args();
         if ($args[0] === 'someArgument') {
             $argument = $args[1];
         }
     };
     $this->mockRequest->expects($this->any())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockEnvironment->expects($this->any())->method('getRawPostArguments')->will($this->returnValue(array('someArgument' => 'POSTArgument')));
     $this->mockEnvironment->expects($this->any())->method('getUploadedFiles')->will($this->returnValue(array()));
     $this->mockRequest->expects($this->exactly(2))->method('setArgument')->will($this->returnCallback($setArgumentCallback));
     $this->builder->build();
     $this->assertEquals('POSTArgument', $argument);
 }
 /**
  * Imports a resource (file) from the given location as a persistent resource.
  * On a successful import this method returns a Resource object representing the
  * newly imported persistent resource.
  *
  * @param string $uri An URI (can also be a path and filename) pointing to the resource to import
  * @return mixed A resource object representing the imported resource or FALSE if an error occurred.
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function importResource($uri)
 {
     $pathInfo = pathinfo($uri);
     if (!isset($pathInfo['extension']) || substr(strtolower($pathInfo['extension']), -3, 3) === 'php') {
         return FALSE;
     }
     $temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('FLOW3_ResourceImport_');
     if (copy($uri, $temporaryTargetPathAndFilename) === FALSE) {
         return FALSE;
     }
     $hash = sha1_file($temporaryTargetPathAndFilename);
     $finalTargetPathAndFilename = $this->persistentResourcesStorageBaseUri . $hash;
     if (rename($temporaryTargetPathAndFilename, $finalTargetPathAndFilename) === FALSE) {
         unlink($temporaryTargetPathAndFilename);
         return FALSE;
     }
     return $this->objectFactory->create('F3\\FLOW3\\Resource\\Resource', $hash, $pathInfo['extension']);
 }
    /**
     * Saves the current configuration into a cache file and creates a cache inclusion script
     * in the context's Configuration directory.
     *
     * @return void
     * @author Robert Lemke <*****@*****.**>
     */
    protected function saveConfigurationCache()
    {
        $configurationCachePath = $this->environment->getPathToTemporaryDirectory() . 'Configuration/';
        if (!file_exists($configurationCachePath)) {
            \F3\FLOW3\Utility\Files::createDirectoryRecursively($configurationCachePath);
        }
        $cachePathAndFilename = $configurationCachePath . $this->context . 'Configurations.php';
        $currentRevision = \F3\FLOW3\Core\Bootstrap::REVISION;
        $includeCachedConfigurationsCode = <<<EOD
<?php
\tif (file_exists('{$cachePathAndFilename}') && \\F3\\FLOW3\\Core\\Bootstrap::REVISION === '{$currentRevision}') {
\t\treturn require '{$cachePathAndFilename}';
\t} else {
\t\tunlink(__FILE__);
\t\treturn array();
\t}
?>
EOD;
        file_put_contents($cachePathAndFilename, '<?php return ' . var_export($this->configurations, TRUE) . '?>');
        file_put_contents($this->includeCachedConfigurationsPathAndFilename, $includeCachedConfigurationsCode);
    }
Пример #13
0
 /**
  * Builds the URI
  *
  * @return string The URI
  * @api
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function build()
 {
     $arguments = array();
     if ($this->addQueryString === TRUE) {
         $arguments = $this->request->getArguments();
         foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) {
             unset($arguments[$argumentToBeExcluded]);
         }
     }
     $arguments = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($arguments, $this->arguments);
     $uri = $this->router->resolve($arguments);
     $this->lastArguments = $arguments;
     if ($this->section !== '') {
         $uri .= '#' . $this->section;
     }
     if (!$this->environment->isRewriteEnabled()) {
         $uri = 'index.php/' . $uri;
     }
     if ($this->createAbsoluteUri === TRUE) {
         $uri = $this->request->getBaseUri() . $uri;
     }
     return $uri;
 }
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \F3\FLOW3\Cache\Frontend\FrontendInterface $cache
  * @return void
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function setCache(\F3\FLOW3\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $this->identifierPrefix = 'FLOW3_' . md5($cache->getIdentifier() . $this->environment->getScriptPathAndFilename() . $this->environment->getSAPIName()) . '_';
 }
 /**
  * This request handler can handle any web request.
  *
  * @return boolean If the request is a web request, TRUE otherwise FALSE
  * @author Robert Lemke <*****@*****.**>
  */
 public function canHandleRequest()
 {
     return $this->utilityEnvironment->getRequestMethod() !== NULL;
 }