/** * Generate documentation for a given bundles. If no bundles are provided * documentation will be generated for all registered bundles. * * @param array $bundles * @return void */ public function bundle(array $bundles = array()) { // If no bundles are provided documentation will be generated for all // registered bundles. if (count($bundles) === 0) { $bundles = Bundle::names(); } // Remove any bundles that have not been registered, and give a // warning for each one we come across. $bundles = array_filter($bundles, function ($name) { if (!Bundle::exists($name)) { if ($name == DEFAULT_BUNDLE) { return true; } echo "Bundle [{$name}] is not registered.", PHP_EOL; return false; } return true; }); // If there are no registered bundles then exit with a message if (count($bundles) === 0) { echo PHP_EOL, "Please register your bundles and try again.", PHP_EOL; return; } // Get the options $options = $this->config(array_map(array('Bundle', 'path'), $bundles)); // Run ApiGen $this->apigen($options); }
/** * Get all of the files at a given path. * * @param string $path * @return array */ protected function globSeedFiles() { if (isset($this->seedFiles)) { return $this->seedFiles; } // If the seeds haven't been read before, we will glob the directories and sort // them alphabetically just in case the developer is using numbers to make // the seed run in a certain order based on their database design needs. $folders = array(path('app') . 'seeds' . DS); foreach (Bundle::$bundles as $bundle) { $folders[] = Bundle::path($bundle['location']) . 'seeds' . DS; } $files = array(); foreach ($folders as $folder) { $files = array_merge($files, glob($folder . '*.php')); } if (false !== $this->getParameter('except')) { $exclude = explode(',', $this->getParameter('except')); foreach ($files as $key => $file) { if (in_array(pathinfo($file, PATHINFO_FILENAME), $exclude)) { unset($files[$key]); } } } sort($files); return $this->seedFiles = $files; }
/** * Get files for comparision editing * * @param string $name * @param string $location * @param string $translation * @return array */ public static function get_files($name, $location, $translation) { $path = \Laravel\Bundle::path($location); if (!is_file($path . 'language/' . $translation . '/' . $name . '.php')) { return null; } $language['from'] = (require $path . 'language/' . \Laravel\Config::get('language-builder::builder.base_lang') . '/' . $name . '.php'); $language['to'] = (require $path . 'language/' . $translation . '/' . $name . '.php'); return $language; }
/** * Get the stub migration with the proper class name. * * @param string $bundle * @param string $migration * @return string */ protected function stub($bundle, $migration) { $stub = File::get(Bundle::path('doctrine') . 'migration_stub' . EXT); $prefix = Bundle::class_prefix($bundle); // The class name is formatted simialrly to tasks and controllers, // where the bundle name is prefixed to the class if it is not in // the default "application" bundle. $class = $prefix . Str::classify($migration); return str_replace('{{class}}', $class, $stub); }
/** * Get the path to a view on disk. * * @param $view * * @return string * @throws \Exception */ protected function path($view) { $view = str_replace('.', '/', $view); $this->bundle_root = $root = Bundle::path(Bundle::name($view)) . 'views'; $path = $root . DS . Bundle::element($view) . $this->template_ext; if (file_exists($path)) { $this->template = $view . $this->template_ext; return $path; } throw new \Exception("View [{$view}] does not exist."); }
/** * Load all the bundles with language files and get their paths * * @param string $lang * @return array */ public static function bundles($lang = null) { $folders = array(); // Get the bundle languages if ($bundles = \Laravel\Bundle::all()) { foreach ($bundles as $bundle) { if (is_dir(\Laravel\Bundle::path($bundle['location']) . '/language/' . $lang)) { $folders[] = array('path' => \Laravel\Bundle::path($bundle['location']) . 'language/', 'name' => $bundle); } } } return $folders; }
/** * Run the tests for a given bundle. * * @param array $bundles * @return void */ public function bundle($bundles = array()) { if (count($bundles) == 0) { $bundles = Bundle::names(); } foreach ($bundles as $bundle) { // To run PHPUnit for the application, bundles, and the framework // from one task, we'll dynamically stub PHPUnit.xml files via // the task and point the test suite to the correct directory // based on what was requested. if (is_dir($path = Bundle::path($bundle) . 'tests')) { $this->stub($path); $this->test(); } } }
/** * Get the displayable name for a given attribute. * * @param string $attribute * @return string */ protected function attribute($attribute) { $bundle = Bundle::prefix($this->bundle); // More reader friendly versions of the attribute names may be stored // in the validation language file, allowing a more readable version // of the attribute name to be used in the message. // // If no language line has been specified for the attribute, all of // the underscores will be removed from the attribute name and that // will be used as the attribtue name. $line = "{$bundle}validation.attributes.{$attribute}"; $display = Lang::line($line)->get($this->language); return is_null($display) ? str_replace('_', ' ', $attribute) : $display; }
@if(isset($modules) and !empty($modules)) <?php $installed_modules = Config::get('installed_modules'); ?> @foreach($modules as $module) <tr id="{{$module->slug}}"> <?php $bundle = \Laravel\Bundle::get($module->slug); ?> <?php $handles = isset($bundle['handles']) ? 1 : 0; ?> @if( isset($installed_modules[$module->slug]) and $module->enabled == true and $handles == 1) <td class="collapse"><a href="{{ URL::base().'/'.ADM_URI.'/'.$module->slug }}">{{ $module->name }}</a></td> @else <td class="collapse">{{ $module->name }}</td> @endif <td>{{ $module->description }}<p>{{ $module->requirements_to_string() }}</p></td> <td>{{ $module->version }}</td> <td class="action-buttons-{{$module->slug}}"> @if($module->enabled == true and isset($installed_modules[$module->slug])) <a data-verb="PUT" data-module="modules" data-title="{{ Lang::line('modules::lang.Are you sure you wanto to disable ":module_name"?', array('module_name' => $module->name))->get(ADM_LANG) }}" class="confirm btn btn-mini" href="{{ URL::base().'/'.ADM_URI.'/' }}modules/disable/{{ $module->slug }}"><i class="icon-minus"></i> {{ Lang::line('modules::lang.disable')->get(ADM_LANG) }}</a> @endif @if( $module->enabled == false and isset($installed_modules[$module->slug]) ) <a data-verb="PUT" data-module="modules" data-title="{{ Lang::line('modules::lang.Are you sure you wanto to enable ":module_name"?', array('module_name' => $module->name))->get(ADM_LANG) }}" class="confirm btn btn-mini btn-success" href="{{ URL::base().'/'.ADM_URI.'/' }}modules/enable/{{ $module->slug }}"><i class="icon-plus"></i> {{ Lang::line('modules::lang.enable')->get(ADM_LANG) }}</a> <a data-module="modules" data-verb="DELETE" data-title="{{ Lang::line('modules::lang.Are you sure you wanto to uninstall ":module_name"?', array('module_name' => $module->name))->get(ADM_LANG) }}" class="btn btn-mini btn-danger confirm" href="{{ URL::base().'/'.ADM_URI.'/' }}modules/{{ $module->slug }}"><i class="icon-remove icon-white"></i> {{ Lang::line('modules::lang.Uninstall')->get(ADM_LANG) }}</a>
/** * Register the auto-loading configuration for a bundle. * * @param string $bundle * @param array $config * @return void */ protected static function autoloads($bundle, $config) { $path = rtrim(Bundle::path($bundle), DS); foreach ($config['autoloads'] as $type => $mappings) { // When registering each type of mapping we'll replace the (:bundle) // place-holder with the path to the bundle's root directory, so // the developer may dryly register the mappings. $mappings = array_map(function ($mapping) use($path) { return str_replace('(:bundle)', $path, $mapping); }, $mappings); // Once the mappings are formatted, we will call the Autoloader // function matching the mapping type and pass in the array of // mappings so they can be registered and used. Autoloader::$type($mappings); } }
/** * Generate an action URI by convention. * * @param string $action * @param array $parameters * @return string */ protected static function convention($action, $parameters) { list($bundle, $action) = Bundle::parse($action); $bundle = Bundle::get($bundle); // If a bundle exists for the action, we will attempt to use it's "handles" // clause as the root of the generated URL, as the bundle can only handle // URIs that begin with that string and no others. $root = $bundle['handles'] ?: ''; $parameters = implode('/', $parameters); // We'll replace both dots and @ signs in the URI since both are used // to specify the controller and action, and by convention should be // translated into URI slashes for the URL. $uri = $root . '/' . str_replace(array('.', '@'), '/', $action); $uri = static::to(str_finish($uri, '/') . $parameters); return trim($uri, '/'); }
/** * Determine if the given view exists. * * @param string $view * @param boolean $return_path * @return string|bool */ public static function exists($view, $return_path = false) { list($bundle, $view) = Bundle::parse($view); $view = str_replace('.', '/', $view); // We delegate the determination of view paths to the view loader event // so that the developer is free to override and manage the loading // of views in any way they see fit for their application. $path = Event::until(static::loader, array($bundle, $view)); if (!is_null($path)) { return $return_path ? $path : true; } return false; }
/** * Get the displayable name for a given attribute. * * @param string $attribute * @return string */ protected function attribute($attribute) { $bundle = Bundle::prefix($this->bundle); // More reader friendly versions of the attribute names may be stored // in the validation language file, allowing a more readable version // of the attribute name in the message. $line = "{$bundle}validation.attributes.{$attribute}"; if (Lang::has($line, $this->language)) { return Lang::line($line)->get($this->language); } else { return str_replace('_', ' ', $attribute); } }
/** * Create a new HelpSpot Migration instance. * * @return void */ public function __construct() { Bundle::start('doctrine'); $this->em = IoC::resolve('doctrine::manager'); $this->sm = $this->em->getConnection()->getSchemaManager(); }
<?php namespace Laravel\CLI; defined('DS') or die('No direct script access.'); use Laravel\Bundle; use Laravel\Config; use Laravel\Request; /** * Fire up the default bundle. This will ensure any dependencies that * need to be registered in the IoC container are registered and that * the auto-loader mappings are registered. */ Bundle::start(DEFAULT_BUNDLE); /** * The default database connection may be set by specifying a value * for the "database" CLI option. This allows migrations to be run * conveniently for a test or staging database. */ if (!is_null($database = get_cli_option('db'))) { Config::set('database.default', $database); } /** * We will register all of the Laravel provided tasks inside the IoC * container so they can be resolved by the task class. This allows * us to seamlessly add tasks to the CLI so that the Task class * doesn't have to worry about how to resolve core tasks. */ require path('sys') . 'cli/dependencies' . EXT; /** * We will wrap the command execution in a try / catch block and
/** * Get the array of configuration paths that should be searched for a bundle. * * @param string $bundle * @return array */ protected static function paths($bundle) { $paths[] = Bundle::path($bundle) . 'config/'; // Configuration files can be made specific for a given environment. If an // environment has been set, we will merge the environment configuration // in last, so that it overrides all other options. if (!is_null(Request::env())) { $paths[] = $paths[count($paths) - 1] . Request::env() . '/'; } return $paths; }
/** * Get the path to a bundle's language file. * * @param string $bundle * @param string $language * @param string $file * @return string */ protected static function path($bundle, $language, $file) { return Bundle::path($bundle) . "language/{$language}/{$file}" . EXT; }
/** * Publish bundle assets to the public directory. * * @param array $bundles * @return void */ public function publish($bundles) { if (count($bundles) == 0) { $bundles = Bundle::names(); } array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'publish')); }
public static function migrate($module_slug, $action = 'run') { require path('sys') . 'cli' . DS . 'dependencies' . EXT; try { $migrations_path = path('bundle') . $module_slug . DS . 'migrations' . DS; if (File::exists($migrations_path)) { $migration_files = glob($migrations_path . '*.php'); if (!empty($migration_files)) { if ($action == 'run') { Bundle::register($module_slug); $custom_tables = \Laravel\CLI\Command::run(array('migrate', $module_slug)); Bundle::disable($module_slug); return true; } if ($action == 'rollback') { Bundle::register($module_slug); $custom_tables = \Laravel\CLI\Command::run(array('migrate:rollback', $module_slug)); Bundle::disable($module_slug); return true; } Log::error('Failed to run migrations for module ' . $module_slug . '. Migration command [' . $action . '] is invalid.'); static::$errors->add('installer', 'Failed to run migrations for module ' . $module_slug . '. Migration command [' . $action . '] is invalid.'); return false; } } return true; } catch (\Exception $e) { Log::error($e->getMessage()); //static::$errors->add('installer', 'Failed to run migrations.'); return false; } }
/** * Format a bundle and controller identifier into the Form's or Page's class name. * * @param string $bundle * @param string $controller * * @return string */ protected static function format($bundle, $path, $type) { return Bundle::class_prefix($bundle) . Str::classify($path) . '_' . ucfirst($type); }
/** * Get the filters that are attached to the route for a given event. * * @param string $event * @return array */ protected function filters($event) { $global = Bundle::prefix($this->bundle) . $event; $filters = array_unique(array($event, $global)); // Next we will check to see if there are any filters attached to // the route for the given event. If there are, we'll merge them // in with the global filters for the event. if (isset($this->action[$event])) { $assigned = Filter::parse($this->action[$event]); $filters = array_merge($filters, $assigned); } return array(new Filter_Collection($filters)); }
/** * Parse the filter string, returning the filter name and parameters. * * @param string $filter * @return array */ public function get($filter) { // If the parameters were specified by passing an array into the collection, // then we will simply return those parameters. Combining passed parameters // with parameters specified directly in the filter attachment is not // currently supported by the framework. if (!is_null($this->parameters)) { return array($filter, $this->parameters()); } // If no parameters were specified when the collection was created, we will // check the filter string itself to see if the parameters were injected // into the string as raw values, such as "role:admin". if (($colon = strpos(Bundle::element($filter), ':')) !== false) { $parameters = explode(',', substr(Bundle::element($filter), $colon + 1)); // If the filter belongs to a bundle, we need to re-calculate the position // of the parameter colon, since we originally calculated it without the // bundle identifier because the identifier uses colons as well. if (($bundle = Bundle::name($filter)) !== DEFAULT_BUNDLE) { $colon = strlen($bundle . '::') + $colon; } return array(substr($filter, 0, $colon), $parameters); } // If no parameters were specified when the collection was created or // in the filter string, we will just return the filter name as is // and give back an empty array of parameters. return array($filter, array()); }
} /* |-------------------------------------------------------------------------- | Set The CLI Options Array |-------------------------------------------------------------------------- | | If the current request is from the Artisan command-line interface, we | will parse the command line arguments and options and set them the | array of options in the $_SERVER global array for convenience. | */ if (defined('STDIN')) { $console = CLI\Command::options($_SERVER['argv']); list($arguments, $options) = $console; $options = array_change_key_case($options, CASE_UPPER); $_SERVER['CLI'] = $options; } /* |-------------------------------------------------------------------------- | Register The Laravel Bundles |-------------------------------------------------------------------------- | | Finally we will register all of the bundles that have been defined for | the application. None of them will be started yet, but will be setup | so that they may be started by the developer at any time. | */ $bundles = (require path('app') . 'bundles' . EXT); foreach ($bundles as $bundle => $config) { Bundle::register($bundle, $config); }
/** * Get the path to a given view on disk. * * @param string $view * @return string */ protected function path($view) { $view = str_replace('.', '/', $view); $root = Bundle::path(Bundle::name($view)) . 'views/'; // Views may have the normal PHP extension or the Blade PHP extension, so // we need to check if either of them exist in the base views directory // for the bundle and return the first one we find. foreach (array(EXT, BLADE_EXT) as $extension) { if (file_exists($path = $root . Bundle::element($view) . $extension)) { return $path; } } throw new \Exception("View [{$view}] does not exist."); }
/** * Format a bundle and controller identifier into the controller's class name. * * @param string $bundle * @param string $controller * @return string */ protected static function format($bundle, $controller) { return Bundle::class_prefix($bundle) . Str::classify($controller) . '_Controller'; }
/** * Format a bundle and task into a task class name. * * @param string $bundle * @param string $task * @return string */ protected static function format($bundle, $task) { $prefix = Bundle::class_prefix($bundle); return '\\' . $prefix . Str::classify($task) . '_Task'; }
/** * Get the filters that are attached to the route for a given event. * * @param string $event * @return array */ protected function filters($event) { $global = Bundle::prefix($this->bundle) . $event; $filters = array_unique(array($event, $global)); // Next we will check to see if there are any filters attached to // the route for the given event. If there are, we'll merge them // in with the global filters for the event. if (isset($this->action[$event])) { $assigned = Filter::parse($this->action[$event]); $filters = array_merge($filters, $assigned); } // Next we will attach any pattern type filters to the array of // filters as these are matched to the route by the route's // URI and not explicitly attached to routes. if ($event == 'before') { $filters = array_merge($filters, $this->patterns()); } return array(new Filter_Collection($filters)); }
/** * Search the routes for the route matching a method and URI. * * @param string $method * @param string $uri * @return Route */ public static function route($method, $uri) { Bundle::start($bundle = Bundle::handles($uri)); $routes = (array) static::method($method); // Of course literal route matches are the quickest to find, so we will // check for those first. If the destination key exists in the routes // array we can just return that route now. if (array_key_exists($uri, $routes)) { $action = $routes[$uri]; return new Route($method, $uri, $action); } // If we can't find a literal match we'll iterate through all of the // registered routes to find a matching route based on the route's // regular expressions and wildcards. if (!is_null($route = static::match($method, $uri))) { return $route; } }
/** * Grab all of the migration filenames for a bundle. * * @param string $bundle * @return array */ protected function migrations($bundle) { $files = glob(Bundle::path($bundle) . 'migrations/*_*' . EXT); // When open_basedir is enabled, glob will return false on an // empty directory, so we will return an empty array in this // case so the application doesn't bomb out. if ($files === false) { return array(); } // Once we have the array of files in the migration directory, // we'll take the basename of the file and remove the PHP file // extension, which isn't needed. foreach ($files as &$file) { $file = str_replace(EXT, '', basename($file)); } // We'll also sort the files so that the earlier migrations // will be at the front of the array and will be resolved // first by this class' resolve method. sort($files); return $files; }
/** * Get the array of configuration paths that should be searched for a bundle. * * @param string $bundle * @return array */ protected static function paths($bundle) { $paths[] = Bundle::path($bundle) . 'config/'; // Configuration files can be made specific for a given environment. If an // environment has been set, we will merge the environment configuration // in last, so that it overrides all other options. if (isset($_SERVER['LARAVEL_ENV'])) { $paths[] = $paths[count($paths) - 1] . $_SERVER['LARAVEL_ENV'] . '/'; } return $paths; }