Skip to content

Commit

Permalink
Merge pull request #422 from rexxars/cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
rexxars committed Dec 9, 2015
2 parents 1e778c6 + 68bd786 commit 9a94505
Show file tree
Hide file tree
Showing 51 changed files with 77 additions and 108 deletions.
Empty file modified library/Imbo/Application.php
100755 → 100644
Empty file.
33 changes: 33 additions & 0 deletions library/Imbo/Auth/AccessControl/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,37 @@ public function hasAccess($publicKey, $resource, $user = null) {

return false;
}

/**
* {@inheritdoc}
*/
public function getUsersForResource($publicKey, $resource) {
if (!$publicKey || !$resource) {
return [];
}

$accessList = $this->getAccessListForPublicKey($publicKey);

// Get all user lists
$userLists = array_filter(array_map(function($acl) {
return isset($acl['users']) ? $acl['users'] : false;
}, $accessList));

// Merge user lists
$users = call_user_func_array('array_merge', $userLists);

// Check if public key has access to user with same name
if ($this->hasAccess($publicKey, $resource, $publicKey)) {
$userList[] = $publicKey;
}

// Check for each user specified in acls
foreach ($users as $user) {
if ($this->hasAccess($publicKey, $resource, $user)) {
$userList[] = $user;
}
}

return $userList;
}
}
33 changes: 0 additions & 33 deletions library/Imbo/Auth/AccessControl/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,6 @@ public function __construct(array $accessList = [], $groups = []) {
$this->validateAccessList();
}

/**
* {@inheritdoc}
*/
public function getUsersForResource($publicKey, $resource) {
if (!$publicKey || !$resource) {
return [];
}

$accessList = $this->getAccessListForPublicKey($publicKey);

// Get all user lists
$userLists = array_filter(array_map(function($acl) {
return isset($acl['users']) ? $acl['users'] : false;
}, $accessList));

// Merge user lists
$users = call_user_func_array('array_merge', $userLists);

// Check if public key has access to user with same name
if ($this->hasAccess($publicKey, $resource, $publicKey)) {
$userList[] = $publicKey;
}

// Check for each user specified in acls
foreach ($users as $user) {
if ($this->hasAccess($publicKey, $resource, $user)) {
$userList[] = $user;
}
}

return $userList;
}

/**
* {@inheritdoc}
*/
Expand Down
37 changes: 0 additions & 37 deletions library/Imbo/Auth/AccessControl/Adapter/MongoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
namespace Imbo\Auth\AccessControl\Adapter;

use Imbo\Exception\DatabaseException,
Imbo\Exception\InvalidArgumentException,
Imbo\Exception\RuntimeException,
Imbo\Auth\AccessControl\GroupQuery,
Imbo\Model\Groups as GroupsModel,
MongoClient,
Expand Down Expand Up @@ -106,39 +104,6 @@ public function __construct(array $params = null, MongoClient $client = null, Mo
}
}

/**
* {@inheritdoc}
*/
public function getUsersForResource($publicKey, $resource) {
if (!$publicKey || !$resource) {
return [];
}

$accessList = $this->getAccessListForPublicKey($publicKey);

// Get all user lists
$userLists = array_filter(array_map(function($acl) {
return isset($acl['users']) ? $acl['users'] : false;
}, $accessList));

// Merge user lists
$users = call_user_func_array('array_merge', $userLists);

// Check if public key has access to user with same name
if ($this->hasAccess($publicKey, $resource, $publicKey)) {
$userList[] = $publicKey;
}

// Check for each user specified in acls
foreach ($users as $user) {
if ($this->hasAccess($publicKey, $resource, $user)) {
$userList[] = $user;
}
}

return $userList;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -388,8 +353,6 @@ public function getAccessListForPublicKey($publicKey) {

return $info;
}, $info['acl']);

return $info['acl'];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Imbo\Auth\AccessControl\Adapter;

use Imbo\Exception\InvalidArgumentException,
Imbo\Auth\AccessControl\GroupQuery,
Imbo\Resource;

/**
Expand Down
Empty file modified library/Imbo/Database/Doctrine.php
100755 → 100644
Empty file.
2 changes: 0 additions & 2 deletions library/Imbo/EventListener/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
namespace Imbo\EventListener;

use Imbo\EventManager\EventInterface,
Imbo\Http\Request\Request,
Imbo\Exception\RuntimeException,
Imbo\Auth\AccessControl\AccessControlAdapter,
Imbo\Auth\AccessControl\GroupQuery,
Imbo\Model\Groups as GroupsModel,
Imbo\Resource;
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/EventListener/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function checkAccessToken(EventInterface $event) {
// See if we should modify the protocol for the incoming request
$protocol = $config['authentication']['protocol'];
if ($protocol === 'both') {
$uris = array_reduce($uris, function($dest, $uri) use ($protocol) {
$uris = array_reduce($uris, function($dest, $uri) {
$baseUrl = preg_replace('#^https?#', '', $uri);
$dest[] = 'http' . $baseUrl;
$dest[] = 'https' . $baseUrl;
Expand Down
1 change: 0 additions & 1 deletion library/Imbo/EventListener/DatabaseOperations.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ public function loadUser(EventInterface $event) {
public function loadStats(EventInterface $event) {
$response = $event->getResponse();
$database = $event->getDatabase();
$accessControl = $event->getAccessControl();

$statsModel = new Model\Stats();
$statsModel->setNumUsers($database->getNumUsers());
Expand Down
10 changes: 2 additions & 8 deletions library/Imbo/EventListener/ImageVariations/Database/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@

namespace Imbo\EventListener\ImageVariations\Database;

use Imbo\Model\Image,
Imbo\Model\Images,
Imbo\Resource\Images\Query,
Imbo\Exception\DatabaseException,
Doctrine\DBAL\Configuration,
use Doctrine\DBAL\Configuration,
Doctrine\DBAL\DriverManager,
Doctrine\DBAL\Connection,
PDO,
DateTime,
DateTimeZone;
PDO;

/**
* Doctrine 2 database driver for the image variations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

namespace Imbo\EventListener\ImageVariations\Database;

use Imbo\Model\Image,
Imbo\Model\Images,
Imbo\Resource\Images\Query,
Imbo\Exception\DatabaseException,
use Imbo\Exception\DatabaseException,
MongoClient,
MongoCollection,
MongoException;
Expand Down
Empty file modified library/Imbo/EventListener/StatsAccess.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/EventListener/StorageOperations.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/EventManager/Event.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Http/Response/Response.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Http/Response/ResponseFormatter.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/Imbo/Image/Identifier/Generator/RandomString.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Imbo\Image\Identifier\Generator;

use Imbo\Model\Image,
Ramsey\Uuid\Uuid as UuidFactory;
use Imbo\Model\Image;

/**
* Random string image identifier generator
Expand Down
3 changes: 2 additions & 1 deletion library/Imbo/Image/ImagePreparation.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Imbo\EventManager\EventInterface,
Imbo\EventListener\ListenerInterface,
Imbo\Image\Identifier\Generator\GeneratorInterface,
Imbo\Exception\ImageException,
Imbo\Exception,
Imbo\Model\Image,
Expand Down Expand Up @@ -109,7 +110,7 @@ private function generateImageIdentifier(EventInterface $event, Image $image) {
$imageIdentifierGenerator = $config['imageIdentifierGenerator'];

if (is_callable($imageIdentifierGenerator) &&
!($imageIdentifierGenerator instanceof ImageIdentifierGeneratorInterface)) {
!($imageIdentifierGenerator instanceof GeneratorInterface)) {
$imageIdentifierGenerator = $imageIdentifierGenerator();
}

Expand Down
Empty file modified library/Imbo/Image/Transformation/AutoRotate.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/Imbo/Image/Transformation/Blur.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Imbo\Image\Transformation;

use Imbo\Model\Image,
Imbo\Exception\TransformationException,
use Imbo\Exception\TransformationException,
Imbo\EventListener\ListenerInterface,
Imbo\EventManager\EventInterface,
ImagickException;
Expand Down
Empty file modified library/Imbo/Image/Transformation/Border.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Canvas.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Compress.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/Imbo/Image/Transformation/Contrast.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Imbo\Image\Transformation;

use Imbo\Model\Image,
Imbo\Exception\TransformationException,
use Imbo\Exception\TransformationException,
Imbo\EventListener\ListenerInterface,
Imbo\EventManager\EventInterface,
ImagickException;
Expand Down
3 changes: 1 addition & 2 deletions library/Imbo/Image/Transformation/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Imbo\Image\Transformation;

use Imbo\Model\Image,
Imbo\Exception\TransformationException,
use Imbo\Exception\TransformationException,
Imbo\EventListener\ListenerInterface,
Imbo\EventManager\EventInterface,
ImagickException;
Expand Down
Empty file modified library/Imbo/Image/Transformation/Desaturate.php
100755 → 100644
Empty file.
2 changes: 0 additions & 2 deletions library/Imbo/Image/Transformation/DrawPois.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
Imbo\EventManager\EventInterface,
Imbo\Model\Image,
Imagick,
ImagickPixel,
ImagickException,
ImagickPixelException,
ImagickDraw;

/**
Expand Down
Empty file modified library/Imbo/Image/Transformation/FlipVertically.php
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion library/Imbo/Image/Transformation/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function transform(EventInterface $event) {

// let's draw a histogram
$origwidth = 256;
$origheight = floor($origwidth / $ratio);
$width = $origwidth * $scale;
$height = floor($width / $ratio);

Expand Down
Empty file modified library/Imbo/Image/Transformation/MaxSize.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Modulate.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Resize.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Rotate.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Sepia.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/Imbo/Image/Transformation/Sharpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Imbo\Image\Transformation;

use Imbo\Model\Image,
Imbo\Exception\TransformationException,
use Imbo\Exception\TransformationException,
Imbo\EventListener\ListenerInterface,
Imbo\EventManager\EventInterface,
ImagickException;
Expand Down
Empty file modified library/Imbo/Image/Transformation/Thumbnail.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Transpose.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Transverse.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Image/Transformation/Watermark.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/Imbo/Resource/GlobalImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace Imbo\Resource;

use Imbo\EventManager\EventInterface,
Imbo\Exception\RuntimeException,
Imbo\Model;
Imbo\Exception\RuntimeException;

/**
* Global images resource
Expand Down
1 change: 0 additions & 1 deletion library/Imbo/Resource/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Imbo\Resource;

use Imbo\EventManager\EventInterface,
Imbo\Exception\InvalidArgumentException,
Imbo\Exception\ResourceException,
Imbo\Auth\AccessControl\Adapter\MutableAdapterInterface,
Imbo\Model\Group as GroupModel;
Expand Down
Empty file modified library/Imbo/Resource/Image.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Resource/ShortUrls.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Resource/Stats.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Storage/Filesystem.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Storage/GridFS.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Storage/S3.php
100755 → 100644
Empty file.
Empty file modified library/Imbo/Storage/StorageInterface.php
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions library/ImboCli/Command/AddPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace ImboCli\Command;

use Symfony\Component\Console\Command\Command as BaseCommand,
Symfony\Component\Console\Input\InputArgument,
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Question\Question,
Symfony\Component\Console\Question\ChoiceQuestion,
Expand Down
2 changes: 1 addition & 1 deletion setup/doctrine.sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ CREATE TABLE IF NOT EXISTS imagevariations (
height INTEGER NOT NULL,
added INTEGER NOT NULL,
PRIMARY KEY (user,imageIdentifier,width)
);
);
31 changes: 30 additions & 1 deletion tests/phpunit/ImboUnitTest/Image/ImagePreparationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

namespace ImboUnitTest\Image;

use Imbo\Image\ImagePreparation;
use Imbo\Image\ImagePreparation,
Imbo\Model\Image,
Imbo\Image\Identifier\Generator\GeneratorInterface;

/**
* @covers Imbo\Image\ImagePreparation
Expand Down Expand Up @@ -173,4 +175,31 @@ public function testInstantiatesImageIdentifierGeneratorOnCallable() {
$this->request->expects($this->once())->method('setImage')->with($this->isInstanceOf('Imbo\Model\Image'));
$this->prepare->prepareImage($event);
}

/**
* @covers Imbo\Image\ImagePreparation::prepareImage
* @covers Imbo\Image\ImagePreparation::generateImageIdentifier
*/
public function testDoesNotInstantiateCallableGenerator() {
$imagePath = FIXTURES_DIR . '/image.png';
$imageData = file_get_contents($imagePath);

$config['imageIdentifierGenerator'] = new CallableImageIdentifierGenerator();

$event = $this->getMock('Imbo\EventManager\Event');
$event->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
$event->expects($this->any())->method('getResponse')->will($this->returnValue($this->response));
$event->expects($this->any())->method('getConfig')->will($this->returnValue($config));
$event->expects($this->any())->method('getDatabase')->will($this->returnValue($this->database));

$this->request->expects($this->once())->method('getContent')->will($this->returnValue($imageData));
$this->request->expects($this->once())->method('setImage')->with($this->isInstanceOf('Imbo\Model\Image'));
$this->prepare->prepareImage($event);
}
}

class CallableImageIdentifierGenerator implements GeneratorInterface {
public function generate(Image $image) {}
public function isDeterministic() {}
public function __invoke() {}
}

0 comments on commit 9a94505

Please sign in to comment.