/** * 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; }
/** * Upgrade the given bundles for the application. * * @param array $bundles * @return void */ public function upgrade($bundles) { if (count($bundles) == 0) { $bundles = Bundle::names(); } foreach ($bundles as $name) { if (!Bundle::exists($name)) { echo "Bundle [{$name}] is not installed!"; continue; } // First we want to retrieve the information for the bundle, such as // where it is currently installed. This will allow us to upgrade // the bundle into it's current installation path. $location = Bundle::path($name); // If the bundle exists, we will grab the data about the bundle from // the API so we can make the right bundle provider for the bundle, // since we don't know the provider used to install. $response = $this->retrieve($name); if ($response['status'] == 'not-found') { continue; } // Once we have the bundle information from the API, we'll simply // recursively delete the bundle and then re-download it using // the correct provider assigned to the bundle. File::rmdir($location); $this->download($response['bundle'], $location); echo "Bundle [{$name}] has been upgraded!" . PHP_EOL; } }
/** * 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 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 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; }
/** * 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."); }
/** * 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(); } } }
/** * 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; }
/** * Load the file for a given controller. * * @param string $bundle * @param string $controller * @return bool */ protected static function load($bundle, $controller) { $controller = strtolower(str_replace('.', '/', $controller)); if (file_exists($path = Bundle::path($bundle) . 'controllers/' . $controller . EXT)) { require_once $path; return true; } return false; }
/** * 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; }
/** * Get the "from" location of the bundle's assets. * * @param string $bundle * @return string */ protected function from($bundle) { return Bundle::path($bundle) . 'public'; }
/** * Generate a new migration file. * * @param array $arguments * @return string */ public function make($arguments = array()) { if (count($arguments) == 0) { throw new \Exception("I need to know what to name the migration."); } list($bundle, $migration) = Bundle::parse($arguments[0]); // The migration path is prefixed with the date timestamp, which // is a better way of ordering migrations than a simple integer // incrementation, since developers may start working on the // next migration at the same time unknowingly. $prefix = date('Y_m_d_His'); $path = Bundle::path($bundle) . 'migrations' . DS; // If the migration directory does not exist for the bundle, // we will create the directory so there aren't errors when // when we try to write the migration file. if (!is_dir($path)) { mkdir($path); } $file = $path . $prefix . '_' . $migration . EXT; File::put($file, $this->stub($bundle, $migration)); echo "Great! New migration created!"; // Once the migration has been created, we'll return the // migration file name so it can be used by the task // consumer if necessary for futher work. return $file; }
/** * 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); } }
/** * 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; }
/** * Resolve an instance of the given task name. * * <code> * // Resolve an instance of a task * $task = Command::resolve('application', 'migrate'); * * // Resolve an instance of a task wtihin a bundle * $task = Command::resolve('bundle', 'foo'); * </code> * * @param string $bundle * @param string $task * @return object */ public static function resolve($bundle, $task) { $identifier = Bundle::identifier($bundle, $task); // First we'll check to see if the task has been registered in the // application IoC container. This allows all dependencies to be // injected into tasks for more testability. if (IoC::registered("task: {$identifier}")) { return IoC::resolve("task: {$identifier}"); } // If the task file exists, we'll format the bundle and task name // into a task class name and resolve an instance of the so that // the requested method may be executed. if (file_exists($path = Bundle::path($bundle) . 'tasks/' . $task . EXT)) { require $path; $task = static::format($bundle, $task); return new $task(); } }
/** * 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 the given template * * @param string $bundle The name of the template's bundle * @param string $name The name of the template * @return string The path to the template source */ public function getPath($bundle, $name) { $name = str_replace('.', '/', $name); return Bundle::path($bundle) . 'views/' . $name . $this->ext; }
<?php namespace Admin\Libraries; use Laravel\Bundle; require Bundle::path('admin') . 'libraries/sensor/' . strtolower(PHP_OS) . '.php'; use Laravel\Config, Admin\Libraries\Sensor\IO as Sensor; use Admin\Models\Monitor\Server, Admin\Models\Monitor\Load; /********************************************************************* * Class : Sneakpeak * Function : System Server Status Class * Author : joharijumali * Description: Class to read hdd, cpu, memory, loads info of current host **********************************************************************/ class Sneakpeak { /** * undocumented function * * @return void * @author **/ public static function initsequence() { $date = date("Y-m-d H:i:s"); $server = new Server(); $id = $server->cron($date); $load = new Load(); $load->cron($id, Sensor::restLoad(), $date); $load->stor($id, Sensor::restLoad(), $date, 'stor_load'); }
/** * Parse the path to the form or page * * @param string $name * @param string $type * * @return array($file,$class_name,$method) */ protected static function parse($name, $type) { list($path, $method) = explode('@', static::$modules[$type][$name]); list($bundle, $path) = Bundle::parse($path); $file = Bundle::path($bundle) . Str::plural($type) . DS . str_replace('.', DS, $path) . EXT; $class_name = static::format($bundle, $path, $type); return array($file, $class_name, $method); }
/** * Load all of the language lines from a language file. * * @param string $bundle * @param string $language * @param string $file * @return bool */ public static function load($bundle, $language, $file) { if (isset(static::$lines[$bundle][$language][$file])) { return true; } $lines = array(); // Language files can belongs to the application or to any bundle // that is installed for the application. So, we'll need to use // the bundle's path when checking for the file. // // This is similar to the loading method for configuration files, // but we do not need to cascade across directories since most // likely language files are static across environments. $path = Bundle::path($bundle) . "language/{$language}/{$file}" . EXT; if (file_exists($path)) { $lines = (require $path); } static::$lines[$bundle][$language][$file] = $lines; return count($lines) > 0; }