Ejemplo n.º 1
0
 public static function from_upload(array $data, $key_mode = false)
 {
     $create = array();
     $file = $data['file'];
     $user = $data['user'];
     if ($key_mode) {
         $keys = collect(function ($key) {
             return $key->key;
         }, Pki::find('all', array('select' => '`key`', 'conditions' => array('user_id' => $user->id))));
         $sig = $data['sig'];
         if (!static::verify($file, $sig, $keys)) {
             throw new NimbleException('Invalid package signature');
         }
     }
     $package_data = new PackageExtractor($file);
     if ($user->pear_farm_url() !== $package_data->data['channel']) {
         throw new Exception('Package channel ' . $package_data->data['channel'] . ' does not match ' . $user->pear_farm_url());
     }
     $name = $package_data->data['name'];
     $version = $package_data->data['version']['release'];
     $stability = $package_data->data['stability']['release'];
     if (!Package::exists(array('name' => $name, 'user_id' => $user->id))) {
         $package = new Package(array('name' => $name, 'user_id' => $user->id, 'category_id' => Category::find_by_name('Default')->id));
     } else {
         $package = Package::find('first', array('conditions' => array('name' => $name, 'user_id' => $user->id)));
     }
     if (!$package->new_record && Version::exists(array('version' => $version, 'package_id' => $package->id))) {
         throw new NimbleException("There is already a {$version}. You cannot replace existing packages. Please bump the version number and try again." . " You can delete a version from the web interface if needed.");
     }
     $package->move_uploaded_file($file, $version);
     $type = VersionType::find_by_name($stability);
     $package->versions = array(array('raw_xml' => $package_data->get_package_xml(), 'version' => $version, 'meta' => serialize($package_data->data), 'version_type_id' => $type->id, 'summary' => $package_data->data['summary'], 'description' => $package_data->data['description'], 'min_php' => $package_data->data['dependencies']['required']['php']['min']));
     $package->save();
     return $package;
 }
Ejemplo n.º 2
0
 /**
  * Replaces an autoloader in a package to help development
  *
  * @param string $package
  *
  * @return boolean
  */
 public static function package($package)
 {
     if ($package = \Package::exists($package)) {
         return static::path($package . 'vendor/autoload.php');
     }
     return false;
 }
Ejemplo n.º 3
0
 public static function forge($args, $subfolder)
 {
     $default_files = array(array('source' => $subfolder . '/controllers/base.php', 'location' => 'classes/controller/base.php', 'type' => 'controller'), array('source' => $subfolder . '/controllers/admin.php', 'location' => 'classes/controller/admin.php', 'type' => 'controller'), array('source' => '/template.php', 'location' => 'views/admin/template.php', 'type' => 'views'), array('source' => 'dashboard.php', 'location' => 'views/admin/dashboard.php', 'type' => 'views'), array('source' => 'login.php', 'location' => 'views/admin/login.php', 'type' => 'views'));
     foreach ($default_files as $file) {
         // check if there's a template in app, and if so, use that
         if (is_file(APPPATH . 'views/' . static::$view_subdir . $file['source'])) {
             Generate::create(APPPATH . $file['location'], file_get_contents(APPPATH . 'views/' . static::$view_subdir . $file['source']), $file['type']);
         } else {
             Generate::create(APPPATH . $file['location'], file_get_contents(\Package::exists('oil') . 'views/' . static::$view_subdir . $file['source']), $file['type']);
         }
     }
     parent::forge($args, $subfolder);
 }
Ejemplo n.º 4
0
 public static function uninstall($package)
 {
     // Check to see if this package is already installed
     if (!($package_folder = \Package::exists($package))) {
         throw new Exception('Package "' . $package . '" is not installed.');
         return false;
     }
     // Check to see if this package is already installed
     if (in_array($package, static::$_protected)) {
         throw new Exception('Package "' . $package . '" cannot be uninstalled.');
         return false;
     }
     \Cli::write('Package "' . $package . '" was uninstalled.', 'yellow');
     \File::delete_dir($package_folder);
 }
 public function packages_post()
 {
     $this->layout = '';
     $cycle_id = Input::get('cycle_id');
     $service_id = Input::get('service_id');
     $price = Input::get('price');
     if (!Package::exists($service_id, $cycle_id)) {
         if (!empty($price) || is_numeric($price)) {
             $package = new Package();
             $package->service_id = $service_id;
             $package->cycle_id = $cycle_id;
             $package->price = $price;
             $package->save();
             return Redirect::to('packages')->with('success', 'Package has been successfully saved.');
         } else {
             return Redirect::to('packages')->with('error', 'Price must be a number.');
         }
     } else {
         return Redirect::to('packages')->with('error', 'Package already exists.');
     }
 }
Ejemplo n.º 6
0
    public static function views($args, $subfolder, $build = true)
    {
        $controller = strtolower(array_shift($args));
        $controller_title = \Inflector::humanize($controller);
        $base_path = APPPATH;
        if ($module = \Cli::option('module')) {
            if (!($base_path = \Module::exists($module))) {
                throw new Exception('Module ' . $module . ' was not found within any of the defined module paths');
            }
        }
        $view_dir = $base_path . 'views/' . trim(str_replace(array('_', '-'), DS, $controller), DS) . DS;
        $args or $args = array('index');
        // Make the directory for these views to be store in
        is_dir($view_dir) or static::$create_folders[] = $view_dir;
        // Add the default template if it doesn't exist
        if (!is_file($app_template = $base_path . 'views/template.php')) {
            static::create($app_template, file_get_contents(\Package::exists('oil') . 'views/scaffolding/template.php'), 'view');
        }
        $subnav = '';
        foreach ($args as $nav_item) {
            $subnav .= "\t<li class='<?php echo Arr::get(\$subnav, \"{$nav_item}\" ); ?>'><?php echo Html::anchor('{$controller}/{$nav_item}','" . \Inflector::humanize($nav_item) . "');?></li>\n";
        }
        foreach ($args as $action) {
            $view_title = (\Cli::option('with-presenter') or \Cli::option('with-viewmodel')) ? '<?php echo $content; ?>' : \Inflector::humanize($action);
            $view = <<<VIEW
<ul class="nav nav-pills">
{$subnav}
</ul>
<p>{$view_title}</p>
VIEW;
            // Create this view
            static::create($view_dir . $action . '.php', $view, 'view');
        }
        $build and static::build();
    }
Ejemplo n.º 7
0
 /**
  * Forge
  *
  * @param   array   Fields mainly
  * @param   string  Subfolder (or admin "theme") where views are held
  * @return	mixed
  */
 public static function forge($args, $subfolder)
 {
     $data = array();
     $subfolder = trim($subfolder, '/');
     if (!is_dir(\Package::exists('oil') . 'views/' . static::$view_subdir . $subfolder)) {
         throw new Exception('The subfolder for admin templates does not exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Go through all arguments after the first and make them into field arrays
     $data['fields'] = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match(static::$fields_regex, $arg, $matches);
         if (!isset($matches[1])) {
             throw new Exception('One or more fields were badly specified. Ensure they are name:type');
         }
         $data['fields'][] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $name = array_shift($args);
     // Replace / with _ and classify the rest. DO NOT singularize
     $controller_name = \Inflector::classify(static::$controller_prefix . str_replace(DS, '_', $name), false);
     // Replace / with _ and classify the rest. Singularize
     $model_name = \Inflector::classify(static::$model_prefix . str_replace(DS, '_', $name), !\Cli::option('singular'));
     // Either foo or folder/foo
     $view_path = $controller_path = str_replace(array('_', '-'), DS, \Str::lower($controller_name));
     // Models are always singular, tough!
     $model_path = str_replace(array('_', '-'), DS, \Str::lower($model_name));
     // uri's have forward slashes, DS is a backslash on Windows
     $uri = str_replace(DS, '/', $controller_path);
     $data['include_timestamps'] = !\Cli::option('no-timestamp', false);
     // If a folder is used, the entity is the last part
     $name_parts = explode(DS, $name);
     $data['singular_name'] = \Cli::option('singular') ? end($name_parts) : \Inflector::singularize(end($name_parts));
     $data['plural_name'] = \Cli::option('singular') ? $data['singular_name'] : \Inflector::pluralize($data['singular_name']);
     $data['table'] = \Inflector::tableize($model_name);
     $data['controller_parent'] = static::$controller_parent;
     /** Generate the Migration **/
     $migration_args = $args;
     // add timestamps to the table if needded
     if ($data['include_timestamps']) {
         if (\Cli::option('mysql-timestamp', false)) {
             $migration_args[] = 'created_at:date:null[1]';
             $migration_args[] = 'updated_at:date:null[1]';
         } else {
             $migration_args[] = 'created_at:int:null[1]';
             $migration_args[] = 'updated_at:int:null[1]';
         }
     }
     $migration_name = \Cli::option('singular') ? \Str::lower($name) : \Inflector::pluralize(\Str::lower($name));
     array_unshift($migration_args, 'create_' . $migration_name);
     Generate::migration($migration_args, false);
     // Merge some other data in
     $data = array_merge(compact(array('controller_name', 'model_name', 'model_path', 'view_path', 'uri')), $data);
     /** Generate the Model **/
     $model = \View::forge(static::$view_subdir . $subfolder . '/model', $data);
     Generate::create(APPPATH . 'classes/model/' . $model_path . '.php', $model, 'model');
     /** Generate the Controller **/
     $controller = \View::forge(static::$view_subdir . $subfolder . '/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/view', $data)), array('name' => 'create', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/delete', $data)));
     Generate::create(APPPATH . 'classes/controller/' . $controller_path . '.php', $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $controller_path . '/' . $view . '.php', \View::forge(static::$view_subdir . $subfolder . '/views/actions/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         // check if there's a template in app, and if so, use that
         if (file_exists(APPPATH . 'views/' . static::$view_subdir . $subfolder . '/views/template.php')) {
             Generate::create($app_template, file_get_contents(APPPATH . 'views/' . static::$view_subdir . $subfolder . '/views/template.php'), 'view');
         } else {
             Generate::create($app_template, file_get_contents(\Package::exists('oil') . 'views/' . static::$view_subdir . 'template.php'), 'view');
         }
     }
     Generate::build();
 }
Ejemplo n.º 8
0
<?php

/**
 * Fuel
 *
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package    Fuel
 * @version    1.8
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2016 Fuel Development Team
 * @link       http://fuelphp.com
 */
/**
 * NOTICE:
 *
 * If you need to make modifications to the default configuration, copy
 * this file to your app/config folder, and make them in there.
 *
 * This will allow you to upgrade fuel without losing your custom config.
 */
return array('extensions' => array('php' => 'View', 'twig' => 'View_Twig', 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'twig'), 'mustache' => 'View_Mustache', 'md' => 'View_Markdown', 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), 'jade' => 'View_Jade', 'haml' => 'View_Haml', 'smarty' => 'View_Smarty', 'phptal' => 'View_Phptal', 'lex' => 'View_Lex'), 'View_Markdown' => array('include' => \Package::exists('parser') . 'vendor' . DS . 'markdown' . DS . 'markdown.php', 'auto_encode' => true, 'allow_php' => true), 'View_Twig' => array('auto_encode' => false, 'views_paths' => array(APPPATH . 'views'), 'delimiters' => array('tag_block' => array('left' => '{%', 'right' => '%}'), 'tag_comment' => array('left' => '{#', 'right' => '#}'), 'tag_variable' => array('left' => '{{', 'right' => '}}')), 'environment' => array('debug' => true, 'charset' => 'utf-8', 'base_template_class' => 'Twig_Template', 'cache' => APPPATH . 'cache' . DS . 'twig' . DS, 'auto_reload' => true, 'strict_variables' => true, 'autoescape' => true, 'optimizations' => -1), 'extensions' => array('Twig_Fuel_Extension')), 'View_HamlTwig' => array('auto_encode' => true, 'environment' => array('auto_escaper' => true, 'escape_html' => true, 'escape_attrs' => true, 'charset' => 'UTF-8', 'format' => 'html5')), 'View_Dwoo' => array('include' => APPPATH . 'vendor' . DS . 'Dwoo' . DS . 'dwooAutoload.php', 'auto_encode' => true, 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array('autoescape' => false, 'nested_comments' => false, 'allow_spaces' => false, 'cache_dir' => APPPATH . 'cache' . DS . 'dwoo' . DS, 'compile_dir' => APPPATH . 'cache' . DS . 'dwoo' . DS . 'compiled' . DS, 'cache_time' => 0, 'allow_php_tags' => 2, 'allow_php_func' => array())), 'View_Mustache' => array('auto_encode' => true, 'environment' => array('cache_dir' => APPPATH . 'cache' . DS . 'mustache' . DS, 'partials' => array(), 'helpers' => array(), 'charset' => 'UTF-8')), 'View_Jade' => array('cache_dir' => APPPATH . 'cache' . DS . 'jade' . DS, 'include' => APPPATH . 'vendor' . DS . 'Jade' . DS . 'autoload.php.dist', 'auto_encode' => true, 'lifetime' => 3600, 'pretty' => false), 'View_Haml' => array('include' => APPPATH . 'vendor' . DS . 'Phamlp' . DS . 'haml' . DS . 'HamlParser.php', 'auto_encode' => true, 'cache_dir' => APPPATH . 'cache' . DS . 'haml' . DS), 'View_Smarty' => array('auto_encode' => true, 'delimiters' => array('left' => '{', 'right' => '}'), 'environment' => array('compile_dir' => APPPATH . 'tmp' . DS . 'Smarty' . DS . 'templates_c' . DS, 'config_dir' => APPPATH . 'tmp' . DS . 'Smarty' . DS . 'configs' . DS, 'cache_dir' => APPPATH . 'cache' . DS . 'Smarty' . DS, 'plugins_dir' => array(), 'caching' => false, 'cache_lifetime' => 0, 'force_compile' => false, 'compile_check' => true, 'debugging' => false, 'autoload_filters' => array(), 'default_modifiers' => array())), 'View_Phptal' => array('include' => APPPATH . 'vendor' . DS . 'PHPTAL' . DS . 'PHPTAL.php', 'auto_encode' => true, 'cache_dir' => APPPATH . 'cache' . DS . 'PHPTAL' . DS, 'cache_lifetime' => 0, 'encoding' => 'UTF-8', 'output_mode' => 'PHPTAL::XHTML', 'template_repository' => '', 'force_reparse' => false), 'View_Lex' => array('scope_glue' => '.', 'allow_php' => false));
Ejemplo n.º 9
0
 /**
  * catches requested method call and runs as needed
  *
  * @param string	name of the method to run
  * @param string	any additional method arguments (not used here!)
  */
 public function __call($name, $args)
 {
     // set method name
     $name = '_' . $name;
     // make sure the called name exists
     if (!method_exists(get_called_class(), $name)) {
         return static::help();
     }
     // run app (default) migrations if default is true
     if (static::$default) {
         static::$name('default', 'app');
     }
     // run migrations on all specified modules
     foreach (static::$modules as $module) {
         // check if the module exists
         if (!\Module::exists($module)) {
             \Cli::write('Requested module "' . $module . '" does not exist!', 'light_red');
         } else {
             // run the migration
             static::$name($module, 'module');
         }
     }
     // run migrations on all specified packages
     foreach (static::$packages as $package) {
         // check if the module exists
         if (!\Package::exists($package)) {
             \Cli::write('Requested package "' . $package . '" does not exist!', 'light_red');
         } else {
             static::$name($package, 'package');
         }
     }
 }
Ejemplo n.º 10
0
    public static function views($args, $subfolder, $build = true)
    {
        $controller = strtolower(array_shift($args));
        $controller_title = \Inflector::humanize($controller);
        $view_dir = APPPATH . 'views/' . trim(str_replace(array('_', '-'), DS, $controller), DS) . DS;
        $args or $args = array('index');
        // Make the directory for these views to be store in
        is_dir($view_dir) or static::$create_folders[] = $view_dir;
        // Add the default template if it doesnt exist
        if (!file_exists($app_template = APPPATH . 'views/template.php')) {
            static::create($app_template, file_get_contents(\Package::exists('oil') . 'views/scaffolding/template.php'), 'view');
        }
        foreach ($args as $action) {
            $view_title = \Cli::option('with-viewmodel') ? '<?php echo $content; ?>' : \Inflector::humanize($action);
            $view = <<<VIEW
<p>{$view_title}</p>
VIEW;
            // Create this view
            static::create($view_dir . $action . '.php', $view, 'view');
        }
        $build and static::build();
    }