<commit_before><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\cli\stdio as stdio;
    
    /**
     * Implements installer for applications based on octris framework.
     *
     * @octdoc      c:app/install
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class install extends \org\octris\core\octsh\libs\plugin
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:install/$next_page
         * @var     array
         */
        protected $next_pages = array();
        /**/

        /**
         * Name of project to install.
         *
         * @octdoc  v:install/$project
         * @var     string
         */
        protected $project = '';
        /**/

        /**
         * Prepare page
         *
         * @octdoc  m:install/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
            $project = $this->project;
            $base    = $_ENV['OCTRIS_BASE']->value;
            
            // create directories
            if ($project == 'org.octris.core') {
                mkdir($base . '/cache',     0755, true);
                mkdir($base . '/data',      0755, true);
                mkdir($base . '/etc',       0755, true);
                mkdir($base . '/host',      0755, true);
                mkdir($base . '/libs',      0755, true);
                mkdir($base . '/locale',    0755, true);
                mkdir($base . '/log',       0755, true);
                mkdir($base . '/templates', 0755, true);
                mkdir($base . '/tools',     0755, true);
            } elseif (!is_dir($base . '/host')) {
                $last_page->addError("You have to install 'org.octris.core' first");
                
                return $last_page;
            } else {
                mkdir($base . '/host/' . $project,             0755, true);
                mkdir($base . '/host/' . $project . '/libsjs', 0777, true);
                mkdir($base . '/host/' . $project . '/styles', 0777, true);
            }
            
            mkdir($base . '/cache/' . $project . '/data',        0777, true);
            mkdir($base . '/cache/' . $project . '/templates_c', 0777, true);
            
            // create symlinks
            $work = app::getPath(app::T_PATH_WORK, $project);
            
            if (is_dir($work . '/data')) {
                symlink($work . '/data', $base . '/data/' . $project);
            }
            if (is_dir($work . '/etc')) {
                symlink($work . '/etc', $base . '/etc/' . $project);
            }
            if (is_dir($work . '/libs')) {
                symlink($work . '/libs', $base . '/libs/' . $project);
            }
            if (is_dir($work . '/locale')) {
                symlink($work . '/locale', $base . '/locale/' . $project);
            }
            if (is_dir($work . '/templates')) {
                symlink($work . '/templates', $base . '/templates/' . $project);
            }

            if ($project != 'org.octris.core') {
                if (is_file($work . '/host/index.php')) {
                    symlink($work . '/host/index.php',  $base . '/host/' . $project . '/index.php');
                }
                if (is_file($work . '/host/robots.txt')) {
                    symlink($work . '/host/robots.txt', $base . '/host/' . $project . '/robots.txt');
                }
                if (is_dir($work . '/host/error')) {
                    symlink($work . '/host/error',      $base . '/host/' . $project . '/error');
                }
                if (is_dir($work . '/host/resources')) {
                    symlink($work . '/host/resources',  $base . '/host/' . $project . '/resources');
                }
            }
        }

        /**
         * Validate help parameters.
         *
         * @octdoc  m:help/validate
         * @param   \org\octris\core\app\cli\page   $last_page      Instance of last called page.
         * @param   string                          $action         Action to select ruleset for.
         * @param   array                           $parameters     Parameters to validate.
         * @return  \org\octris\core\app\cli\page                   Returns page to display errors for.
         */
        public function validate(\org\octris\core\app\cli\page $last_page, $action, array $parameters = array())
        /**/
        {
            $project = array_shift($parameters);
            
            if (is_scalar($project)) {
                if (!is_dir(app::getPath(app::T_PATH_WORK, $project))) {
                    $last_page->addError("unable to locate project '$project'");
                } else {
                    $this->project = $project;
                }
            } elseif (is_array($project)) {
                $last_page->addError("usage: 'install [<path-of-project>]'");
            } else {
                $state = app::getInstance()->getState();
                
                $this->project = $state['project']->value;
            }
            
            return (count($last_page->errors) == 0
                    ? null
                    : $last_page);
        }

        /**
         * Implements dialog.
         *
         * @octdoc  m:install/dialog
         * @param   string                          $action         Action that led to current page.
         */
        public function dialog($action)
        /**/
        {
        }
    }
}<commit_msg>- rewrote validation<commit_after><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\cli\stdio as stdio;
    use \org\octris\core\validate as validate;
    use \org\octris\core\provider as provider;
    
    /**
     * Implements installer for applications based on octris framework.
     *
     * @octdoc      c:app/install
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class install extends \org\octris\core\octsh\libs\plugin
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:install/$next_page
         * @var     array
         */
        protected $next_pages = array();
        /**/

        /**
         * Name of project to install.
         *
         * @octdoc  v:install/$project
         * @var     string
         */
        protected $project = '';
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:install/__construct
         */
        public function __construct()
        /**/
        {
            parent::__construct();
            
            $this->addValidator(
                'request',
                'install', 
                array(
                    'type'              => validate::T_OBJECT,
                    'keyrename'         => array('project'),
                    'properties'        => array(
                        'project'       => array(
                            'type'       => validate::T_CHAIN,
                            'chain'      => array(
                                array(
                                    'type'      => validate::T_PROJECT,
                                    'invalid'   => 'project name is invalid',
                                ),
                                array(
                                    'type'      => validate::T_CALLBACK,
                                    'callback'  => function($project, $validator) {
                                        $work = app::getPath(app::T_PATH_WORK, $project);
                                    
                                        if (!($return = is_dir($work))) {
                                            $validator->addError('project does not exist');
                                        }

                                        return $return;
                                    }
                                )
                            )
                        )        
                    )
                )
            );
        }

        /**
         * Prepare page
         *
         * @octdoc  m:install/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
            list($is_valid, $data, $errors) = $this->applyValidator('request', $action);
            
            if (!$is_valid) {
                $last_page->addErrors($errors);
                
                return $last_page;
            }

            if (!isset($data['project'])) {
                $state   = app::getInstance()->getState();
                $project = $state['project'];
            } else {
                $project = $data['project'];
            }
        
            $env  = provider::access('env');
            $base = $env->getValue('OCTRIS_BASE', validate::T_PATH);
            $work = app::getPath(app::T_PATH_WORK, $project);

            // create directories
            if ($project == 'org.octris.core') {
                mkdir($base . '/cache',     0755, true);
                mkdir($base . '/data',      0755, true);
                mkdir($base . '/etc',       0755, true);
                mkdir($base . '/host',      0755, true);
                mkdir($base . '/libs',      0755, true);
                mkdir($base . '/locale',    0755, true);
                mkdir($base . '/log',       0755, true);
                mkdir($base . '/templates', 0755, true);
                mkdir($base . '/tools',     0755, true);
            } elseif (!is_dir($base . '/host')) {
                $last_page->addError("You have to install 'org.octris.core' first");
                
                return $last_page;
            } else {
                mkdir($base . '/host/' . $project,             0755, true);
                mkdir($base . '/host/' . $project . '/libsjs', 0777, true);
                mkdir($base . '/host/' . $project . '/styles', 0777, true);
            }
            
            mkdir($base . '/cache/' . $project . '/data',        0777, true);
            mkdir($base . '/cache/' . $project . '/templates_c', 0777, true);
            
            // create symlinks
            if (is_dir($work . '/data')) {
                symlink($work . '/data', $base . '/data/' . $project);
            }
            if (is_dir($work . '/etc')) {
                symlink($work . '/etc', $base . '/etc/' . $project);
            }
            if (is_dir($work . '/libs')) {
                symlink($work . '/libs', $base . '/libs/' . $project);
            }
            if (is_dir($work . '/locale')) {
                symlink($work . '/locale', $base . '/locale/' . $project);
            }
            if (is_dir($work . '/templates')) {
                symlink($work . '/templates', $base . '/templates/' . $project);
            }

            if ($project != 'org.octris.core') {
                if (is_file($work . '/host/index.php')) {
                    symlink($work . '/host/index.php',  $base . '/host/' . $project . '/index.php');
                }
                if (is_file($work . '/host/robots.txt')) {
                    symlink($work . '/host/robots.txt', $base . '/host/' . $project . '/robots.txt');
                }
                if (is_dir($work . '/host/error')) {
                    symlink($work . '/host/error',      $base . '/host/' . $project . '/error');
                }
                if (is_dir($work . '/host/resources')) {
                    symlink($work . '/host/resources',  $base . '/host/' . $project . '/resources');
                }
            }
        }

        /**
         * Validate parameters.
         *
         * @octdoc  m:help/validate
         * @param   string                          $action         Action that led to current page.
         * @return  
         */
        public function validate()
        /**/
        {
            return true;
        }

        /**
         * Implements dialog.
         *
         * @octdoc  m:install/dialog
         * @param   string                          $action         Action that led to current page.
         */
        public function dialog($action)
        /**/
        {
        }
    }
}
{'fraction_non_alphanumeric': 0.14135886912904697, 'fraction_numerical': 0.00919592643258854, 'mean_word_length': 1.0490501401432575, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '649469', 'n_tokens_mistral': 3587, 'n_tokens_neox': 3360, 'n_words': 757}