From 237e0ca136524cf1c89d91840036de1a463c5256 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:24:24 +0000 Subject: [PATCH 01/28] Update MIT License year. --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 98b65e4..6cb8287 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 CodeSleeve +Copyright (c) 2016 Code Sleeve LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 1cfd80361bfe00602f06feb343d0b242b8d0ce54 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:24:40 +0000 Subject: [PATCH 02/28] Remove older php version. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index de44e61..84363b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 5.5 - 5.6 + - 7.0 - hhvm before_script: From 235475f0125045e353304930b349ad5edc0220e1 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:26:04 +0000 Subject: [PATCH 03/28] Push min required php version to 5.6. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a3e0076..6e1f1ca 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=5.6", "codesleeve/stapler": "1.2.*", "laravel/framework": "4.*|5.*" }, From 41945840c56777e897bb5751f9634a244ea84459 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:27:55 +0000 Subject: [PATCH 04/28] Add rackspace config to the publishes and merge arrays. --- src/Providers/L5ServiceProvider.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Providers/L5ServiceProvider.php b/src/Providers/L5ServiceProvider.php index d87f47c..bec23e6 100644 --- a/src/Providers/L5ServiceProvider.php +++ b/src/Providers/L5ServiceProvider.php @@ -26,13 +26,15 @@ public function boot() // config $this->publishes([ $packageRoot.'/config/filesystem.php' => config_path('laravel-stapler/filesystem.php'), - $packageRoot.'/config/s3.php' => config_path('laravel-stapler/s3.php'), - $packageRoot.'/config/stapler.php' => config_path('laravel-stapler/stapler.php'), - $packageRoot.'/config/bindings.php' => config_path('laravel-stapler/bindings.php'), + $packageRoot.'/config/s3.php' => config_path('laravel-stapler/s3.php'), + $packageRoot.'/config/rackspace.php' => config_path('laravel-stapler/rackspace.php'), + $packageRoot.'/config/stapler.php' => config_path('laravel-stapler/stapler.php'), + $packageRoot.'/config/bindings.php' => config_path('laravel-stapler/bindings.php'), ]); $this->mergeConfigFrom($packageRoot.'/config/filesystem.php', 'laravel-stapler.filesystem'); $this->mergeConfigFrom($packageRoot.'/config/s3.php', 'laravel-stapler.s3'); + $this->mergeConfigFrom($packageRoot.'/config/rackspace.php', 'laravel-stapler.rackspace'); $this->mergeConfigFrom($packageRoot.'/config/stapler.php', 'laravel-stapler.stapler'); $this->mergeConfigFrom($packageRoot.'/config/bindings.php', 'laravel-stapler.bindings'); From e50f758487b42763a4cf05bc43c6de7aa229bafc Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:28:21 +0000 Subject: [PATCH 05/28] Remove deprecated service provider. --- src/LaravelStaplerServiceProvider.php | 121 -------------------------- 1 file changed, 121 deletions(-) delete mode 100644 src/LaravelStaplerServiceProvider.php diff --git a/src/LaravelStaplerServiceProvider.php b/src/LaravelStaplerServiceProvider.php deleted file mode 100644 index 6508a73..0000000 --- a/src/LaravelStaplerServiceProvider.php +++ /dev/null @@ -1,121 +0,0 @@ -package('codesleeve/laravel-stapler', null, __DIR__); - $this->bootstrapStapler(); - } - - /** - * Register the service provider. - */ - public function register() - { - // commands - $this->registerStaplerFastenCommand(); - $this->registerStaplerRefreshCommand(); - - // services - $this->registerImageRefreshService(); - - // msc - $this->registerMigrationFolderPath(); - - $this->commands('stapler.fasten'); - $this->commands('stapler.refresh'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - /** - * Bootstrap up the stapler package: - * - Boot stapler. - * - Set the config driver. - * - Set public_path config using laravel's public_path() method (if necessary). - * - Set base_path config using laravel's base_path() method (if necessary). - */ - protected function bootstrapStapler() - { - Stapler::boot(); - - $config = new IlluminateConfig(Config::getFacadeRoot(), 'laravel-stapler'); - Stapler::setConfigInstance($config); - - if (!$config->get('stapler.public_path')) { - $config->set('stapler.public_path', realpath(public_path())); - } - - if (!$config->get('stapler.base_path')) { - $config->set('stapler.base_path', realpath(base_path())); - } - } - - /** - * Register the stapler fasten command with the container. - */ - protected function registerStaplerFastenCommand() - { - $this->app->bind('stapler.fasten', function ($app) { - $migrationsFolderPath = app_path().'/database/migrations'; - - return new Commands\FastenCommand($app['view'], $app['files'], $migrationsFolderPath); - }); - } - - /** - * Register the stapler refresh command with the container. - */ - protected function registerStaplerRefreshCommand() - { - $this->app->bind('stapler.refresh', function ($app) { - $refreshService = $app['ImageRefreshService']; - - return new Commands\RefreshCommand($refreshService); - }); - } - - /** - * Register the image refresh service with the container. - */ - protected function registerImageRefreshService() - { - $this->app->singleton('ImageRefreshService', function ($app, $params) { - return new ImageRefreshService($app); - }); - } - - /** - * Register the the migrations folder path with the container. - */ - protected function registerMigrationFolderPath() - { - $this->app->bind('migration_folder_path', app_path().'/database/migrations'); - } -} From ce2308b7213956d8e15891a414d13fa8079cfaa2 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:29:02 +0000 Subject: [PATCH 06/28] Add rackspace config file. --- src/config/rackspace.php | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/config/rackspace.php diff --git a/src/config/rackspace.php b/src/config/rackspace.php new file mode 100644 index 0000000..8356230 --- /dev/null +++ b/src/config/rackspace.php @@ -0,0 +1,75 @@ + '', + + /* + |-------------------------------------------------------------------------- + | Rackspace API Key + |-------------------------------------------------------------------------- + | + | The API key from your Rackspace account. You may find this under the + | 'Account Settings' page inside the rackspace cloud control panel. + | + */ + 'apiKey' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace Region + |-------------------------------------------------------------------------- + | + | This should match the region of the conainer being used to store your + | your uploaded files. + | + */ + + 'region' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace Container + |-------------------------------------------------------------------------- + | + | This is the name of an existing container that you wish to store your + | uploaded files in. If you don't already have a container, you can + | easily create one by using the Rackspace cloud control panel. + | + */ + + 'container' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace SSL Links + |-------------------------------------------------------------------------- + | + | When generating links to your uploaded files, you may wish to create + | secure (https) links to your uploaded file assets. + | + */ + + 'use_ssl' => true, + + /* + |-------------------------------------------------------------------------- + | Rackspace Path + |-------------------------------------------------------------------------- + | + | This is the key (in your container) under which a file will be stored. + | The URL to a file will be generated using the your container's name + | and this value (once it's been ran through the interpolator). + | + */ + + 'path' => ':attachment/:id/:style/:filename' +]; From e4897e0148f125a499dccfe4a1d04dc50bf04de8 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 17:46:01 +0000 Subject: [PATCH 07/28] Use the development version of stapler (for now). --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e1f1ca..9079d62 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=5.6", - "codesleeve/stapler": "1.2.*", + "codesleeve/stapler": "dev-develop", "laravel/framework": "4.*|5.*" }, "autoload": { From 985dd504d4c688ad975df3b55b4993b19969dea9 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:16:56 +0000 Subject: [PATCH 08/28] Require php7 as a minimum version. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9079d62..263847b 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.0", "codesleeve/stapler": "dev-develop", "laravel/framework": "4.*|5.*" }, From e414c76807e54674ffbdf1d7d5a12e8af54d6ba8 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:17:59 +0000 Subject: [PATCH 09/28] Use namespace grouping and scalar typehints. --- src/Commands/RefreshCommand.php | 5 ++--- src/IlluminateConfig.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Commands/RefreshCommand.php b/src/Commands/RefreshCommand.php index 39ac397..a520678 100644 --- a/src/Commands/RefreshCommand.php +++ b/src/Commands/RefreshCommand.php @@ -3,8 +3,7 @@ namespace Codesleeve\LaravelStapler\Commands; use Illuminate\Console\Command; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\{InputOption, InputArgument}; use Codesleeve\LaravelStapler\Services\ImageRefreshService; class RefreshCommand extends Command @@ -21,7 +20,7 @@ class RefreshCommand extends Command * * @var string */ - protected $description = 'Regenerate images for a given model (and optional attachment and styles)'; + protected $description = 'Regenerate images for a given Eloquent model (and optional attachment and styles)'; /** * The image refresh service that will be used to diff --git a/src/IlluminateConfig.php b/src/IlluminateConfig.php index 42bcc15..3838143 100644 --- a/src/IlluminateConfig.php +++ b/src/IlluminateConfig.php @@ -16,7 +16,7 @@ class IlluminateConfig implements Config /** * The name of the package this driver is being used with. - * + * * @var string */ protected $packageName; @@ -45,11 +45,11 @@ public function __construct(Repository $config, $packageName = null, $separator /** * Retrieve a configuration value. * - * @param $name + * @param string $name * * @return mixed */ - public function get($name) + public function get(string $name) { $item = $this->getItemPath($name); @@ -59,12 +59,12 @@ public function get($name) /** * Set a configuration value. * - * @param $name - * @param $value + * @param string $name + * @param mixed $value * * @return mixed */ - public function set($name, $value) + public function set(string $name, $value) { $item = $this->getItemPath($name); @@ -75,12 +75,12 @@ public function set($name, $value) * Return the path to an item so that it can be loaded via config. * We need to append the package name to the item separated * with '::' for L4 and '.' for L5. - * + * * @param string $item * * @return string */ - protected function getItemPath($item) + protected function getItemPath(string $item) : string { return $this->packageName.$this->separator.$item; } From c1b5d238341f4750a71b2563b27f805348725730 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:19:21 +0000 Subject: [PATCH 10/28] Chunk results, use scalar typehints and namespace groups. --- src/Services/ImageRefreshService.php | 70 +++++++++++++++------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/Services/ImageRefreshService.php b/src/Services/ImageRefreshService.php index 491444f..558daba 100644 --- a/src/Services/ImageRefreshService.php +++ b/src/Services/ImageRefreshService.php @@ -2,12 +2,11 @@ namespace Codesleeve\LaravelStapler\Services; +use Codesleeve\Stapler\ORM\StaplerableInterface; use Codesleeve\LaravelStapler\Exceptions\InvalidClassException; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Application; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Output\NullOutput; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\{Helper\ProgressBar, Output\NullOutput, OutputInterface}; class ImageRefreshService { @@ -26,11 +25,13 @@ class ImageRefreshService protected $output; /** - * @param Application $app + * @param Application $app + * @param OutputInterface $output */ - public function __construct(Application $app) + public function __construct(Application $app, OutputInterface $output = null) { $this->app = $app; + $this->output = $output ?: new NullOutput(); } /** @@ -46,45 +47,47 @@ public function setOutput(OutputInterface $output) * * @throws InvalidClassException * - * @param string $class + * @param string $className * @param string $attachments */ - public function refresh($class, $attachments) + public function refresh(string $className, string $attachments) { - if (!method_exists($class, 'hasAttachedFile')) { - throw new InvalidClassException("Invalid class: the $class class is not currently using Stapler.", 1); - } + $model = $this->app->make($className); - $models = $this->app->make($class)->all(); + if (!$model instanceof StaplerableInterface) { + throw new InvalidClassException("Invalid class: the $className class is not currently using Stapler.", 1); + } if ($attachments) { $attachments = explode(',', str_replace(', ', ',', $attachments)); - $this->processSomeAttachments($models, $attachments); + $this->processSomeAttachments($model, $attachments); } else { - $this->processAllAttachments($models); + $this->processAllAttachments($model); } } /** * Process a only a specified subset of stapler attachments. * - * @param Collection $models - * @param array $attachments + * @param StaplerableInterface $model + * @param array $attachments */ - protected function processSomeAttachments(Collection $models, array $attachments) + protected function processSomeAttachments(StaplerableInterface $model, array $attachments) { - $progress = $this->getProgressBar($models); + $progress = $this->getProgressBar($model->count()); $progress->start(); - foreach ($models as $model) { + $model->chunk(100, function($models) use ($progress, $attachments) { $progress->advance(); - foreach ($model->getAttachedFiles() as $attachedFile) { - if (in_array($attachedFile->name, $attachments)) { - $attachedFile->reprocess(); + foreach ($models as $model) { + foreach ($model->getAttachments() as $attachment) { + if (in_array($attachment->name, $attachments)) { + $attachment->reprocess(); + } } } - } + }); $progress->finish(); } @@ -92,20 +95,22 @@ protected function processSomeAttachments(Collection $models, array $attachments /** * Process all stapler attachments defined on a class. * - * @param Collection $models + * @param StaplerableInterface $model */ - protected function processAllAttachments(Collection $models) + protected function processAllAttachments(StaplerableInterface $model) { - $progress = $this->getProgressBar($models); + $progress = $this->getProgressBar($model->count()); $progress->start(); - foreach ($models as $model) { + $model->chunk(100, function($models) use ($progress) { $progress->advance(); - foreach ($model->getAttachedFiles() as $attachedFile) { - $attachedFile->reprocess(); + foreach ($models as $model) { + foreach ($model->getAttachements() as $attachment) { + $attachment->reprocess(); + } } - } + }); $progress->finish(); } @@ -113,14 +118,13 @@ protected function processAllAttachments(Collection $models) /** * Get an instance of the ProgressBar helper. * - * @param Collection $models + * @param int $count * * @return ProgressBar */ - protected function getProgressBar(Collection $models) + protected function getProgressBar(int $count) { - $output = $this->output ?: new NullOutput(); - $progress = new ProgressBar($output, $models->count()); + $progress = new ProgressBar($this->output, $count); return $progress; } From 6d8560fd67964b4fdbe8351bd71e7488b8545b3a Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Wed, 18 May 2016 04:48:25 +0000 Subject: [PATCH 11/28] Clean up S3 config. --- src/config/s3.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/config/s3.php b/src/config/s3.php index a565027..8898683 100644 --- a/src/config/s3.php +++ b/src/config/s3.php @@ -8,15 +8,18 @@ |-------------------------------------------------------------------------- | | This is array holds the default configuration options used when creating - | an instance of Aws\S3\S3Client. These options will be passed directly to + | an instance of Aws\S3\S3Client. These options will be passed directly to | the s3ClientFactory when creating an S3 client instance. | */ 's3_client_config' => [ - 'key' => '', - 'secret' => '', + 'credentials' => [ + 'key' => '', + 'secret' => '' + ], 'region' => '', 'scheme' => 'http', + 'version' => 'latest' ], /* @@ -26,7 +29,7 @@ | | An array of options used by the Aws\S3\S3Client::putObject() method when | storing a file on S3. - | AWS Documentation for Aws\S3\S3Client::putObject() at + | AWS Documentation for Aws\S3\S3Client::putObject() at | http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_putObject | */ @@ -50,4 +53,4 @@ 'path' => ':attachment/:id/:style/:filename', -]; +]; \ No newline at end of file From 6af9b83f2a8c565be678c1fa14cba78f1448c978 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:11:24 +0000 Subject: [PATCH 12/28] Update the name of the stapler package config interface. --- src/IlluminateConfig.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IlluminateConfig.php b/src/IlluminateConfig.php index 3838143..95f747f 100644 --- a/src/IlluminateConfig.php +++ b/src/IlluminateConfig.php @@ -2,10 +2,10 @@ namespace Codesleeve\LaravelStapler; -use Codesleeve\Stapler\Interfaces\Config; +use Codesleeve\Stapler\Interfaces\ConfigInterface; use Illuminate\Contracts\Config\Repository; -class IlluminateConfig implements Config +class IlluminateConfig implements ConfigInterface { /** * An instance of Laravel's config class. From fa8d0aaa0ffc9875936a3448d59e9d60dc1b2b71 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:13:06 +0000 Subject: [PATCH 13/28] Remove laravel 4.* compatability. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 263847b..eb5043d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=7.0", "codesleeve/stapler": "dev-develop", - "laravel/framework": "4.*|5.*" + "laravel/framework": "5.*" }, "autoload": { "classmap": [ From 399550866f246a3cc9e01a29819af1a8bf530677 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:14:12 +0000 Subject: [PATCH 14/28] Remove this provider since we're no longer supporting L4 in 2.*. --- src/Providers/L4ServiceProvider.php | 80 ----------------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/Providers/L4ServiceProvider.php diff --git a/src/Providers/L4ServiceProvider.php b/src/Providers/L4ServiceProvider.php deleted file mode 100644 index 558e6da..0000000 --- a/src/Providers/L4ServiceProvider.php +++ /dev/null @@ -1,80 +0,0 @@ -package('codesleeve/laravel-stapler', null, dirname(__DIR__)); - $this->bootstrapStapler(); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - /** - * Bootstrap up the stapler package: - * - Boot stapler. - * - Set the config driver. - * - Set public_path config using laravel's public_path() method (if necessary). - * - Set base_path config using laravel's base_path() method (if necessary). - */ - protected function bootstrapStapler() - { - Stapler::boot(); - - $config = new IlluminateConfig(Config::getFacadeRoot(), 'laravel-stapler'); - Stapler::setConfigInstance($config); - - if (!$config->get('stapler.public_path')) { - $config->set('stapler.public_path', realpath(public_path())); - } - - if (!$config->get('stapler.base_path')) { - $config->set('stapler.base_path', realpath(base_path())); - } - } - - /** - * Register the stapler fasten command with the container. - */ - protected function registerStaplerFastenCommand() - { - $this->app->bind('stapler.fasten', function ($app) { - $migrationsFolderPath = app_path().'/database/migrations'; - - return new FastenCommand($app['view'], $app['files'], $migrationsFolderPath); - }); - } - - /** - * Register the the migrations folder path with the container. - */ - protected function registerMigrationFolderPath() - { - $this->app->bind('migration_folder_path', app_path().'/database/migrations'); - } -} From cc376d1b76856189088aa9940408a338dcdc8dbf Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:24:24 +0000 Subject: [PATCH 15/28] Update MIT License year. --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 98b65e4..6cb8287 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 CodeSleeve +Copyright (c) 2016 Code Sleeve LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 746afea433ac3be06e346ce31bd783446bd3411e Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:24:40 +0000 Subject: [PATCH 16/28] Remove older php version. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index de44e61..84363b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 5.5 - 5.6 + - 7.0 - hhvm before_script: From 65a8b399098e8d4fd4a404fce7cdefa4bce29ded Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:26:04 +0000 Subject: [PATCH 17/28] Push min required php version to 5.6. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a3e0076..6e1f1ca 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=5.6", "codesleeve/stapler": "1.2.*", "laravel/framework": "4.*|5.*" }, From 9a96018ebd977bb3197d752a0d39e476a08dd529 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:27:55 +0000 Subject: [PATCH 18/28] Add rackspace config to the publishes and merge arrays. --- src/Providers/L5ServiceProvider.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Providers/L5ServiceProvider.php b/src/Providers/L5ServiceProvider.php index d87f47c..bec23e6 100644 --- a/src/Providers/L5ServiceProvider.php +++ b/src/Providers/L5ServiceProvider.php @@ -26,13 +26,15 @@ public function boot() // config $this->publishes([ $packageRoot.'/config/filesystem.php' => config_path('laravel-stapler/filesystem.php'), - $packageRoot.'/config/s3.php' => config_path('laravel-stapler/s3.php'), - $packageRoot.'/config/stapler.php' => config_path('laravel-stapler/stapler.php'), - $packageRoot.'/config/bindings.php' => config_path('laravel-stapler/bindings.php'), + $packageRoot.'/config/s3.php' => config_path('laravel-stapler/s3.php'), + $packageRoot.'/config/rackspace.php' => config_path('laravel-stapler/rackspace.php'), + $packageRoot.'/config/stapler.php' => config_path('laravel-stapler/stapler.php'), + $packageRoot.'/config/bindings.php' => config_path('laravel-stapler/bindings.php'), ]); $this->mergeConfigFrom($packageRoot.'/config/filesystem.php', 'laravel-stapler.filesystem'); $this->mergeConfigFrom($packageRoot.'/config/s3.php', 'laravel-stapler.s3'); + $this->mergeConfigFrom($packageRoot.'/config/rackspace.php', 'laravel-stapler.rackspace'); $this->mergeConfigFrom($packageRoot.'/config/stapler.php', 'laravel-stapler.stapler'); $this->mergeConfigFrom($packageRoot.'/config/bindings.php', 'laravel-stapler.bindings'); From d4a1fa93f1c6688535afc8188a08ff5e9cde17fb Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:28:21 +0000 Subject: [PATCH 19/28] Remove deprecated service provider. --- src/LaravelStaplerServiceProvider.php | 121 -------------------------- 1 file changed, 121 deletions(-) delete mode 100644 src/LaravelStaplerServiceProvider.php diff --git a/src/LaravelStaplerServiceProvider.php b/src/LaravelStaplerServiceProvider.php deleted file mode 100644 index 6508a73..0000000 --- a/src/LaravelStaplerServiceProvider.php +++ /dev/null @@ -1,121 +0,0 @@ -package('codesleeve/laravel-stapler', null, __DIR__); - $this->bootstrapStapler(); - } - - /** - * Register the service provider. - */ - public function register() - { - // commands - $this->registerStaplerFastenCommand(); - $this->registerStaplerRefreshCommand(); - - // services - $this->registerImageRefreshService(); - - // msc - $this->registerMigrationFolderPath(); - - $this->commands('stapler.fasten'); - $this->commands('stapler.refresh'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - /** - * Bootstrap up the stapler package: - * - Boot stapler. - * - Set the config driver. - * - Set public_path config using laravel's public_path() method (if necessary). - * - Set base_path config using laravel's base_path() method (if necessary). - */ - protected function bootstrapStapler() - { - Stapler::boot(); - - $config = new IlluminateConfig(Config::getFacadeRoot(), 'laravel-stapler'); - Stapler::setConfigInstance($config); - - if (!$config->get('stapler.public_path')) { - $config->set('stapler.public_path', realpath(public_path())); - } - - if (!$config->get('stapler.base_path')) { - $config->set('stapler.base_path', realpath(base_path())); - } - } - - /** - * Register the stapler fasten command with the container. - */ - protected function registerStaplerFastenCommand() - { - $this->app->bind('stapler.fasten', function ($app) { - $migrationsFolderPath = app_path().'/database/migrations'; - - return new Commands\FastenCommand($app['view'], $app['files'], $migrationsFolderPath); - }); - } - - /** - * Register the stapler refresh command with the container. - */ - protected function registerStaplerRefreshCommand() - { - $this->app->bind('stapler.refresh', function ($app) { - $refreshService = $app['ImageRefreshService']; - - return new Commands\RefreshCommand($refreshService); - }); - } - - /** - * Register the image refresh service with the container. - */ - protected function registerImageRefreshService() - { - $this->app->singleton('ImageRefreshService', function ($app, $params) { - return new ImageRefreshService($app); - }); - } - - /** - * Register the the migrations folder path with the container. - */ - protected function registerMigrationFolderPath() - { - $this->app->bind('migration_folder_path', app_path().'/database/migrations'); - } -} From 48b59a8a69a16a030f54b82789061d4224b6384d Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 16:29:02 +0000 Subject: [PATCH 20/28] Add rackspace config file. --- src/config/rackspace.php | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/config/rackspace.php diff --git a/src/config/rackspace.php b/src/config/rackspace.php new file mode 100644 index 0000000..8356230 --- /dev/null +++ b/src/config/rackspace.php @@ -0,0 +1,75 @@ + '', + + /* + |-------------------------------------------------------------------------- + | Rackspace API Key + |-------------------------------------------------------------------------- + | + | The API key from your Rackspace account. You may find this under the + | 'Account Settings' page inside the rackspace cloud control panel. + | + */ + 'apiKey' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace Region + |-------------------------------------------------------------------------- + | + | This should match the region of the conainer being used to store your + | your uploaded files. + | + */ + + 'region' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace Container + |-------------------------------------------------------------------------- + | + | This is the name of an existing container that you wish to store your + | uploaded files in. If you don't already have a container, you can + | easily create one by using the Rackspace cloud control panel. + | + */ + + 'container' => '', + + /* + |-------------------------------------------------------------------------- + | Rackspace SSL Links + |-------------------------------------------------------------------------- + | + | When generating links to your uploaded files, you may wish to create + | secure (https) links to your uploaded file assets. + | + */ + + 'use_ssl' => true, + + /* + |-------------------------------------------------------------------------- + | Rackspace Path + |-------------------------------------------------------------------------- + | + | This is the key (in your container) under which a file will be stored. + | The URL to a file will be generated using the your container's name + | and this value (once it's been ran through the interpolator). + | + */ + + 'path' => ':attachment/:id/:style/:filename' +]; From d15ae62ce04750c0b7c0dd55a9135b681caecf6f Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Fri, 13 May 2016 17:46:01 +0000 Subject: [PATCH 21/28] Use the development version of stapler (for now). --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e1f1ca..9079d62 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=5.6", - "codesleeve/stapler": "1.2.*", + "codesleeve/stapler": "dev-develop", "laravel/framework": "4.*|5.*" }, "autoload": { From c785024a5d3d8e9dbe78d3b516eff317f9419514 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:16:56 +0000 Subject: [PATCH 22/28] Require php7 as a minimum version. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9079d62..263847b 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.0", "codesleeve/stapler": "dev-develop", "laravel/framework": "4.*|5.*" }, From 1fee20745f284bde4d6e84c7de7e11095307844a Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:17:59 +0000 Subject: [PATCH 23/28] Use namespace grouping and scalar typehints. --- src/Commands/RefreshCommand.php | 5 ++--- src/IlluminateConfig.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Commands/RefreshCommand.php b/src/Commands/RefreshCommand.php index 39ac397..a520678 100644 --- a/src/Commands/RefreshCommand.php +++ b/src/Commands/RefreshCommand.php @@ -3,8 +3,7 @@ namespace Codesleeve\LaravelStapler\Commands; use Illuminate\Console\Command; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\{InputOption, InputArgument}; use Codesleeve\LaravelStapler\Services\ImageRefreshService; class RefreshCommand extends Command @@ -21,7 +20,7 @@ class RefreshCommand extends Command * * @var string */ - protected $description = 'Regenerate images for a given model (and optional attachment and styles)'; + protected $description = 'Regenerate images for a given Eloquent model (and optional attachment and styles)'; /** * The image refresh service that will be used to diff --git a/src/IlluminateConfig.php b/src/IlluminateConfig.php index 42bcc15..3838143 100644 --- a/src/IlluminateConfig.php +++ b/src/IlluminateConfig.php @@ -16,7 +16,7 @@ class IlluminateConfig implements Config /** * The name of the package this driver is being used with. - * + * * @var string */ protected $packageName; @@ -45,11 +45,11 @@ public function __construct(Repository $config, $packageName = null, $separator /** * Retrieve a configuration value. * - * @param $name + * @param string $name * * @return mixed */ - public function get($name) + public function get(string $name) { $item = $this->getItemPath($name); @@ -59,12 +59,12 @@ public function get($name) /** * Set a configuration value. * - * @param $name - * @param $value + * @param string $name + * @param mixed $value * * @return mixed */ - public function set($name, $value) + public function set(string $name, $value) { $item = $this->getItemPath($name); @@ -75,12 +75,12 @@ public function set($name, $value) * Return the path to an item so that it can be loaded via config. * We need to append the package name to the item separated * with '::' for L4 and '.' for L5. - * + * * @param string $item * * @return string */ - protected function getItemPath($item) + protected function getItemPath(string $item) : string { return $this->packageName.$this->separator.$item; } From 452ac5f19e6b03a52af42aff36f1fc250bb311f4 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Sat, 14 May 2016 07:19:21 +0000 Subject: [PATCH 24/28] Chunk results, use scalar typehints and namespace groups. --- src/Services/ImageRefreshService.php | 70 +++++++++++++++------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/Services/ImageRefreshService.php b/src/Services/ImageRefreshService.php index 491444f..558daba 100644 --- a/src/Services/ImageRefreshService.php +++ b/src/Services/ImageRefreshService.php @@ -2,12 +2,11 @@ namespace Codesleeve\LaravelStapler\Services; +use Codesleeve\Stapler\ORM\StaplerableInterface; use Codesleeve\LaravelStapler\Exceptions\InvalidClassException; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Application; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Output\NullOutput; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\{Helper\ProgressBar, Output\NullOutput, OutputInterface}; class ImageRefreshService { @@ -26,11 +25,13 @@ class ImageRefreshService protected $output; /** - * @param Application $app + * @param Application $app + * @param OutputInterface $output */ - public function __construct(Application $app) + public function __construct(Application $app, OutputInterface $output = null) { $this->app = $app; + $this->output = $output ?: new NullOutput(); } /** @@ -46,45 +47,47 @@ public function setOutput(OutputInterface $output) * * @throws InvalidClassException * - * @param string $class + * @param string $className * @param string $attachments */ - public function refresh($class, $attachments) + public function refresh(string $className, string $attachments) { - if (!method_exists($class, 'hasAttachedFile')) { - throw new InvalidClassException("Invalid class: the $class class is not currently using Stapler.", 1); - } + $model = $this->app->make($className); - $models = $this->app->make($class)->all(); + if (!$model instanceof StaplerableInterface) { + throw new InvalidClassException("Invalid class: the $className class is not currently using Stapler.", 1); + } if ($attachments) { $attachments = explode(',', str_replace(', ', ',', $attachments)); - $this->processSomeAttachments($models, $attachments); + $this->processSomeAttachments($model, $attachments); } else { - $this->processAllAttachments($models); + $this->processAllAttachments($model); } } /** * Process a only a specified subset of stapler attachments. * - * @param Collection $models - * @param array $attachments + * @param StaplerableInterface $model + * @param array $attachments */ - protected function processSomeAttachments(Collection $models, array $attachments) + protected function processSomeAttachments(StaplerableInterface $model, array $attachments) { - $progress = $this->getProgressBar($models); + $progress = $this->getProgressBar($model->count()); $progress->start(); - foreach ($models as $model) { + $model->chunk(100, function($models) use ($progress, $attachments) { $progress->advance(); - foreach ($model->getAttachedFiles() as $attachedFile) { - if (in_array($attachedFile->name, $attachments)) { - $attachedFile->reprocess(); + foreach ($models as $model) { + foreach ($model->getAttachments() as $attachment) { + if (in_array($attachment->name, $attachments)) { + $attachment->reprocess(); + } } } - } + }); $progress->finish(); } @@ -92,20 +95,22 @@ protected function processSomeAttachments(Collection $models, array $attachments /** * Process all stapler attachments defined on a class. * - * @param Collection $models + * @param StaplerableInterface $model */ - protected function processAllAttachments(Collection $models) + protected function processAllAttachments(StaplerableInterface $model) { - $progress = $this->getProgressBar($models); + $progress = $this->getProgressBar($model->count()); $progress->start(); - foreach ($models as $model) { + $model->chunk(100, function($models) use ($progress) { $progress->advance(); - foreach ($model->getAttachedFiles() as $attachedFile) { - $attachedFile->reprocess(); + foreach ($models as $model) { + foreach ($model->getAttachements() as $attachment) { + $attachment->reprocess(); + } } - } + }); $progress->finish(); } @@ -113,14 +118,13 @@ protected function processAllAttachments(Collection $models) /** * Get an instance of the ProgressBar helper. * - * @param Collection $models + * @param int $count * * @return ProgressBar */ - protected function getProgressBar(Collection $models) + protected function getProgressBar(int $count) { - $output = $this->output ?: new NullOutput(); - $progress = new ProgressBar($output, $models->count()); + $progress = new ProgressBar($this->output, $count); return $progress; } From f1e6b4565e4d73414e175b78d4bef249333b22e7 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Wed, 18 May 2016 04:48:25 +0000 Subject: [PATCH 25/28] Clean up S3 config. --- src/config/s3.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/config/s3.php b/src/config/s3.php index a565027..8898683 100644 --- a/src/config/s3.php +++ b/src/config/s3.php @@ -8,15 +8,18 @@ |-------------------------------------------------------------------------- | | This is array holds the default configuration options used when creating - | an instance of Aws\S3\S3Client. These options will be passed directly to + | an instance of Aws\S3\S3Client. These options will be passed directly to | the s3ClientFactory when creating an S3 client instance. | */ 's3_client_config' => [ - 'key' => '', - 'secret' => '', + 'credentials' => [ + 'key' => '', + 'secret' => '' + ], 'region' => '', 'scheme' => 'http', + 'version' => 'latest' ], /* @@ -26,7 +29,7 @@ | | An array of options used by the Aws\S3\S3Client::putObject() method when | storing a file on S3. - | AWS Documentation for Aws\S3\S3Client::putObject() at + | AWS Documentation for Aws\S3\S3Client::putObject() at | http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_putObject | */ @@ -50,4 +53,4 @@ 'path' => ':attachment/:id/:style/:filename', -]; +]; \ No newline at end of file From 17896c82ac31b903fdc21766e4fd40af96e6014f Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:11:24 +0000 Subject: [PATCH 26/28] Update the name of the stapler package config interface. --- src/IlluminateConfig.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IlluminateConfig.php b/src/IlluminateConfig.php index 3838143..95f747f 100644 --- a/src/IlluminateConfig.php +++ b/src/IlluminateConfig.php @@ -2,10 +2,10 @@ namespace Codesleeve\LaravelStapler; -use Codesleeve\Stapler\Interfaces\Config; +use Codesleeve\Stapler\Interfaces\ConfigInterface; use Illuminate\Contracts\Config\Repository; -class IlluminateConfig implements Config +class IlluminateConfig implements ConfigInterface { /** * An instance of Laravel's config class. From 9bb85b0aaa4e0f17302b68993529d030e1bdc05f Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:13:06 +0000 Subject: [PATCH 27/28] Remove laravel 4.* compatability. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 263847b..eb5043d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=7.0", "codesleeve/stapler": "dev-develop", - "laravel/framework": "4.*|5.*" + "laravel/framework": "5.*" }, "autoload": { "classmap": [ From 2170dc9b065d3e9ee3a58d12ca26a3c99d332ac3 Mon Sep 17 00:00:00 2001 From: Travis Bennett Date: Mon, 23 Jan 2017 00:14:12 +0000 Subject: [PATCH 28/28] Remove this provider since we're no longer supporting L4 in 2.*. --- src/Providers/L4ServiceProvider.php | 80 ----------------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/Providers/L4ServiceProvider.php diff --git a/src/Providers/L4ServiceProvider.php b/src/Providers/L4ServiceProvider.php deleted file mode 100644 index 558e6da..0000000 --- a/src/Providers/L4ServiceProvider.php +++ /dev/null @@ -1,80 +0,0 @@ -package('codesleeve/laravel-stapler', null, dirname(__DIR__)); - $this->bootstrapStapler(); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - /** - * Bootstrap up the stapler package: - * - Boot stapler. - * - Set the config driver. - * - Set public_path config using laravel's public_path() method (if necessary). - * - Set base_path config using laravel's base_path() method (if necessary). - */ - protected function bootstrapStapler() - { - Stapler::boot(); - - $config = new IlluminateConfig(Config::getFacadeRoot(), 'laravel-stapler'); - Stapler::setConfigInstance($config); - - if (!$config->get('stapler.public_path')) { - $config->set('stapler.public_path', realpath(public_path())); - } - - if (!$config->get('stapler.base_path')) { - $config->set('stapler.base_path', realpath(base_path())); - } - } - - /** - * Register the stapler fasten command with the container. - */ - protected function registerStaplerFastenCommand() - { - $this->app->bind('stapler.fasten', function ($app) { - $migrationsFolderPath = app_path().'/database/migrations'; - - return new FastenCommand($app['view'], $app['files'], $migrationsFolderPath); - }); - } - - /** - * Register the the migrations folder path with the container. - */ - protected function registerMigrationFolderPath() - { - $this->app->bind('migration_folder_path', app_path().'/database/migrations'); - } -}