1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 08:40:33 +02:00

removed illuminate depedencies

This commit is contained in:
Oliver Vogel
2014-08-01 11:04:36 +02:00
parent 2c61389c6e
commit 2fb5e286e4
9 changed files with 105 additions and 181 deletions

View File

@@ -17,16 +17,12 @@
},
"require-dev": {
"phpunit/phpunit": "3.*",
"mockery/mockery": "0.9.*",
"illuminate/support": "4.*",
"illuminate/config": "4.*"
"mockery/mockery": "0.9.*"
},
"suggest": {
"ext-gd": "to use GD library based image processing.",
"ext-imagick": "to use Imagick based image processing.",
"intervention/imagecache": "Caching extension for the Intervention Image library",
"illuminate/support": "Used for Laravel integration",
"illuminate/config": "Used for Laravel integration"
"intervention/imagecache": "Caching extension for the Intervention Image library"
},
"autoload": {
"psr-0": {

View File

@@ -3,60 +3,38 @@
namespace Intervention\Image;
use Closure;
use Illuminate\Config\Repository as Config;
use Illuminate\Config\FileLoader;
use Illuminate\Filesystem\Filesystem;
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
*
* @param \Illuminate\Config\Repository $config
* @param array $config
*/
public function __construct(\Illuminate\Config\Repository $config = null)
public function __construct(array $config = array())
{
// create configurator
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');
}
$this->configure($config);
}
/**
* 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'));
$driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
$this->config = array_replace($this->config, $config);
if (class_exists($driverclass)) {
return new $driverclass;
}
throw new \Intervention\Image\Exception\NotSupportedException(
"Driver ({$drivername}) could not be instantiated."
);
return $this;
}
/**
@@ -113,4 +91,23 @@ class ImageManager
"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."
);
}
}

View File

@@ -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."
);
}
}

View File

@@ -7,30 +7,42 @@ use Closure;
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
*
* @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)
{
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)
{
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)
{
return self::newInstance()->manager->cache($callback, $lifetime, $returnObj);
return self::getManager()->cache($callback, $lifetime, $returnObj);
}
}

View File

@@ -100,7 +100,7 @@ class ImageServiceProvider extends ServiceProvider
$app = $this->app;
$app['image'] = $app->share(function ($app) {
return new ImageManager($app['config']);
return new ImageManager($app['config']->get('image::config'));
});
}

View File

@@ -1557,9 +1557,8 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
private function manager()
{
$manager = new \Intervention\Image\ImageManager;
$manager->config->set('image::driver', 'gd');
return $manager;
return new \Intervention\Image\ImageManager(array(
'driver' => 'gd'
));
}
}

View File

@@ -9,27 +9,27 @@ class ImageManagerStaticTest extends PHPUnit_Framework_TestCase
Mockery::close();
}
public function testNewInstance()
public function testGetManager()
{
$manager = Mockery::mock('Intervention\Image\ImageManagerBasic');
$manager = Mockery::mock('Intervention\Image\ImageManager');
$managerStatic = new ImageManagerStatic($manager);
$m = $managerStatic->newInstance();
$this->assertInstanceOf('Intervention\Image\ImageManagerStatic', $m);
$m = $managerStatic->getManager();
$this->assertInstanceOf('Intervention\Image\ImageManager', $m);
}
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);
$img = $managerStatic->make('tests/images/tile.png');
$this->assertInstanceOf('Intervention\Image\Image', $img);
$managerStatic->make('foo');
}
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);
$img = $managerStatic->canvas(100, 100);
$this->assertInstanceOf('Intervention\Image\Image', $img);
$managerStatic->canvas(100, 100);
}
}

View 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']);
}
}

View File

@@ -1538,9 +1538,8 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
private function manager()
{
$manager = new \Intervention\Image\ImageManager;
$manager->config->set('image::driver', 'imagick');
return $manager;
return new \Intervention\Image\ImageManager(array(
'driver' => 'imagick'
));
}
}