Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     $result = ProjectManager::activateProject($id);
     if ($result) {
         $output->writeln(sprintf('<info>Activated project "%s"</info>', $id));
     } else {
         $output->writeln('<error>Something went wrong</error>');
     }
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     $result = ProjectManager::updateProject($id, $input->getArgument('property'), $input->getArgument('value'));
     if ($result) {
         $output->writeln(sprintf('<info>Project "%s" updated successfully</info>', $id));
     } else {
         $output->writeln('<error>Something went wrong</error>');
     }
 }
Example #3
0
 /**
  * @param  string $path
  * @param  boolean $absolute
  * @return string
  */
 public static function getPath($path, $absolute = false)
 {
     $project = ProjectManager::getActiveProject();
     $resPath = '';
     if ($project) {
         $resPath .= $project->getResourcePath();
     } else {
         $resPath .= ProjectManager::getDefaultProject()->getResourcePath();
     }
     $resPath .= $path;
     if (!$absolute) {
         $resPath = str_replace(PathHelper::getBasePath(), '', $resPath);
     }
     return PathHelper::normalizePath($resPath);
 }
Example #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     $name = $input->getArgument('name');
     $namespace = $input->getArgument('namespace');
     $description = $input->getArgument('description');
     $active = $input->getOption('activate');
     if (empty($name)) {
         $name = $id . ' name';
     }
     if (empty($description)) {
         $description = $id . ' description';
     }
     ProjectManager::createProject($id, $name, $description, $namespace, $active, $output);
     $output->writeln(sprintf('<info>Created project "%s"</info>', $id));
 }
Example #5
0
 /**
  * Renders a exception/error template
  *
  * @param array $args
  */
 protected static final function renderException($args)
 {
     Buffer::clear(true);
     /**
      * Set header status code
      */
     Header::set(500, false);
     /**
      * Reset all to the default
      */
     $activeProject = ProjectManager::getActiveProject();
     if ($activeProject) {
         $activeProject->setActive(false);
     }
     Locale::set(DEFAULT_LOCALE);
     /**
      * Render with the exception layout
      */
     self::renderTemplate(EXCEPTION_LAYOUT, $args, true);
     exit;
 }
Example #6
0
 public function handleShutdown()
 {
     $isError = false;
     $type = "UnknownError";
     if ($error = error_get_last()) {
         switch ($error['type']) {
             case E_ERROR:
                 $type = "FatalError";
                 $isError = true;
             case E_CORE_ERROR:
                 $type = "CoreError";
                 $isError = true;
             case E_COMPILE_ERROR:
                 $type = "CompileError";
                 $isError = true;
             case E_USER_ERROR:
                 $type = "UserError";
                 $isError = true;
             case E_PARSE:
                 $type = "ParseError";
                 $isError = true;
                 break;
         }
         if ($isError) {
             // Create new exception
             $className = '\\' . ProjectManager::getDefaultProject()->getNsName();
             $className .= '\\Handler\\Error\\Exception\\Shutdown\\' . $type . 'Exception';
             $exception = new $className();
             if (false == is_null($exception)) {
                 $message = array_key_exists('message', $error) ? $error['message'] : $type;
                 $exception->setMessage(self::SHUTDOWN_ERROR_MESSAGE . ": " . $message);
                 // Define position
                 if (array_key_exists('line', $error) && array_key_exists('file', $error)) {
                     $exception->setFile($error['file']);
                     $exception->setLine($error['line']);
                 }
                 // Render new application after wipeout
                 Application::renderShutdownError($exception);
             }
         }
     }
 }
Example #7
0
    /**
     * Sets the defined code
     *
     * @param number $code
     */
    public static function set($code, $throw = true)
    {
        // Check for recursion
        if (self::$running == true) {
            throw new Header\Exception\StillRunningException('
				Could not (re)set the header, another process
				is still running. Recursion?
			');
        }
        self::$running = true;
        // Check if status message is given
        if (!array_key_exists($code, self::$messages)) {
            $code = self::DEFAULT_ERROR_CODE;
        }
        // Build message
        $message = self::$messages[$code]['status'];
        if (!empty(self::$messages[$code]['message'])) {
            $message = self::$messages[$code]['message'];
        }
        // Set status to the header
        self::setStatus(self::$messages[$code]['status']);
        // Check if a view was set
        if (array_key_exists($code, self::$codeViews)) {
            $throw = false;
            /**
             * Clear previous outputs
             * completely
             */
            Buffer::clear(true);
            /**
             * Render new template
             * with the given view path
             * and layout
             */
            $template = Template::getInstance();
            $template->setLayout(self::$codeViews[$code]['layout']);
            $template->setView(self::$codeViews[$code]['routing']['view']);
            $project = ProjectManager::getActiveProject();
            $ctrlClass = '\\' . $project->getNsName() . CONTROLLER_V_RL_NS . '\\' . self::$codeViews[$code]['routing']['ctrl'];
            if (!class_exists($ctrlClass) || !is_string(self::$codeViews[$code]['routing']['ctrl'])) {
                $project = ProjectManager::getDefaultProject();
                $ctrlClass = '\\' . $project->getNsName() . CONTROLLER_V_RL_NS . '\\Error';
            }
            $template->getView()->setControllerClass($ctrlClass);
            $template->getView()->setAction(self::$codeViews[$code]['routing']['action']);
            $template->renderAll();
            // Check end to recognize recursion
            self::$running = false;
            // Abort to prevent further actions
            exit;
        } else {
            if (true == $throw) {
                self::$running = false;
                // Throw HTTP exception
                throw new Header\Exception\HttpException($message);
            }
        }
        self::$running = false;
    }
Example #8
0
 /**
  * Check if the given path
  * points to a valid view
  *
  * @param  string  $path
  * @return boolean
  */
 public static function isView($path)
 {
     $project = ProjectManager::getActiveProject();
     $project = $project ? $project : ProjectManager::getDefaultProject();
     $exp = '/' . preg_replace('/\\//', '\\/', self::normalizePath($project->getViewPath())) . '/';
     return preg_match($exp, self::normalizePath($path));
 }
Example #9
0
    /**
     * Calls undefined functions
     * (mostly used for view helpers)
     *
     * @param  string $name
     * @param  array  $value
     * @return *
     */
    public function __call($name, $args)
    {
        if (preg_match($this->viewHelperExp, $name)) {
            $helperName = preg_replace($this->viewHelperExp, '', $name);
            $helperName = ucfirst($helperName);
            $activeProject = ProjectManager::getActiveProject();
            $helperClass = "";
            if ($activeProject) {
                $defaultNs = $activeProject->getNsName() . VIEW_HELPER_RL_NS;
                $helperClass = $defaultNs . '\\' . $helperName;
            }
            if (!class_exists($helperClass)) {
                $defaultNs = ProjectManager::getDefaultProject()->getNsName() . VIEW_HELPER_RL_NS;
                $helperClass = $defaultNs . '\\' . $helperName;
                if (!class_exists($helperClass)) {
                    throw new Exception\HelperNotFoundException('View helper "' . $helperClass . '" was
                        not found!');
                }
            }
            $helper = $this->getHelperClass($helperClass);
            if (false == $helper instanceof \Fewlines\Core\Helper\AbstractViewHelper) {
                throw new Exception\HelperInvalidInstanceException('The view helper "' . $helperName . '" was
			 		NOT extended by "' . $defaultNs . '\\AbstractViewHelper"');
            }
            if (false == method_exists($helper, $helperName)) {
                throw new Exception\HelperMethodNotFoundException('The view helper method "' . $helperName . '"
					was not found!');
            }
            $reflection = new \ReflectionMethod($helperClass, $helperName);
            $needArgsCount = $reflection->getNumberOfRequiredParameters();
            $foundArgsCount = count($args);
            if ($needArgsCount > $foundArgsCount) {
                throw new Exception\HelperArgumentException('The view helper method "' . $helperName . '"
    				requires at least "' . $needArgsCount . '"
    				parameter(s). Found ' . $foundArgsCount);
            }
            return call_user_func_array(array($helper, $helperName), $args);
        } else {
            if ($this->view->isRouteActive()) {
                $controller = $this->view->getRouteController();
            } else {
                $controller = $this->view->getViewController();
            }
            if (!is_null($controller) && method_exists($controller, $name)) {
                return call_user_func_array(array($controller, $name), $args);
            } else {
                if (!method_exists($this, $name)) {
                    $msg = 'The method "' . $name . '" was not found in ' . get_class($this);
                    if (!is_null($controller)) {
                        $msg .= ' or in the controller ' . get_class($controller);
                    }
                    throw new Exception\TemplateMethodNotFoundException($msg);
                }
            }
            return call_user_func_array(array($this, $name), $args);
        }
    }
Example #10
0
 /**
  * Returns the first project registered
  *
  * @return \Fewlines\Core\Application\ProjectManager\Project
  */
 public function getFirstProject()
 {
     if ($this->countProjects() > 0) {
         $projects = ProjectManager::getProjects();
         return $projects[0];
     }
     return null;
 }
Example #11
0
 /**
  * Init the namespaces of the
  * projects
  */
 protected final function initNamespaces()
 {
     $autoloader = $this->application->getAutoloader();
     foreach (ProjectManager::getProjects() as $project) {
         $autoloader->addPsr4(rtrim($project->getNsName(), '\\') . '\\', $project->getNsPath());
     }
 }
Example #12
0
 /**
  * Sets the controller by the active namespace
  */
 private function setViewControllerClass()
 {
     $project = ProjectManager::getActiveProject();
     $class = '\\';
     if ($project && $project->hasNsName() && Template::getInstance()->getLayout()->getName() != EXCEPTION_LAYOUT) {
         $class .= $project->getNsName();
     } else {
         $class .= ProjectManager::getDefaultProject()->getNsName();
     }
     $class .= CONTROLLER_V_RL_NS . '\\' . ucfirst($this->name);
     if (!class_exists($class)) {
         HttpHeader::set(404, false);
         throw new View\Exception\ControllerClassNotFoundException('The class "' . $class . '", for the
             controller was not found.');
     }
     $this->controllerClass = $class;
 }
Example #13
0
 /**
  * Get a translation from a file by a path
  *
  * @param  string|arary $path
  * @return string
  */
 public static function get($path)
 {
     $project = ProjectManager::getActiveProject();
     $project = $project ? $project : ProjectManager::getDefaultProject();
     $pathParts = ArrayHelper::clean(explode(self::SUBPATH_SEPERATOR, $path));
     $localeDir = PathHelper::createPath(array($project->getTranslationPath(), Locale::getKey()));
     $entryPoint = '';
     $entryPointIndex = 0;
     // Check if path is empty
     if (empty($pathParts)) {
         return '';
     }
     // Get entry point file
     for ($i = 0, $len = count($pathParts); $i < $len; $i++) {
         $isFile = false;
         $localeDir = PathHelper::getRealPath($localeDir);
         for ($x = 0, $lenX = count(self::$translationTypes); $x < $lenX; $x++) {
             $fileExt = self::$translationTypes[$x];
             $pathPart = $pathParts[$i];
             $isFile = is_file($localeDir . $pathPart . '.' . $fileExt);
             // Escape loop if file was found
             if (true == $isFile) {
                 break;
             }
         }
         // Attach current "dir" to the localdir (next level)
         $localeDir .= $pathPart;
         // Excape loop if entry point was found
         if (true == $isFile) {
             $entryPointIndex = $i;
             $entryPoint = $localeDir . '.' . $fileExt;
             break;
         }
     }
     /**
      * If there is no entry point take
      * all supported translation files
      * from the given directory
      */
     if (empty($entryPoint) && is_dir($localeDir)) {
         $files = DirHelper::scanDir($localeDir);
         $names = array();
         foreach ($files as $file) {
             $extension = pathinfo($file['path'], PATHINFO_EXTENSION);
             $filename = pathinfo($file['path'], PATHINFO_FILENAME);
             if (array_search($extension, self::$translationTypes) !== false) {
                 $names[] = $filename;
             }
         }
         return $names;
     }
     // if (true == empty($entryPoint)) {
     //     throw new Translator\Exception\EntryPointNotFoundException("No entry point (file) found for: " . (string) $path);
     // }
     $pathParts = array_slice($pathParts, $entryPointIndex + 1);
     $pathParts = ArrayHelper::clean($pathParts);
     // The default translation value
     $value = $path;
     /**
      * Operate with the key functions for different file types.
      * At this point we are handling valid values
      */
     switch ($fileExt) {
         case self::$translationTypes[0]:
             $value = self::getValueByKeyPHP($entryPoint, $pathParts);
             break;
         case self::$translationTypes[1]:
             $value = self::getValueByKeyCSV($entryPoint, $pathParts);
             break;
     }
     /**
      * If the value is a array and empty it doesn't
      * need to be returned. Return a empty string
      * instead
      */
     if (empty($value)) {
         return '';
     } else {
         return $value;
     }
 }