/**
  * Handles the web request. The response will automatically be sent to the client.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function handleRequest()
 {
     $request = $this->requestBuilder->build();
     $response = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Response');
     $this->dispatcher->dispatch($request, $response);
     $response->send();
 }
 /**
  * Factory method which creates the specified logger along with the specified backend(s).
  *
  * @param string $identifier An identifier for the logger
  * @param string $loggerObjectName Object name of the log frontend
  * @param mixed $backendObjectNames Object name (or array of object names) of the log backend(s)
  * @param array $backendOptions (optional) Array of backend options. If more than one backend is specified, this is an array of array.
  * @return \F3\FLOW3\Log\LoggerInterface The created logger frontend
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function create($identifier, $loggerObjectName, $backendObjectNames, array $backendOptions = array())
 {
     $logger = $this->objectFactory->create($loggerObjectName);
     if (is_array($backendObjectNames)) {
         foreach ($backendObjectNames as $i => $backendObjectName) {
             if (isset($backendOptions[$i])) {
                 $backend = $this->objectFactory->create($backendObjectName, $backendOptions[$i]);
                 $logger->addBackend($backend);
             }
         }
     } else {
         $backend = $this->objectFactory->create($backendObjectNames, $backendOptions);
         $logger->addBackend($backend);
     }
     return $logger;
 }
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function buildAspectContainerDetectsAllSupportedKindsOfAdviceAndPointcutsAndIntroductions()
 {
     $mockReflectionService = $this->getMock('F3\\FLOW3\\Reflection\\ReflectionService', array('loadFromCache', 'saveToCache'), array(), '', FALSE, TRUE);
     $mockReflectionService->initialize(array('F3\\FLOW3\\Tests\\AOP\\Fixture\\AspectClassWithAllAdviceTypes'));
     $mockPointcutExpressionParser = $this->getMock('F3\\FLOW3\\AOP\\Pointcut\\PointcutExpressionParser', array('parse'), array(), '', FALSE);
     $mockPointcutExpressionParser->expects($this->any())->method('parse')->will($this->returnCallBack(array($this, 'pointcutFilterCompositeCallBack')));
     $this->mockObjectFactory->expects($this->any())->method('create')->will($this->returnCallBack(array($this, 'objectFactoryCallBack')));
     $framework = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\AOP\\Framework'), array('dummy'), array($this->mockObjectManager, $this->mockObjectFactory), '', TRUE, TRUE);
     $framework->injectReflectionService($mockReflectionService);
     $framework->injectPointcutExpressionParser($mockPointcutExpressionParser);
     $container = $framework->_call('buildAspectContainer', 'F3\\FLOW3\\Tests\\AOP\\Fixture\\AspectClassWithAllAdviceTypes');
     $this->assertType('F3\\FLOW3\\AOP\\AspectContainer', $container);
     $this->assertSame('F3\\FLOW3\\Tests\\AOP\\Fixture\\AspectClassWithAllAdviceTypes', $container->getClassName());
     $advisors = $container->getAdvisors();
     $this->assertType('F3\\FLOW3\\AOP\\Advice\\AroundAdvice', $advisors[0]->getAdvice());
     $this->assertSame('fooAround', $advisors[0]->getPointcut()->getPointcutExpression());
     $this->assertType('F3\\FLOW3\\AOP\\Advice\\BeforeAdvice', $advisors[1]->getAdvice());
     $this->assertSame('fooBefore', $advisors[1]->getPointcut()->getPointcutExpression());
     $this->assertType('F3\\FLOW3\\AOP\\Advice\\AfterReturningAdvice', $advisors[2]->getAdvice());
     $this->assertSame('fooAfterReturning', $advisors[2]->getPointcut()->getPointcutExpression());
     $this->assertType('F3\\FLOW3\\AOP\\Advice\\AfterThrowingAdvice', $advisors[3]->getAdvice());
     $this->assertSame('fooAfterThrowing', $advisors[3]->getPointcut()->getPointcutExpression());
     $this->assertType('F3\\FLOW3\\AOP\\Advice\\AfterAdvice', $advisors[4]->getAdvice());
     $this->assertSame('fooAfter', $advisors[4]->getPointcut()->getPointcutExpression());
     $pointcuts = $container->getPointcuts();
     $this->assertTrue(count($pointcuts) === 1);
     $this->assertType('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $pointcuts[0]);
     $this->assertSame('fooPointcut', $pointcuts[0]->getPointcutExpression());
     $introductions = $container->getIntroductions();
     $this->assertTrue(count($introductions) === 1);
     $this->assertType('F3\\FLOW3\\AOP\\Introduction', $introductions[0]);
     $this->assertSame('F3\\FLOW3\\Tests\\AOP\\Fixture\\AspectClassWithAllAdviceTypes', $introductions[0]->getDeclaringAspectClassName());
     $this->assertSame('F3\\FLOW3\\Tests\\AOP\\Fixture\\InterfaceForIntroduction', $introductions[0]->getInterfaceName());
     $this->assertSame('ThePointcutExpression', $introductions[0]->getPointcut()->getPointcutExpression());
 }
 /**
  * Create the internal stream wrapper if needed.
  *
  * @param string $path The path to fetch the scheme from.
  * @return void
  * @author Karsten Dambekalns <*****@*****.**>
  */
 protected function createStreamWrapper($path)
 {
     if ($this->streamWrapper === NULL) {
         $explodedPath = explode(':', $path, 2);
         $scheme = array_shift($explodedPath);
         $this->streamWrapper = self::$objectFactory->create(self::$registeredStreamWrappers[$scheme]);
     }
 }
 /**
  * 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;
 }
 /**
  * Build the rendering context
  *
  * @param array $contextVariables
  */
 protected function buildRenderingContext($contextVariables)
 {
     $variableContainer = $this->objectFactory->create('F3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $contextVariables);
     $renderingContext = $this->objectFactory->create('F3\\Fluid\\Core\\Rendering\\RenderingContext');
     $renderingContext->setTemplateVariableContainer($variableContainer);
     $viewHelperVariableContainer = $this->objectFactory->create('F3\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer');
     $renderingContext->setViewHelperVariableContainer($viewHelperVariableContainer);
     return $renderingContext;
 }
Exemplo n.º 7
0
 /**
  * Creates the tables needed for the cache backend.
  * 
  * @return void
  * @throws \RuntimeException if something goes wrong
  * @author Karsten Dambekalns <*****@*****.**>
  */
 protected function createCacheTables()
 {
     try {
         $pdoHelper = $this->objectFactory->create('F3\\FLOW3\\Utility\\PdoHelper', $this->dataSourceName, $this->username, $this->password);
         $pdoHelper->importSql(FLOW3_PATH_FLOW3 . 'Resources/Private/Cache/SQL/DDL.sql');
     } catch (\PDOException $e) {
         throw new \RuntimeException('Could not create cache tables with DSN "' . $this->dataSourceName . '". PDO error: ' . $e->getMessage(), 1259576985);
     }
 }
Exemplo n.º 8
0
 /**
  * Create and set a validator conjunction
  *
  * @param array $objectNames Object names of the validators
  * @return \F3\FLOW3\MVC\Controller\Argument Returns $this (used for fluent interface)
  * @author Andreas Förthner <*****@*****.**>
  * @api
  */
 public function setNewValidatorConjunction(array $objectNames)
 {
     $this->validator = $this->objectFactory->create('F3\\FLOW3\\Validation\\Validator\\ConjunctionValidator');
     foreach ($objectNames as $objectName) {
         if (!$this->objectManager->isObjectRegistered($objectName)) {
             $objectName = 'F3\\FLOW3\\Validation\\Validator\\' . $objectName;
         }
         $this->validator->addValidator($this->objectManager->getObject($objectName));
     }
     return $this;
 }
 /**
  * Builds a web request object from the raw HTTP information
  *
  * @return \F3\FLOW3\MVC\Web\Request The web request as an object
  * @author Robert Lemke <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function build()
 {
     $request = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Request');
     $request->injectEnvironment($this->environment);
     $request->setRequestUri($this->environment->getRequestUri());
     $request->setMethod($this->environment->getRequestMethod());
     $this->setArgumentsFromRawRequestData($request);
     $routesConfiguration = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
     $this->router->setRoutesConfiguration($routesConfiguration);
     $this->router->route($request);
     return $request;
 }
 /**
  * Retrieve information about a file.
  *
  * This method is called in response to all stat() related functions.
  *
  * $flags can hold one or more of the following values OR'd together:
  *  STREAM_URL_STAT_LINK
  *     For resources with the ability to link to other resource (such as an
  *     HTTP Location: forward, or a filesystem symlink). This flag specified
  *     that only information about the link itself should be returned, not
  *     the resource pointed to by the link. This flag is set in response to
  *     calls to lstat(), is_link(), or filetype().
  *  STREAM_URL_STAT_QUIET
  *     If this flag is set, your wrapper should not raise any errors. If
  *     this flag is not set, you are responsible for reporting errors using
  *     the trigger_error() function during stating of the path.
  *
  * @param string $path The file path or URL to stat. Note that in the case of a URL, it must be a :// delimited URL. Other URL forms are not supported.
  * @param integer $flags Holds additional flags set by the streams API.
  * @return array Should return as many elements as stat() does. Unknown or unavailable values should be set to a rational value (usually 0).
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function pathStat($path, $flags)
 {
     $this->checkScheme($path);
     $uri = $this->objectFactory->create('F3\\FLOW3\\Property\\DataType\\Uri', $path);
     $package = $this->packageManager->getPackage($uri->getHost());
     $path = \F3\FLOW3\Utility\Files::concatenatePaths(array($package->getResourcesPath(), $uri->getPath()));
     if (file_exists($path)) {
         return stat($path);
     } else {
         return FALSE;
     }
 }
 /**
  * Generates a new keypair and returns a UUID to refer to it
  *
  * @param boolean $usedForPasswords TRUE if this keypair should be used to decrypt passwords. (Decryption won't be allowed!)
  * @return uuid An UUID that identifies the generated keypair
  */
 public function generateNewKeypair($usedForPasswords = FALSE)
 {
     $keyResource = openssl_pkey_new($this->openSSLConfiguration);
     if ($keyResource === FALSE) {
         throw new \F3\FLOW3\Security\Exception('OpenSSL private key generation failed.', 1254838154);
     }
     $modulus = $this->getModulus($keyResource);
     $privateKeyString = $this->getPrivateKeyString($keyResource);
     $publicKeyString = $this->getPublicKeyString($keyResource);
     $privateKey = $this->objectFactory->create('F3\\FLOW3\\Security\\Cryptography\\OpenSslRsaKey', $modulus, $privateKeyString);
     $publicKey = $this->objectFactory->create('F3\\FLOW3\\Security\\Cryptography\\OpenSslRsaKey', $modulus, $publicKeyString);
     return $this->storeKeyPair($publicKey, $privateKey, $usedForPasswords);
 }
 /**
  * Imports a resource (file) from the given upload info array as a persistent
  * resource.
  * On a successful import this method returns a Resource object representing
  * the newly imported persistent resource.
  *
  * @param array $uploadInfo An array detailing the resource to import (expected keys: name, tmp_name)
  * @return mixed A resource object representing the imported resource or FALSE if an error occurred.
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function importUploadedResource(array $uploadInfo)
 {
     $pathInfo = pathinfo($uploadInfo['name']);
     if (!isset($pathInfo['extension']) || substr(strtolower($pathInfo['extension']), -3, 3) === 'php') {
         return FALSE;
     }
     $hash = sha1_file($uploadInfo['tmp_name']);
     $finalTargetPathAndFilename = $this->persistentResourcesStorageBaseUri . $hash;
     if (move_uploaded_file($uploadInfo['tmp_name'], $finalTargetPathAndFilename) === FALSE) {
         return FALSE;
     }
     return $this->objectFactory->create('F3\\FLOW3\\Resource\\Resource', $hash, $pathInfo['extension']);
 }
 /**
  * Processes a general request. The result can be returned by altering the given response.
  *
  * @param \F3\FLOW3\MVC\RequestInterface $request The request object
  * @param \F3\FLOW3\MVC\ResponseInterface $response The response, modified by this handler
  * @return void
  * @throws \F3\FLOW3\MVC\Exception\UnsupportedRequestTypeException if the controller doesn't support the current request type
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function processRequest(\F3\FLOW3\MVC\RequestInterface $request, \F3\FLOW3\MVC\ResponseInterface $response)
 {
     if (!$this->canProcessRequest($request)) {
         throw new \F3\FLOW3\MVC\Exception\UnsupportedRequestTypeException(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes), 1187701131);
     }
     $this->request = $request;
     $this->request->setDispatched(TRUE);
     $this->response = $response;
     $this->uriBuilder = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Routing\\UriBuilder');
     $this->uriBuilder->setRequest($request);
     $this->initializeControllerArgumentsBaseValidators();
     $this->mapRequestArgumentsToControllerArguments();
     $this->controllerContext = $this->objectFactory->create('F3\\FLOW3\\MVC\\Controller\\Context', $this->request, $this->response, $this->arguments, $this->argumentsMappingResults, $this->uriBuilder, $this->flashMessageContainer);
 }
Exemplo n.º 14
0
 /**
  * Factory method which creates the specified cache along with the specified kind of backend.
  * After creating the cache, it will be registered at the cache manager.
  *
  * @param string $cacheIdentifier The name / identifier of the cache to create
  * @param string $cacheObjectName Object name of the cache frontend
  * @param string $backendObjectName Object name of the cache backend
  * @param array $backendOptions (optional) Array of backend options
  * @return \F3\FLOW3\Cache\Frontend\FrontendInterface The created cache frontend
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = array())
 {
     $context = $this->objectManager->getContext();
     $backend = $this->objectFactory->create($backendObjectName, $context, $backendOptions);
     if (!$backend instanceof \F3\FLOW3\Cache\Backend\BackendInterface) {
         throw new \F3\FLOW3\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301);
     }
     $cache = $this->objectFactory->create($cacheObjectName, $cacheIdentifier, $backend);
     if (!$cache instanceof \F3\FLOW3\Cache\Frontend\FrontendInterface) {
         throw new \F3\FLOW3\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300);
     }
     $this->cacheManager->registerCache($cache);
     return $cache;
 }
Exemplo n.º 15
0
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function setNewValidatorConjunctionCanHandleShortValidatorNames()
 {
     $mockValidator1 = $this->getMock('F3\\FLOW3\\Validation\\Validator\\ValidatorInterface');
     $mockValidator2 = $this->getMock('F3\\FLOW3\\Validation\\Validator\\ValidatorInterface');
     $mockValidatorChain = $this->getMock('F3\\FLOW3\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
     $mockValidatorChain->expects($this->at(0))->method('addValidator')->with($mockValidator1);
     $mockValidatorChain->expects($this->at(1))->method('addValidator')->with($mockValidator2);
     $this->mockObjectFactory->expects($this->once())->method('create')->with('F3\\FLOW3\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($mockValidatorChain));
     $this->mockObjectManager->expects($this->any())->method('isObjectRegistered')->will($this->returnValue(FALSE));
     $this->mockObjectManager->expects($this->exactly(2))->method('getObject')->will($this->onConsecutiveCalls($mockValidator1, $mockValidator2));
     $argument = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\MVC\\Controller\\Argument'), array('dummy'), array(), '', FALSE);
     $argument->_set('objectManager', $this->mockObjectManager);
     $argument->_set('objectFactory', $this->mockObjectFactory);
     $argument->setNewValidatorConjunction(array('Validator1', 'Validator2'));
 }
Exemplo n.º 16
0
 /**
  * Returns the available documentation formats for this documentation
  *
  * @return array Array of \F3\FLOW3\Package\DocumentationFormat
  * @author Christopher Hlubek <*****@*****.**>
  * @api
  */
 public function getDocumentationFormats()
 {
     $documentationFormats = array();
     $documentationFormatsDirectoryIterator = new \DirectoryIterator($this->documentationPath);
     $documentationFormatsDirectoryIterator->rewind();
     while ($documentationFormatsDirectoryIterator->valid()) {
         $filename = $documentationFormatsDirectoryIterator->getFilename();
         if ($filename[0] != '.' && $documentationFormatsDirectoryIterator->isDir()) {
             $documentationFormat = $this->objectFactory->create('F3\\FLOW3\\Package\\Documentation\\Format', $filename, $this->documentationPath . $filename . '/');
             $documentationFormats[$filename] = $documentationFormat;
         }
         $documentationFormatsDirectoryIterator->next();
     }
     return $documentationFormats;
 }
Exemplo n.º 17
0
 /**
  * Returns the available documentations for this package
  *
  * @return array Array of \F3\FLOW3\Package\Documentation
  * @author Christopher Hlubek <*****@*****.**>
  * @api
  */
 public function getPackageDocumentations()
 {
     $documentations = array();
     $documentationPath = $this->getDocumentationPath();
     if (is_dir($documentationPath)) {
         $documentationsDirectoryIterator = new \DirectoryIterator($documentationPath);
         $documentationsDirectoryIterator->rewind();
         while ($documentationsDirectoryIterator->valid()) {
             $filename = $documentationsDirectoryIterator->getFilename();
             if ($filename[0] != '.' && $documentationsDirectoryIterator->isDir()) {
                 $filename = $documentationsDirectoryIterator->getFilename();
                 $documentation = $this->objectFactory->create('F3\\FLOW3\\Package\\Documentation', $this, $filename, $documentationPath . $filename . '/');
                 $documentations[$filename] = $documentation;
             }
             $documentationsDirectoryIterator->next();
         }
     }
     return $documentations;
 }
Exemplo n.º 18
0
 /**
  * Parses the privileges for the specified identifier and role
  *
  * @param string $identifier The identifier (class->method or resource) to parse the privileges for
  * @param string $role The string representation of a role to parse the privileges for
  * @param string $privilegeType If set, only the privilege of the given type will be parsed
  * @return array Parsed privileges
  * @author Andreas Förthner <*****@*****.**>
  */
 protected function parsePrivileges($identifier, $role, $privilegeType)
 {
     $privileges = array();
     if (!isset($this->acls[$identifier][$role])) {
         return NULL;
     }
     foreach ($this->acls[$identifier][$role] as $privilegeString) {
         preg_match('/^(.+)_(GRANT|DENY)$/', $privilegeString, $matches);
         if ($privilegeType !== '' && $privilegeType !== $matches[1]) {
             continue;
         }
         $privileges[] = $this->objectFactory->create('F3\\FLOW3\\Security\\ACL\\Privilege', $matches[1], $matches[2] === 'GRANT' ? TRUE : FALSE);
     }
     if (is_array($this->roles[$role])) {
         foreach ($this->roles[$role] as $parentRole) {
             $privileges = array_merge($this->parsePrivileges($identifier, $parentRole, $privilegeType), $privileges);
         }
     }
     return $privileges;
 }
Exemplo n.º 19
0
 /**
  * Scans all directories in the packages directories for available packages.
  * For each package a \F3\FLOW3\Package\ object is created and returned as
  * an array.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function scanAvailablePackages()
 {
     $this->packages = array('FLOW3' => $this->objectFactory->create('F3\\FLOW3\\Package\\Package', 'FLOW3', FLOW3_PATH_FLOW3));
     foreach (new \DirectoryIterator(FLOW3_PATH_PACKAGES) as $parentFileInfo) {
         $parentFilename = $parentFileInfo->getFilename();
         if ($parentFilename[0] === '.' || !$parentFileInfo->isDir()) {
             continue;
         }
         foreach (new \DirectoryIterator($parentFileInfo->getPathname()) as $childFileInfo) {
             $childFilename = $childFileInfo->getFilename();
             if ($childFilename[0] !== '.' && $childFilename !== 'FLOW3') {
                 $packagePath = \F3\FLOW3\Utility\Files::getUnixStylePath($childFileInfo->getPathName()) . '/';
                 if (isset($this->packages[$childFilename])) {
                     throw new \F3\FLOW3\Package\Exception\DuplicatePackageException('Detected a duplicate package, remove either "' . $this->packages[$childFilename]->getPackagePath() . '" or "' . $packagePath . '".', 1253716811);
                 }
                 $this->packages[$childFilename] = $this->objectFactory->create('F3\\FLOW3\\Package\\Package', $childFilename, $packagePath);
             }
         }
     }
     foreach (array_keys($this->packages) as $upperCamelCasedPackageKey) {
         $this->packageKeys[strtolower($upperCamelCasedPackageKey)] = $upperCamelCasedPackageKey;
     }
 }
Exemplo n.º 20
0
 /**
  * Creates F3\FLOW3\MVC\Web\Routing\Route objects from the injected routes
  * configuration.
  *
  * @return void
  * @author Bastian Waidelich <*****@*****.**>
  */
 protected function createRoutesFromConfiguration()
 {
     if ($this->routesCreated === FALSE) {
         $this->routes = array();
         foreach ($this->routesConfiguration as $routeConfiguration) {
             $route = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Routing\\Route');
             if (isset($routeConfiguration['name'])) {
                 $route->setName($routeConfiguration['name']);
             }
             $route->setUriPattern($routeConfiguration['uriPattern']);
             if (isset($routeConfiguration['defaults'])) {
                 $route->setDefaults($routeConfiguration['defaults']);
             }
             if (isset($routeConfiguration['routeParts'])) {
                 $route->setRoutePartsConfiguration($routeConfiguration['routeParts']);
             }
             if (isset($routeConfiguration['toLowerCase'])) {
                 $route->setLowerCase($routeConfiguration['toLowerCase']);
             }
             $this->routes[] = $route;
         }
         $this->routesCreated = TRUE;
     }
 }
Exemplo n.º 21
0
 /**
  * Iterates through all segments in $this->uriPattern and creates
  * appropriate RoutePart instances.
  *
  * @return void
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function parse()
 {
     if ($this->isParsed || $this->uriPattern === NULL || $this->uriPattern === '') {
         return;
     }
     $this->routeParts = array();
     $currentRoutePartIsOptional = FALSE;
     if (substr($this->uriPattern, -1) === '/') {
         throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" ends with a slash, which is not allowed. You can put the trailing slash in brackets to make it optional.', 1234782997);
     }
     if ($this->uriPattern[0] === '/') {
         throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" starts with a slash, which is not allowed.', 1234782983);
     }
     $matches = array();
     preg_match_all(self::PATTERN_EXTRACTROUTEPARTS, $this->uriPattern, $matches, PREG_SET_ORDER);
     $lastRoutePart = NULL;
     foreach ($matches as $match) {
         $routePartType = empty($match['dynamic']) ? self::ROUTEPART_TYPE_STATIC : self::ROUTEPART_TYPE_DYNAMIC;
         $routePartName = $match['content'];
         if (!empty($match['optionalStart'])) {
             if ($lastRoutePart !== NULL && $lastRoutePart->isOptional()) {
                 throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains succesive optional Route sections, which is not allowed.', 1234562050);
             }
             $currentRoutePartIsOptional = TRUE;
         }
         $routePart = NULL;
         switch ($routePartType) {
             case self::ROUTEPART_TYPE_DYNAMIC:
                 if ($lastRoutePart instanceof \F3\FLOW3\MVC\Web\Routing\DynamicRoutePartInterface) {
                     throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains succesive Dynamic Route Parts, which is not allowed.', 1218446975);
                 }
                 if (isset($this->routePartsConfiguration[$routePartName]['handler'])) {
                     $routePart = $this->objectManager->getObject($this->routePartsConfiguration[$routePartName]['handler']);
                     if (!$routePart instanceof \F3\FLOW3\MVC\Web\Routing\DynamicRoutePartInterface) {
                         throw new \F3\FLOW3\MVC\Exception\InvalidRoutePartHandlerException('routePart handlers must implement "\\F3\\FLOW3\\MVC\\Web\\Routing\\DynamicRoutePartInterface" in route "' . $this->getName() . '"', 1218480972);
                     }
                 } else {
                     $routePart = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Routing\\DynamicRoutePart');
                 }
                 if (isset($this->defaults[$routePartName])) {
                     $routePart->setDefaultValue($this->defaults[$routePartName]);
                 }
                 break;
             case self::ROUTEPART_TYPE_STATIC:
                 $routePart = $this->objectFactory->create('F3\\FLOW3\\MVC\\Web\\Routing\\StaticRoutePart');
                 if ($lastRoutePart !== NULL && $lastRoutePart instanceof \F3\FLOW3\MVC\Web\Routing\DynamicRoutePartInterface) {
                     $lastRoutePart->setSplitString($routePartName);
                 }
         }
         $routePart->setName($routePartName);
         $routePart->setOptional($currentRoutePartIsOptional);
         if ($this->lowerCase) {
             $routePart->setLowerCase(TRUE);
         }
         if (isset($this->routePartsConfiguration[$routePartName]['options'])) {
             $routePart->setOptions($this->routePartsConfiguration[$routePartName]['options']);
         }
         if (isset($this->routePartsConfiguration[$routePartName]['toLowerCase'])) {
             $routePart->setLowerCase($this->routePartsConfiguration[$routePartName]['toLowerCase']);
         }
         $this->routeParts[] = $routePart;
         if (!empty($match['optionalEnd'])) {
             if (!$currentRoutePartIsOptional) {
                 throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unopened optional section.', 1234564495);
             }
             $currentRoutePartIsOptional = FALSE;
         }
         $lastRoutePart = $routePart;
     }
     if ($currentRoutePartIsOptional) {
         throw new \F3\FLOW3\MVC\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unterminated optional section.', 1234563922);
     }
     $this->isParsed = TRUE;
 }
Exemplo n.º 22
0
 /**
  * Creates a query object working on the given class name
  *
  * @param string $className
  * @return \F3\FLOW3\Persistence\Query
  * @author Karsten Dambekalns <*****@*****.**>
  * @api
  */
 public function create($className)
 {
     return $this->objectFactory->create('F3\\FLOW3\\Persistence\\Query', $className);
 }
 /**
  * Adds a setting filter to the poincut filter composite
  *
  * @param string $operator The operator
  * @param string $configurationPath The path to the settings option, that should be used
  * @param \F3\FLOW3\AOP\Pointcut\PointcutFilterComposite $pointcutFilterComposite An instance of the pointcut filter composite. The result (ie. the custom filter) will be added to this composite object.
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 protected function parseDesignatorSetting($operator, $configurationPath, \F3\FLOW3\AOP\Pointcut\PointcutFilterComposite $pointcutFilterComposite)
 {
     $pointcutFilterComposite->addFilter($operator, $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\PointcutSettingFilter', $configurationPath));
 }
Exemplo n.º 24
0
 /**
  * Creates and returns an aspect from the annotations found in a class which
  * is tagged as an aspect. The object acting as an advice will already be
  * fetched (and therefore instantiated if neccessary).
  *
  * @param  string $aspectClassName Name of the class which forms the aspect, contains advices etc.
  * @return mixed The aspect container containing one or more advisors or FALSE if no container could be built
  * @author Robert Lemke <*****@*****.**>
  */
 protected function buildAspectContainer($aspectClassName)
 {
     if (!$this->reflectionService->isClassReflected($aspectClassName)) {
         return FALSE;
     }
     if (!$this->reflectionService->isClassTaggedWith($aspectClassName, 'aspect')) {
         return FALSE;
     }
     $aspectContainer = new \F3\FLOW3\AOP\AspectContainer($aspectClassName);
     foreach ($this->reflectionService->getClassMethodNames($aspectClassName) as $methodName) {
         foreach ($this->reflectionService->getMethodTagsValues($aspectClassName, $methodName) as $tagName => $tagValues) {
             foreach ($tagValues as $tagValue) {
                 switch ($tagName) {
                     case 'around':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $advice = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advice\\AroundAdvice', $aspectClassName, $methodName);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName);
                         $advisor = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advisor', $advice, $pointcut);
                         $aspectContainer->addAdvisor($advisor);
                         break;
                     case 'before':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $advice = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advice\\BeforeAdvice', $aspectClassName, $methodName);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName);
                         $advisor = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advisor', $advice, $pointcut);
                         $aspectContainer->addAdvisor($advisor);
                         break;
                     case 'afterreturning':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $advice = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advice\\AfterReturningAdvice', $aspectClassName, $methodName);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName);
                         $advisor = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advisor', $advice, $pointcut);
                         $aspectContainer->addAdvisor($advisor);
                         break;
                     case 'afterthrowing':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $advice = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advice\\AfterThrowingAdvice', $aspectClassName, $methodName);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName);
                         $advisor = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advisor', $advice, $pointcut);
                         $aspectContainer->addAdvisor($advisor);
                         break;
                     case 'after':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $advice = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advice\\AfterAdvice', $aspectClassName, $methodName);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName);
                         $advisor = $this->objectFactory->create('F3\\FLOW3\\AOP\\Advisor', $advice, $pointcut);
                         $aspectContainer->addAdvisor($advisor);
                         break;
                     case 'pointcut':
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($tagValue);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $tagValue, $pointcutFilterComposite, $aspectClassName, $methodName);
                         $aspectContainer->addPointcut($pointcut);
                         break;
                 }
             }
         }
     }
     foreach ($this->reflectionService->getClassPropertyNames($aspectClassName) as $propertyName) {
         foreach ($this->reflectionService->getPropertyTagsValues($aspectClassName, $propertyName) as $tagName => $tagValues) {
             foreach ($tagValues as $tagValue) {
                 switch ($tagName) {
                     case 'introduce':
                         $splittedTagValue = explode(',', $tagValue);
                         if (!is_array($splittedTagValue) || count($splittedTagValue) != 2) {
                             throw new \F3\FLOW3\AOP\Exception('The introduction in class "' . $aspectClassName . '" does not contain the two required parameters.', 1172694761);
                         }
                         $pointcutExpression = trim($splittedTagValue[1]);
                         $pointcutFilterComposite = $this->pointcutExpressionParser->parse($pointcutExpression);
                         $pointcut = $this->objectFactory->create('F3\\FLOW3\\AOP\\Pointcut\\Pointcut', $pointcutExpression, $pointcutFilterComposite, $aspectClassName);
                         $interfaceName = trim($splittedTagValue[0]);
                         $introduction = $this->objectFactory->create('F3\\FLOW3\\AOP\\Introduction', $aspectClassName, $interfaceName, $pointcut);
                         $aspectContainer->addIntroduction($introduction);
                         break;
                 }
             }
         }
     }
     if (count($aspectContainer->getAdvisors()) < 1 && count($aspectContainer->getPointcuts()) < 1 && count($aspectContainer->getIntroductions()) < 1) {
         throw new \F3\FLOW3\AOP\Exception('The class "' . $aspectClassName . '" is tagged to be an aspect but doesn\'t contain advices nor pointcut or introduction declarations.', 1169124534);
     }
     return $aspectContainer;
 }
Exemplo n.º 25
0
 /**
  * Text node handler
  *
  * @param \F3\Fluid\Core\Parser\ParsingState $state
  * @param string $text
  * @return void
  * @author Sebastian Kurfürst <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  */
 protected function textHandler(\F3\Fluid\Core\Parser\ParsingState $state, $text)
 {
     $node = $this->objectFactory->create('F3\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', $text);
     if ($this->configuration !== NULL) {
         foreach ($this->configuration->getTextInterceptors() as $interceptor) {
             $node = $interceptor->process($node);
         }
     }
     $state->getNodeFromStack()->addChildNode($node);
 }
Exemplo n.º 26
0
 /**
  * Controls cloning of the object manager. Cloning should only be used within unit tests.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function __clone()
 {
     $this->singletonObjectsRegistry = clone $this->singletonObjectsRegistry;
     $this->objectFactory = clone $this->objectFactory;
     $this->objectFactory->injectObjectManager($this);
 }
 /**
  * Evaluates to the upper-case string value (or values, if multi-valued) of an operand.
  *
  * @param \F3\FLOW3\Persistence\QOM\DynamicOperand $operand the operand whose value is converted to a upper-case string; non-null
  * @return \F3\FLOW3\Persistence\QOM\UpperCase the operand; non-null
  * @author Karsten Dambekalns <*****@*****.**>
  * @api
  */
 public function upperCase(\F3\FLOW3\Persistence\QOM\DynamicOperand $operand)
 {
     return $this->objectFactory->create('F3\\FLOW3\\Persistence\\QOM\\UpperCase', $operand);
 }
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 protected function addError($message, $code)
 {
     $this->errors[] = $this->objectFactory->create('F3\\FLOW3\\Validation\\Error', $message, $code);
 }
Exemplo n.º 29
0
 /**
  * Initializes this locale service
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function initialize()
 {
     $locale = $this->objectFactory->create('F3\\FLOW3\\Locale\\Locale', $this->settings['locale']['defaultLocaleIdentifier']);
     $this->settings['locale']['defaultLocale'] = $locale;
 }