/**
  * Index action
  *
  * @return void
  * @author Christopher Hlubek <*****@*****.**>
  * @author Robert Lemke <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function indexAction()
 {
     $this->view->assign('flow3PathRoot', realpath(FLOW3_PATH_ROOT));
     $this->view->assign('flow3PathWeb', realpath(FLOW3_PATH_WEB));
     $this->view->assign('myPackageUrl', $this->uriBuilder->uriFor('index', array(), 'Standard', 'MyPackage'));
     $this->view->assign('isWindows', $this->isWindows());
     $flow3Package = $this->packageManager->getPackage('FLOW3');
     $version = $flow3Package->getPackageMetaData()->getVersion();
     $this->view->assign('version', $version);
     $activePackages = $this->packageManager->getActivePackages();
     $this->view->assign('activePackages', $activePackages);
     $this->view->assign('notDevelopmentContext', $this->objectManager->getContext() !== 'Development');
 }
 /**
  * Finds and instanciates a controller that matches the current request.
  * If no controller can be found, an instance of NotFoundControllerInterface is returned.
  *
  * @param \F3\FLOW3\MVC\RequestInterface $request The request to dispatch
  * @return \F3\FLOW3\MVC\Controller\ControllerInterface
  * @author Bastian Waidelich <*****@*****.**>
  */
 protected function resolveController(\F3\FLOW3\MVC\RequestInterface $request)
 {
     $exception = NULL;
     $packageKey = $request->getControllerPackageKey();
     if (!$this->packageManager->isPackageAvailable($packageKey)) {
         $exception = new \F3\FLOW3\MVC\Controller\Exception\InvalidPackageException($request, 'package "' . $packageKey . '" does not exist');
     } elseif (!$this->packageManager->isPackageActive($packageKey)) {
         $exception = new \F3\FLOW3\MVC\Controller\Exception\InactivePackageException($request, 'package "' . $packageKey . '" is not active');
     } else {
         $controllerObjectName = $request->getControllerObjectName();
         if ($controllerObjectName === '') {
             $exception = new \F3\FLOW3\MVC\Controller\Exception\InvalidControllerException($request, 'no controller could be resolved which would match your request');
         }
     }
     if ($exception !== NULL) {
         $controller = $this->objectManager->getObject($this->settings['mvc']['notFoundController']);
         if (!$controller instanceof \F3\FLOW3\MVC\Controller\NotFoundControllerInterface) {
             throw new \F3\FLOW3\MVC\Exception\InvalidControllerException('The NotFoundController must implement "\\F3\\FLOW3\\MVC\\Controller\\NotFoundControllerInterface", ' . (is_object($controller) ? get_class($controller) : gettype($controller)) . ' given.', 1246714416);
         }
         $controller->setException($exception);
     } else {
         $controller = $this->objectManager->getObject($controllerObjectName);
         if (!$controller instanceof \F3\FLOW3\MVC\Controller\ControllerInterface) {
             throw new \F3\FLOW3\MVC\Exception\InvalidControllerException('Invalid controller "' . $request->getControllerObjectName() . '". The controller must be a valid request handling controller, ' . (is_object($controller) ? get_class($controller) : gettype($controller)) . ' given.', 1202921619);
         }
     }
     return $controller;
 }
 /**
  * The view action loads the file from the given documentation and
  * acts as a proxy between the documentation browser and the private
  * documentation, that is not directly accessible.
  *
  * @param string $packageKey The package key
  * @param string $documentationName The documentation name
  * @param string $language The language
  * @param string $file The file to display
  * @return string The file contents
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function viewAction($packageKey, $documentationName, $language, $file)
 {
     $packageKey = $this->packageManager->getCaseSensitivePackageKey($packageKey);
     $package = $this->packageManager->getPackage($packageKey);
     $documentations = $package->getPackageDocumentations();
     foreach ($documentations as $iteratedDocumentationName => $iteratedDocumentation) {
         if (strtolower($iteratedDocumentationName) == strtolower($documentationName)) {
             $documentation = $iteratedDocumentation;
             break;
         }
     }
     if (!isset($documentation)) {
         return 'Documentation for ' . $packageKey . ' / ' . $documentationName . ' not found';
     }
     $formats = $documentation->getDocumentationFormats();
     if (!isset($formats['HTML'])) {
         return 'HTML documentation for ' . $packageKey . ' not found';
     }
     $format = $formats['HTML'];
     $contentType = $this->guessContentTypeByFilename($file);
     header('Content-Type: ' . $contentType);
     $path = $format->getFormatPath() . $language . '/' . $file;
     $path = dirname($path) . '/' . basename($path);
     if (strpos($path, $documentation->getDocumentationPath()) !== 0) {
         return 'Invalid file for documentation';
     }
     return file_get_contents($path);
 }
 /**
  * Initialize the resource management component, setting up stream wrappers,
  * publishing the public resources of all found packages, ...
  *
  * @return void
  * @author Karsten Dambekalns <*****@*****.**>
  * @see initialize()
  */
 public function initializeResources()
 {
     $resourceManager = $this->objectManager->getObject('F3\\FLOW3\\Resource\\ResourceManager', $this->settings['resource']);
     $resourceManager->initialize();
     if (FLOW3_SAPITYPE === 'Web') {
         $resourceManager->publishPublicPackageResources($this->packageManager->getActivePackages());
     }
 }
 /**
  * Sets the package key of the controller.
  *
  * @param string $packageKey The package key.
  * @return void
  * @throws \F3\FLOW3\MVC\Exception\InvalidPackageKeyException if the package key is not valid
  * @author Robert Lemke <*****@*****.**>
  */
 public function setControllerPackageKey($packageKey)
 {
     $upperCamelCasedPackageKey = $this->packageManager->getCaseSensitivePackageKey($packageKey);
     if ($upperCamelCasedPackageKey !== FALSE) {
         $this->controllerPackageKey = $upperCamelCasedPackageKey;
     } else {
         $this->controllerPackageKey = $packageKey;
     }
 }
 /**
  * Generate a repository for a model given a package key and model name
  *
  * @param string $packageKey The package key
  * @param string $modelName The name of the domain model class
  * @return void
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function generateRepositoryAction($packageKey, $modelName)
 {
     if (!$this->packageManager->isPackageKeyValid($packageKey)) {
         return 'Package key "' . $packageKey . '" is not valid. Only UpperCamelCase with alphanumeric characters and underscore, please!' . PHP_EOL;
     }
     if (!$this->packageManager->isPackageAvailable($packageKey)) {
         return 'Package "' . $packageKey . '" is not available.' . PHP_EOL;
     }
     $generatedFiles = $this->generatorService->generateRepository($packageKey, $modelName);
     return implode(PHP_EOL, $generatedFiles) . PHP_EOL;
 }
 /**
  * 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;
     }
 }
 /**
  * Generate a repository for a model given a model name and package key
  *
  * @param string $packageKey The package key
  * @param string $modelName The name of the model
  * @return array An array of generated filenames
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function generateRepository($packageKey, $modelName)
 {
     $modelName = ucfirst($modelName);
     $repositoryClassName = $modelName . 'Repository';
     $namespace = 'F3\\' . $packageKey . '\\Domain\\Repository';
     $templatePathAndFilename = 'package://Kickstart/Private/Generator/Repository/RepositoryTemplate.php.tmpl';
     $contextVariables = array();
     $contextVariables['packageKey'] = $packageKey;
     $contextVariables['modelName'] = $modelName;
     $contextVariables['repositoryClassName'] = $repositoryClassName;
     $contextVariables['namespace'] = $namespace;
     $fileContent = $this->renderTemplate($templatePathAndFilename, $contextVariables);
     $repositoryFilename = $repositoryClassName . '.php';
     $repositoryPath = $this->packageManager->getPackage($packageKey)->getClassesPath() . 'Domain/Repository/';
     $targetPathAndFilename = $repositoryPath . $repositoryFilename;
     $this->generateFile($targetPathAndFilename, $fileContent);
     return $this->generatedFiles;
 }