/** * 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; } }
public static function logs($logfile) { $file = File::get(path('storage') . '/logs/' . $logfile . '.log'); $array = array_reverse(explode("\n", $file)); unset($array[0]); return $array; }
/** * Install a bundle from by downloading a Zip. * * @param string $url * @param array $bundle * @param string $path * @return void */ protected function zipball($url, $bundle, $path) { $work = path('storage') . 'work/'; // When installing a bundle from a Zip archive, we'll first clone // down the bundle zip into the bundles "working" directory so // we have a spot to do all of our bundle extration work. $target = $work . 'laravel-bundle.zip'; File::put($target, $this->download($url)); $zip = new \ZipArchive(); $zip->open($target); // Once we have the Zip archive, we can open it and extract it // into the working directory. By convention, we expect the // archive to contain one root directory with the bundle. mkdir($work . 'zip'); $zip->extractTo($work . 'zip'); $latest = File::latest($work . 'zip')->getRealPath(); @chmod($latest, 0777); // Once we have the latest modified directory, we should be // able to move its contents over into the bundles folder // so the bundle will be usable by the develoepr. File::mvdir($latest, $path); File::rmdir($work . 'zip'); $zip->close(); @unlink($target); }
/** * Set the session driver to a given value. * * @param string $driver * @return void */ protected function driver($driver) { // By default no session driver is set within the configuration. // This method will replace the empty driver option with the // driver specified in the arguments. $config = File::get(path('app') . 'config/session' . EXT); $config = str_replace("'driver' => '',", "'driver' => 'database',", $config); File::put(path('app') . 'config/session' . EXT, $config); }
/** * 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); }
/** * Create an empty language file if it doesn't exist. * * @param string $path * @return bool */ public static function create($full_path) { $dir = str_replace(basename($full_path), '', $full_path); if (!is_dir($dir)) { static::make($dir); } if (!file_exists($full_path)) { $data = '<?php return array();'; \Laravel\File::put($full_path, $data); } return true; }
/** * List available artisan commands. * * @return void */ public function commands() { // read help contents $command_data = json_decode(File::get(__DIR__ . '/help.json')); // format and display help contents $i = 0; foreach ($command_data as $category => $commands) { if ($i++ != 0) { echo PHP_EOL; } echo PHP_EOL . "# {$category}" . PHP_EOL; foreach ($commands as $command => $details) { echo PHP_EOL . str_pad($command, 20) . str_pad($details->description, 30); } } }
/** * Set which types of files are accepted by the file input * */ public function accept() { $mimes = array(); // Transform all extensions/groups to mime types foreach (func_get_args() as $mime) { // Shortcuts and extensions if (in_array($mime, $this->mimeGroups)) { $mime .= '/*'; } $mime = LaravelFile::mime($mime, $mime); $mimes[] = $mime; } // Add accept attribute by concatenating the mimes $this->attributes['accept'] = implode('|', $mimes); return $this; }
/** * Generate a random key for the application. * * @param array $arguments * @return void */ public function generate($arguments = array()) { // By default the Crypter class uses AES-256 encryption which uses // a 32 byte input vector, so that is the length of string we will // generate for the application token unless another length is // specified through the CLI. $key = Str::random(array_get($arguments, 0, 32)); $config = File::get($this->path); $config = str_replace("'key' => '',", "'key' => '{$key}',", $config, $count); File::put($this->path, $config); if ($count > 0) { echo "Configuration updated with secure key!"; } else { echo "An application key already exists!"; } echo PHP_EOL; }
/** * Create a response that will force a image to be displayed inline. * * @param string $path Path to the image * @param string $name Filename * @param int $lifetime Lifetime in browsers cache * @return Response */ public static function inline($path, $name = null, $lifetime = 0) { if (is_null($name)) { $name = basename($path); } $filetime = filemtime($path); $etag = md5($filetime . $path); $time = gmdate('r', $filetime); $expires = gmdate('r', $filetime + $lifetime); $length = filesize($path); $headers = array('Content-Disposition' => 'inline; filename="' . $name . '"', 'Last-Modified' => $time, 'Cache-Control' => 'must-revalidate', 'Expires' => $expires, 'Pragma' => 'public', 'Etag' => $etag); // If enabled, we need to disable the profiler LaravelConfig::set('application.profiler', false); // Check the Browsers cache $headerTest1 = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $time; $headerTest2 = isset($_SERVER['HTTP_IF_NONE_MATCH']) && str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == $etag; if ($headerTest1 || $headerTest2) { //image is cached by the browser, we dont need to send it again return static::make('', 304, $headers); } $fileinfos = Imwg::imageInfo($path); $headers = array_merge($headers, array('Content-Type' => $fileinfos['mime'], 'Content-Length' => $length)); return static::make(File::get($path), 200, $headers); }
/** * Get a created placeholdr image content. * * @param integer $width * @param integer $height * @param string $text * @return string */ public function get($width, $height = 0, $text = '') { if (!($image_file = $this->make($width, $height, $text))) { throw new Exception('Failed to create placeholdr.'); } // Get image file contents $image_file_contents = File::get($image_file); if (Config::get('placeholdr::placeholdr.gd.save_created_placeholdrs') !== true) { File::delete($image_file); } return $image_file_contents; }
<?php Route::get('(:bundle)/rejigger.js', array('as' => 'rejigger_js', function () { return View::make('rejigger::js'); })); Route::get('(:bundle)/version', array('as' => 'rejigger_version', function () { // Don't let the controller mistake this for a regular AJAX call unset($_SERVER['HTTP_X_REQUESTED_WITH']); $uri = \Rejigger\URI::resolve(Input::get('uri')); $route = \Laravel\Routing\Router::route('GET', $uri); $response = $route->call(); $version = md5($response->content); // Parse out resources (css & script) preg_match_all('/\\<script[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $scripts); preg_match_all('/\\<link[^\\>]+href=\\"(?P<href>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $styles); preg_match_all('/\\<img[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $images); $resources = array_merge($scripts['src'], $styles['href'], $images['src']); $public = path('public'); foreach ($resources as $resource) { $resource = $public . str_replace(\Laravel\URL::base(), '', $resource); if (\Laravel\File::exists($resource)) { $version .= File::modified($resource); } } return '{ "version": "' . md5($version) . '" }'; }));
/** * Checks if the module is valid * and can be loaded * * @return Module */ public function is_valid() { $info_file_path = ''; if (!file_exists($this->path)) { $this->errors->add($this->slug, 'Module [' . $this->slug . '] was not found'); return false; } $info_files = glob($this->path . 'info.*'); if (empty($info_files)) { $this->errors->add($this->slug, 'The information file for [' . $this->slug . '] module is missing'); return false; } $info_file_path = $info_files['0']; $this->file_info_type = file_extension($info_file_path); // create method to decode // other types of info files $json_module_info = json_decode(File::get($info_file_path), true); if (!isset($json_module_info) or empty($json_module_info)) { $this->errors->add('module', 'The information file for module [' . $this->slug . '] is malformed'); return false; } foreach ($json_module_info as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } $this->exist = true; return $this; }
public static function schema($action, $module_slug) { try { // Does the schema task file exists? $schema_path = path('bundle') . $module_slug . DS . 'tasks' . DS . 'schema' . EXT; if (\Laravel\File::exists($schema_path)) { include_once $schema_path; // Does the class exists? $class = Str::title($module_slug . '_Schema_Task'); if (class_exists($class)) { $schema_class = new $class(); // The action is callable? if (is_callable(array($schema_class, $action))) { $schema_class->{$action}(); return true; } else { Log::error('Failed to run data schema for module ' . $module_slug . '. Schema action [' . $action . '] not found.'); } } else { Log::error('Failed to run data schema for module ' . $module_slug . '. Schema class [' . $class . '] not found.'); } } // we dont have task schema to run return true; } catch (\Exception $e) { Log::error($e->getMessage()); return false; } }
/** * Saves an Image * @param string $file_name The new Filename * @param bool $override True to override existing files * @param bool $destroy True to destroy the Imwg instance * @return array with infos about the image. example:<code> * ( * [width] => 32 * [height] => 32 * [type] => GIF * [attr] => width="32" height="32" * [bits] => 4 * [channels] => 3 * [mime] => image/gif * ) * </code> */ public function save($file_name, $override = true, $destroy = true) { if (static::$image_resource) { if (!File::exists($file_name) || $override) { // JPEG if (static::$file_info['type'] == "JPG") { ImageJPEG(static::$image_resource, $file_name, static::$image_quality); } elseif (static::$file_info['type'] == "GIF") { ImageGIF(static::$image_resource, $file_name); } elseif (static::$file_info['type'] == "PNG") { ImagePNG(static::$image_resource, $file_name, static::$image_quality); } } // cache $file_info $file_info = static::$file_info; if ($destroy) { // destroy all resources $this->destroy(); } // return the infos about the image return $file_info; } }
public static function remove($module_slug) { if (isset($module_slug) and !empty($module_slug)) { // Remove bundle files if (\File::rmdir(path('bundle') . $module_slug) === null) { static::$errors->add('installer', 'Module [' . $module_slug . '] was successfully removed.'); // // Remove published assets // if (File::rmdir(path('public') . 'bundles' . DS . $module_slug) === null) { static::$errors->add('installer', 'Module assets for module [' . $module_slug . '] were successfully removed.'); return true; } else { static::$errors->add('installer', 'Failed to remove assets for module [' . $module_slug . '].'); return false; } } else { static::$errors->add('installer', 'Failed to remove module [' . $module_slug . '].'); return false; } } else { static::$errors->add('installer', 'Failed to remove module, invalid module slug'); return false; } }
/** * Starts the activated ibundles as bundles. * * @return array */ public function register() { if (empty($this->registered)) { foreach ($this->activated() as $bundle => $config) { if (!Laravel_File::exists(ibundle_config('path') . $bundle)) { // Remove it and skip registration $this->deactivate($bundle); continue; } if (!Bundle::exists($bundle)) { // register the bundle using the ibundle.json data Bundle::register($bundle, $config); if (isset($config['auto']) and $config['auto'] === true) { // Start the registered bundle Bundle::start($bundle); if (Bundle::started($bundle)) { $this->registered[$bundle] = $config; } } } } } return (array) $this->registered; }
/** * Write a stub phpunit.xml file to the base directory. * * @param string $directory * @return void */ protected function stub($directory) { $path = path('sys') . 'cli/tasks/test/'; $stub = File::get($path . 'stub.xml'); // The PHPUnit bootstrap file contains several items that are swapped // at test time. This allows us to point PHPUnit at a few different // locations depending on what the developer wants to test. foreach (array('bootstrap', 'directory') as $item) { $stub = $this->{"swap_{$item}"}($stub, $path, $directory); } File::put(path('base') . 'phpunit.xml', $stub); }
/** * Copy the contents of a bundle's assets to the public folder. * * @param string $source * @param string $destination * @return void */ protected function move($source, $destination) { File::cpdir($source, $destination); }
protected function minify_style($assets, $attributes, $files_to_compile, $output_file, $compile) { if ($compile) { $output_file_contents = ''; foreach ($files_to_compile as $file) { $asset_content = File::get(path('public') . $file); $output_file_contents .= Compressor::process($asset_content); } File::put($this->config['cache_dir_path'] . $output_file, $output_file_contents); } return HTML::style($this->config['cache_dir'] . $output_file, $attributes); }
/** * Validate the MIME type of a file upload attribute is in a set of MIME types. * * @param string $attribute * @param array $value * @param array $parameters * @return bool */ protected function validate_mimes($attribute, $value, $parameters) { if (!is_array($value) or array_get($value, 'tmp_name', '') == '') { return true; } foreach ($parameters as $extension) { if (File::is($extension, $value['tmp_name'])) { return true; } } return false; }
/** * Saves activated bundle list to filesystem. * * @return boolean */ protected function save() { return (bool) Laravel_File::put(ibundle_config('file'), $this->_data); }
/** * Creates the filename used for caching * @param string $image The original image path * @param array $option The route_option * @return string The Filename */ public static function retrieveValidFilename($image, $option) { $ext = File::extension($image); return md5($option . $image) . '.' . $ext; }
protected function minify_script($assets, $attributes, $files_to_compile, $output_file, $compile) { if ($compile) { $scripts_to_minify = array(); foreach ($files_to_compile as $file) { $scripts_to_minify[] = '--js=' . path('public') . $file; } $scripts_to_minify = implode(' ', $scripts_to_minify); $java = 'java'; // find java binary foreach ($this->config['java_binary_path_overrides'] as $java_bin_path) { if (file_exists($java_bin_path)) { $java = $java_bin_path; } } // generate command line $jar = '-jar ' . __DIR__ . '/drivers/closure-compiler/compiler.jar'; $out_script = '--js_output_file=' . $this->config['cache_dir_path'] . $output_file; // red team, go! exec("{$java} {$jar} {$scripts_to_minify} {$out_script}"); } return HTML::script($this->config['cache_dir'] . $output_file . '?t=' . File::modified($this->config['cache_dir_path'] . $output_file), $attributes); }
/** * Create a new download response instance. * * <code> * // Create a download response to a given file * return Response::download('path/to/file.jpg'); * * // Create a download response with a given file name * return Response::download('path/to/file.jpg', 'your_file.jpg'); * </code> * * @param string $path * @param string $name * @param array $headers * @return Response */ public static function download($path, $name = null, $headers = array()) { if (is_null($name)) { $name = basename($path); } // We'll set some sensible default headers, but merge the array given to // us so that the developer has the chance to override any of these // default headers with header values of their own liking. $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path)), $headers); // Once we create the response, we need to set the content disposition // header on the response based on the file's name. We'll pass this // off to the HttpFoundation and let it create the header text. $response = new static(File::get($path), 200, $headers); $d = $response->disposition($name); return $response->header('Content-Disposition', $d); }
/** * 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(path('sys') . 'cli/tasks/migrate/stub' . EXT); // 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 bundle. $class = Bundle::class_prefix($bundle) . Str::classify($migration); return str_replace('{{class}}', $class, $stub); }