mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 16:50:07 +02:00
removed illuminate depedencies
This commit is contained in:
@@ -17,16 +17,12 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.*",
|
"phpunit/phpunit": "3.*",
|
||||||
"mockery/mockery": "0.9.*",
|
"mockery/mockery": "0.9.*"
|
||||||
"illuminate/support": "4.*",
|
|
||||||
"illuminate/config": "4.*"
|
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-gd": "to use GD library based image processing.",
|
"ext-gd": "to use GD library based image processing.",
|
||||||
"ext-imagick": "to use Imagick based image processing.",
|
"ext-imagick": "to use Imagick based image processing.",
|
||||||
"intervention/imagecache": "Caching extension for the Intervention Image library",
|
"intervention/imagecache": "Caching extension for the Intervention Image library"
|
||||||
"illuminate/support": "Used for Laravel integration",
|
|
||||||
"illuminate/config": "Used for Laravel integration"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
@@ -3,60 +3,38 @@
|
|||||||
namespace Intervention\Image;
|
namespace Intervention\Image;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Config\Repository as Config;
|
|
||||||
use Illuminate\Config\FileLoader;
|
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
class ImageManager
|
class ImageManager
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Instance of Illuminate Config respository
|
* Config
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Config\Repository
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $config;
|
public $config = array(
|
||||||
|
'driver' => 'gd'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of Image Manager
|
* Creates new instance of Image Manager
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Config\Repository $config
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public function __construct(\Illuminate\Config\Repository $config = null)
|
public function __construct(array $config = array())
|
||||||
{
|
{
|
||||||
// create configurator
|
$this->configure($config);
|
||||||
if (is_a($config, 'Illuminate\\Config\\Repository')) {
|
|
||||||
|
|
||||||
$this->config = $config;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$config_path = __DIR__.'/../../config';
|
|
||||||
$env = 'production';
|
|
||||||
|
|
||||||
$file = new Filesystem;
|
|
||||||
$loader = new FileLoader($file, $config_path);
|
|
||||||
$this->config = new Config($loader, $env);
|
|
||||||
$this->config->package('intervention/image', $config_path, 'image');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a driver instance according to config settings
|
* Overrides configuration settings
|
||||||
*
|
*
|
||||||
* @return Intervention\Image\AbstractDriver
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
private function createDriver()
|
public function configure(array $config = array())
|
||||||
{
|
{
|
||||||
$drivername = ucfirst($this->config->get('image::driver'));
|
$this->config = array_replace($this->config, $config);
|
||||||
$driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
|
|
||||||
|
|
||||||
if (class_exists($driverclass)) {
|
return $this;
|
||||||
return new $driverclass;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Intervention\Image\Exception\NotSupportedException(
|
|
||||||
"Driver ({$drivername}) could not be instantiated."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,4 +91,23 @@ class ImageManager
|
|||||||
"Please install package intervention/imagecache before running this function."
|
"Please install package intervention/imagecache before running this function."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a driver instance according to config settings
|
||||||
|
*
|
||||||
|
* @return Intervention\Image\AbstractDriver
|
||||||
|
*/
|
||||||
|
private function createDriver()
|
||||||
|
{
|
||||||
|
$drivername = ucfirst($this->config['driver']);
|
||||||
|
$driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
|
||||||
|
|
||||||
|
if (class_exists($driverclass)) {
|
||||||
|
return new $driverclass;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Intervention\Image\Exception\NotSupportedException(
|
||||||
|
"Driver ({$drivername}) could not be instantiated."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Intervention\Image;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
|
|
||||||
class ImageManagerBasic
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Config
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default config
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $defaultConfig = array(
|
|
||||||
'driver' => 'gd',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new instance of Image Manager
|
|
||||||
*
|
|
||||||
* @param array $config
|
|
||||||
*/
|
|
||||||
public function __construct(array $config = array())
|
|
||||||
{
|
|
||||||
$this->config = $this->defaultConfig + $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a driver instance according to config settings
|
|
||||||
*
|
|
||||||
* @return Intervention\Image\AbstractDriver
|
|
||||||
*/
|
|
||||||
private function createDriver()
|
|
||||||
{
|
|
||||||
$drivername = ucfirst($this->config['driver']);
|
|
||||||
$driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
|
|
||||||
|
|
||||||
if (class_exists($driverclass)) {
|
|
||||||
return new $driverclass;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Intervention\Image\Exception\NotSupportedException(
|
|
||||||
"Driver ({$drivername}) could not be instantiated."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initiates an Image instance from different input types
|
|
||||||
*
|
|
||||||
* @param mixed $data
|
|
||||||
*
|
|
||||||
* @return Intervention\Image\Image
|
|
||||||
*/
|
|
||||||
public function make($data)
|
|
||||||
{
|
|
||||||
return $this->createDriver()->init($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an empty image canvas
|
|
||||||
*
|
|
||||||
* @param integer $width
|
|
||||||
* @param integer $height
|
|
||||||
* @param mixed $background
|
|
||||||
*
|
|
||||||
* @return Intervention\Image\Image
|
|
||||||
*/
|
|
||||||
public function canvas($width, $height, $background = null)
|
|
||||||
{
|
|
||||||
return $this->createDriver()->newImage($width, $height, $background);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new cached image and run callback
|
|
||||||
* (requires additional package intervention/imagecache)
|
|
||||||
*
|
|
||||||
* @param Closure $callback
|
|
||||||
* @param integer $lifetime
|
|
||||||
* @param boolean $returnObj
|
|
||||||
*
|
|
||||||
* @return Image
|
|
||||||
*/
|
|
||||||
public function cache(Closure $callback, $lifetime = null, $returnObj = false)
|
|
||||||
{
|
|
||||||
if (class_exists('Intervention\\Image\\ImageCache')) {
|
|
||||||
// create imagecache
|
|
||||||
$imagecache = new ImageCache($this);
|
|
||||||
|
|
||||||
// run callback
|
|
||||||
if (is_callable($callback)) {
|
|
||||||
$callback($imagecache);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $imagecache->get($lifetime, $returnObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Intervention\Image\Exception\NotSupportedException(
|
|
||||||
"Please install package intervention/imagecache before running this function."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -7,30 +7,42 @@ use Closure;
|
|||||||
class ImageManagerStatic
|
class ImageManagerStatic
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Instance of Intervention\Image\ImageManagerBasic
|
* Instance of Intervention\Image\ImageManager
|
||||||
*
|
*
|
||||||
* @var ImageManagerBasic
|
* @var ImageManager
|
||||||
*/
|
*/
|
||||||
public $manager;
|
public static $manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
* @param ImageManagerBasic $manager
|
* @param ImageManager $manager
|
||||||
*/
|
*/
|
||||||
public function __construct(ImageManagerBasic $manager = null)
|
public function __construct(ImageManager $manager = null)
|
||||||
{
|
{
|
||||||
$this->manager = $manager ? $manager : new ImageManagerBasic;
|
self::$manager = $manager ? $manager : new ImageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Get or create new ImageManager instance
|
||||||
*
|
*
|
||||||
* @return Intervention\Image\ImageManagerStatic
|
* @return ImageManager
|
||||||
*/
|
*/
|
||||||
public static function newInstance()
|
public static function getManager()
|
||||||
{
|
{
|
||||||
return new self;
|
return self::$manager ? self::$manager : new ImageManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Statically create new custom configured image manager
|
||||||
|
*
|
||||||
|
* @param array $config
|
||||||
|
*
|
||||||
|
* @return ImageManager
|
||||||
|
*/
|
||||||
|
public static function configure(array $config = array())
|
||||||
|
{
|
||||||
|
return self::$manager = self::getManager()->configure($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +54,7 @@ class ImageManagerStatic
|
|||||||
*/
|
*/
|
||||||
public static function make($data)
|
public static function make($data)
|
||||||
{
|
{
|
||||||
return self::newInstance()->manager->make($data);
|
return self::getManager()->make($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,7 +68,7 @@ class ImageManagerStatic
|
|||||||
*/
|
*/
|
||||||
public static function canvas($width, $height, $background = null)
|
public static function canvas($width, $height, $background = null)
|
||||||
{
|
{
|
||||||
return self::newInstance()->manager->canvas($width, $height, $background);
|
return self::getManager()->canvas($width, $height, $background);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,6 +82,6 @@ class ImageManagerStatic
|
|||||||
*/
|
*/
|
||||||
public static function cache(Closure $callback, $lifetime = null, $returnObj = false)
|
public static function cache(Closure $callback, $lifetime = null, $returnObj = false)
|
||||||
{
|
{
|
||||||
return self::newInstance()->manager->cache($callback, $lifetime, $returnObj);
|
return self::getManager()->cache($callback, $lifetime, $returnObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -100,7 +100,7 @@ class ImageServiceProvider extends ServiceProvider
|
|||||||
$app = $this->app;
|
$app = $this->app;
|
||||||
|
|
||||||
$app['image'] = $app->share(function ($app) {
|
$app['image'] = $app->share(function ($app) {
|
||||||
return new ImageManager($app['config']);
|
return new ImageManager($app['config']->get('image::config'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1557,9 +1557,8 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
private function manager()
|
private function manager()
|
||||||
{
|
{
|
||||||
$manager = new \Intervention\Image\ImageManager;
|
return new \Intervention\Image\ImageManager(array(
|
||||||
$manager->config->set('image::driver', 'gd');
|
'driver' => 'gd'
|
||||||
|
));
|
||||||
return $manager;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,27 +9,27 @@ class ImageManagerStaticTest extends PHPUnit_Framework_TestCase
|
|||||||
Mockery::close();
|
Mockery::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewInstance()
|
public function testGetManager()
|
||||||
{
|
{
|
||||||
$manager = Mockery::mock('Intervention\Image\ImageManagerBasic');
|
$manager = Mockery::mock('Intervention\Image\ImageManager');
|
||||||
$managerStatic = new ImageManagerStatic($manager);
|
$managerStatic = new ImageManagerStatic($manager);
|
||||||
$m = $managerStatic->newInstance();
|
$m = $managerStatic->getManager();
|
||||||
$this->assertInstanceOf('Intervention\Image\ImageManagerStatic', $m);
|
$this->assertInstanceOf('Intervention\Image\ImageManager', $m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMake()
|
public function testMake()
|
||||||
{
|
{
|
||||||
$manager = Mockery::mock('Intervention\Image\ImageManagerBasic');
|
$manager = Mockery::mock('Intervention\Image\ImageManager');
|
||||||
|
$manager->shouldReceive('make')->with('foo')->once();
|
||||||
$managerStatic = new ImageManagerStatic($manager);
|
$managerStatic = new ImageManagerStatic($manager);
|
||||||
$img = $managerStatic->make('tests/images/tile.png');
|
$managerStatic->make('foo');
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanvas()
|
public function testCanvas()
|
||||||
{
|
{
|
||||||
$manager = Mockery::mock('Intervention\Image\ImageManagerBasic');
|
$manager = Mockery::mock('Intervention\Image\ImageManager');
|
||||||
|
$manager->shouldReceive('canvas')->with(100, 100, null)->once();
|
||||||
$managerStatic = new ImageManagerStatic($manager);
|
$managerStatic = new ImageManagerStatic($manager);
|
||||||
$img = $managerStatic->canvas(100, 100);
|
$managerStatic->canvas(100, 100);
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
tests/ImageManagerTest.php
Normal file
29
tests/ImageManagerTest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Intervention\Image\ImageManager;
|
||||||
|
|
||||||
|
class ImageManagerTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
Mockery::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
|
$config = array('driver' => 'foo', 'bar' => 'baz');
|
||||||
|
$manager = new ImageManager($config);
|
||||||
|
$this->assertEquals('foo', $manager->config['driver']);
|
||||||
|
$this->assertEquals('baz', $manager->config['bar']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConfigure()
|
||||||
|
{
|
||||||
|
$overwrite = array('driver' => 'none', 'bar' => 'none');
|
||||||
|
$config = array('driver' => 'foo', 'bar' => 'baz');
|
||||||
|
$manager = new ImageManager($overwrite);
|
||||||
|
$manager->configure($config);
|
||||||
|
$this->assertEquals('foo', $manager->config['driver']);
|
||||||
|
$this->assertEquals('baz', $manager->config['bar']);
|
||||||
|
}
|
||||||
|
}
|
@@ -1538,9 +1538,8 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
private function manager()
|
private function manager()
|
||||||
{
|
{
|
||||||
$manager = new \Intervention\Image\ImageManager;
|
return new \Intervention\Image\ImageManager(array(
|
||||||
$manager->config->set('image::driver', 'imagick');
|
'driver' => 'imagick'
|
||||||
|
));
|
||||||
return $manager;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user