Skip to content

Commit 0f61a6a

Browse files
committed
Updated, use short array, renamed tests IndexController to DemoController + added factory
1 parent 465cbdc commit 0f61a6a

File tree

9 files changed

+62
-68
lines changed

9 files changed

+62
-68
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Service that provides API to manipulate images.
1414

1515
- Powered by [PHPThumb](https://github.com/masterexploder/PHPThumb)
1616
- Demo [webino-image-thumb.demo.webino.org](http://webino-image-thumb.demo.webino.org/)
17-
- [Reflection](http://webino-image-thumb.demo.webino.org/application/index/reflection)
18-
- [Whitespace cropper](http://webino-image-thumb.demo.webino.org/application/index/whitespace-cropper)
19-
- [Sharpen](http://webino-image-thumb.demo.webino.org/application/index/sharpen)
17+
- [Reflection](http://webino-image-thumb.demo.webino.org/application/demo/reflection)
18+
- [Whitespace cropper](http://webino-image-thumb.demo.webino.org/application/demo/whitespace-cropper)
19+
- [Sharpen](http://webino-image-thumb.demo.webino.org/application/demo/sharpen)
2020

2121
## Features
2222

composer.json

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
"homepage": "https://github.com/webino/WebinoImageThumb",
55
"type": "library",
66
"license": "BSD-3-Clause",
7-
"keywords": [
8-
"webino",
9-
"image",
10-
"thumb",
11-
"zf2",
12-
"zend",
13-
"framework"
14-
],
7+
"keywords": ["webino", "image", "thumb", "zf2", "zend", "framework"],
158
"authors": [
169
{
1710
"name": "Webino, s. r. o.",
@@ -26,8 +19,10 @@
2619
"role": "Developer"
2720
}
2821
],
22+
"minimum-stability": "dev",
23+
"prefer-stable": true,
2924
"require": {
30-
"php": ">=5.3.3",
25+
"php": ">=5.5",
3126
"ext-gd": "*",
3227
"masterexploder/PHPThumb": "2.*",
3328
"zendframework/zend-di": "2.*"

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"name": "WebinoImageThumb",
32
"devDependencies": {
43
"grunt": "0.4.*",
54
"grunt-cli": "0.1.*",

src/WebinoImageThumb/PhpThumb/Plugin/Sharpen.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
* Webino (https://github.com/webino/)
44
*
55
* @link https://github.com/webino/WebinoImageThumb/ for the canonical source repository
6-
* @copyright Copyright (c) 2013-2014 Webino, s. r. o. (http://webino.sk/)
6+
* @copyright Copyright (c) 2013-2015 Webino, s. r. o. (http://webino.sk/)
77
* @license BSD-3-Clause
88
*/
99

1010
namespace WebinoImageThumb\PhpThumb\Plugin;
1111

1212
use PHPThumb\GD as PHPThumb;
13+
use PHPThumb\PluginInterface;
1314

1415
/**
1516
* Sharpen plugin
1617
*
1718
* @author Miguel Vieira <vieira@miguelvieira.com.pt>
1819
*/
19-
class Sharpen implements \PHPThumb\PluginInterface
20+
class Sharpen implements PluginInterface
2021
{
2122
/**
2223
* @var int
@@ -26,17 +27,17 @@ class Sharpen implements \PHPThumb\PluginInterface
2627
/**
2728
* @var array
2829
*/
29-
protected $matrix = array(
30-
array(0.0, -1.0, 0.0),
31-
array(-1.0, 5.0, -1.0),
32-
array(0.0, -1.0, 0.0)
33-
);
30+
protected $matrix = [
31+
[0.0, -1.0, 0.0],
32+
[-1.0, 5.0, -1.0],
33+
[0.0, -1.0, 0.0],
34+
];
3435

3536
/**
36-
* @param type $offset Color offset
37-
* @param type $matrix A 3x3 matrix: an array of three arrays of three floats
37+
* @param int $offset Color offset
38+
* @param int $matrix A 3x3 matrix: an array of three arrays of three floats
3839
*/
39-
public function __construct($offset = 0, $matrix = array())
40+
public function __construct($offset = 0, $matrix = [])
4041
{
4142
empty($offset) or $this->offset = $offset;
4243
empty($matrix) or $this->matrix = $matrix;

src/WebinoImageThumb/Service/ImageThumb.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ImageThumb
3030
* @param array $plugins
3131
* @return PHPThumb
3232
*/
33-
public function create($filename = null, array $options = array(), array $plugins = array())
33+
public function create($filename = null, array $options = [], array $plugins = [])
3434
{
3535
try {
3636
$thumb = new PHPThumb($filename, $options, $plugins);
@@ -75,7 +75,7 @@ public function createWhitespaceCropper($border = 0, $color = 0)
7575
* @param array $matrix
7676
* @return ExtraPlugins\Sharpen
7777
*/
78-
public function createSharpen($offset = 0, array $matrix = array())
78+
public function createSharpen($offset = 0, array $matrix = [])
7979
{
8080
return new ExtraPlugins\Sharpen($offset, $matrix);
8181
}

tests/resources/config/module.config.php

+7-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* @license BSD-3-Clause
88
*/
99

10-
use Application\Controller\IndexController;
10+
namespace Application;
11+
12+
use Application\Controller;
13+
use Application\Factory;
1114
use Zend\I18n\Translator\TranslatorInterface;
1215
use Zend\I18n\Translator\TranslatorServiceFactory;
1316

@@ -20,46 +23,13 @@
2023
*/
2124
return [
2225
'service_manager' => [
23-
'aliases' => [
24-
'Application\Controller\Index' => IndexController::class,
25-
],
2626
'factories' => [
2727
TranslatorInterface::class => TranslatorServiceFactory::class,
2828
],
2929
],
30-
'router' => [
31-
'routes' => [
32-
'home' => [
33-
'options' => [
34-
'defaults' => [
35-
/**
36-
* We want to use the DI, so override the application
37-
* module config with a controller FQCN, instead of invocable alias
38-
*/
39-
'controller' => IndexController::class,
40-
],
41-
],
42-
],
43-
],
44-
],
45-
'di' => [
46-
/**
47-
* For security reasons we must allow
48-
* our controller for the DI
49-
*/
50-
'allowed_controllers' => [
51-
IndexController::class,
52-
],
53-
'instance' => [
54-
/**
55-
* Configure the controller
56-
* to inject WebinoImageThumb service
57-
*/
58-
IndexController::class => [
59-
'parameters' => [
60-
'thumbnailer' => 'WebinoImageThumb',
61-
],
62-
],
30+
'controllers' => [
31+
'factories' => [
32+
'Application\Controller\Demo' => Factory\DemoControllerFactory::class,
6333
],
6434
],
6535
'webino_debug' => [

tests/resources/src/Application/Controller/IndexController.php renamed to tests/resources/src/Application/Controller/DemoController.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
/**
1616
* Image Thumbnailer test application controller
1717
*/
18-
class IndexController extends AbstractActionController
18+
class DemoController extends AbstractActionController
1919
{
20-
2120
/**
2221
* @var ImageThumb
2322
*/
@@ -34,7 +33,7 @@ class IndexController extends AbstractActionController
3433
* To see how we configure the controller to use DI
3534
* check out tests/resources/config/module.config.php
3635
*
37-
* @param ImageThumb $thumbnailer
36+
* @param ImageThumb|object $thumbnailer
3837
*/
3938
public function __construct(ImageThumb $thumbnailer)
4039
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Webino (https://github.com/webino/)
4+
*
5+
* @link https://github.com/webino/WebinoImageThumb/ for the canonical source repository
6+
* @copyright Copyright (c) 2015 Webino, s. r. o. (http://webino.sk/)
7+
* @license BSD-3-Clause
8+
*/
9+
10+
namespace Application\Factory;
11+
12+
use Application\Controller\DemoController;
13+
use Zend\ServiceManager\FactoryInterface;
14+
use Zend\ServiceManager\ServiceLocatorInterface;
15+
16+
/**
17+
* Class DemoControllerFactory
18+
*/
19+
class DemoControllerFactory implements FactoryInterface
20+
{
21+
/**
22+
* @param ServiceLocatorInterface|\Zend\Mvc\Controller\ControllerManager $controllers
23+
* @return DemoController
24+
*/
25+
public function createService(ServiceLocatorInterface $controllers)
26+
{
27+
$services = $controllers->getServiceLocator();
28+
return new DemoController($services->get('WebinoImageThumb'));
29+
}
30+
}

tests/selenium/WebinoImageThumb/HomeTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HomeTest extends AbstractTestCase
1919
*/
2020
public function testReflection()
2121
{
22-
$src = file_get_contents($this->uri . 'application/index-controller/reflection');
22+
$src = file_get_contents($this->uri . 'application/demo/reflection');
2323
$this->assertJpegImage($src);
2424
}
2525

@@ -28,7 +28,7 @@ public function testReflection()
2828
*/
2929
public function testWhitespaceCropper()
3030
{
31-
$src = file_get_contents($this->uri . 'application/index-controller/whitespace-cropper');
31+
$src = file_get_contents($this->uri . 'application/demo/whitespace-cropper');
3232
$this->assertJpegImage($src);
3333
}
3434

@@ -37,7 +37,7 @@ public function testWhitespaceCropper()
3737
*/
3838
public function testSharpen()
3939
{
40-
$src = file_get_contents($this->uri . 'application/index-controller/sharpen');
40+
$src = file_get_contents($this->uri . 'application/demo/sharpen');
4141
$this->assertJpegImage($src);
4242
}
4343
}

0 commit comments

Comments
 (0)