Skip to content

Commit

Permalink
Merge pull request #446 from christeredvartsen/issue-444
Browse files Browse the repository at this point in the history
Added a getData method to the model interface
  • Loading branch information
christeredvartsen committed Mar 17, 2016
2 parents c982fea + 2f975fe commit 1da4a2c
Show file tree
Hide file tree
Showing 25 changed files with 379 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog for Imbo
==================

Imbo-2.1.2
----------
__N/A__

* #444: Added a getData() method to the Imbo\Model\ModelInterface (Christer Edvartsen)

Imbo-2.1.1
----------
__2016-03-11__
Expand Down
12 changes: 12 additions & 0 deletions library/Imbo/Model/AccessRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,16 @@ public function setUsers(array $users) {
public function getUsers() {
return $this->users;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'id' => $this->getId(),
'group' => $this->getGroup(),
'resources' => $this->getResources(),
'users' => $this->getUsers(),
];
}
}
7 changes: 7 additions & 0 deletions library/Imbo/Model/AccessRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public function setRules(array $rules) {
public function getRules() {
return $this->rules;
}

/**
* {@inheritdoc}
*/
public function getData() {
return $this->getRules();
}
}
4 changes: 1 addition & 3 deletions library/Imbo/Model/ArrayModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function setData(array $data) {
}

/**
* Get the data
*
* @return array
* {@inheritdoc}
*/
public function getData() {
return $this->data;
Expand Down
13 changes: 13 additions & 0 deletions library/Imbo/Model/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ public function getImageIdentifier() {
return $this->imageIdentifier;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'httpCode' => $this->getHttpCode(),
'errorMessage' => $this->getErrorMessage(),
'date' => $this->getDate(),
'imboErrorCode' => $this->getImboErrorCode(),
'imageIdentifier' => $this->getImageIdentifier(),
];
}

/**
* Create an error based on an exception instance
*
Expand Down
10 changes: 10 additions & 0 deletions library/Imbo/Model/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ public function setResources(array $resources = []) {
public function getResources() {
return $this->resources;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'name' => $this->getName(),
'resources' => $this->getResources(),
];
}
}
13 changes: 13 additions & 0 deletions library/Imbo/Model/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,17 @@ public function setPage($page) {
public function getPage() {
return $this->page;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'groups' => $this->getGroups(),
'count' => $this->getCount(),
'hits' => $this->getHits(),
'limit' => $this->getLimit(),
'page' => $this->getPage(),
];
}
}
21 changes: 21 additions & 0 deletions library/Imbo/Model/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,27 @@ public function hasBeenTransformed($flag = null) {
return $this;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'filesize' => $this->getFilesize(),
'mimeType' => $this->getMimeType(),
'extension' => $this->getExtension(),
'metadata' => $this->getMetadata(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'addedDate' => $this->getAddedDate(),
'updatedDate' => $this->getUpdatedDate(),
'user' => $this->getUser(),
'imageIdentifier' => $this->getImageIdentifier(),
'checksum' => $this->getChecksum(),
'originalChecksum' => $this->getOriginalChecksum(),
'hasBeenTransformed' => $this->hasBeenTransformed(),
];
}

/**
* Check if a mime type is supported by Imbo
*
Expand Down
14 changes: 14 additions & 0 deletions library/Imbo/Model/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,18 @@ public function setPage($page) {
public function getPage() {
return $this->page;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'images' => $this->getImages(),
'fields' => $this->getFields(),
'count' => $this->getCount(),
'hits' => $this->getHits(),
'limit' => $this->getLimit(),
'page' => $this->getPage(),
];
}
}
11 changes: 11 additions & 0 deletions library/Imbo/Model/ListModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ public function setEntry($entry) {

return $this;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'list' => $this->getList(),
'container' => $this->getContainer(),
'entry' => $this->getEntry(),
];
}
}
9 changes: 8 additions & 1 deletion library/Imbo/Model/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
* @author Christer Edvartsen <cogo@starzinger.net>
* @package Models
*/
interface ModelInterface {}
interface ModelInterface {
/**
* Return the "data" found in the model
*
* @return mixed
*/
function getData();
}
12 changes: 12 additions & 0 deletions library/Imbo/Model/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,16 @@ public function offsetSet($offset, $value) {
public function offsetUnset($offset) {
unset($this->customStats[$offset]);
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'numUsers' => $this->getNumUsers(),
'numBytes' => $this->getNumBytes(),
'numImages' => $this->getNumImages(),
'customStats' => $this->getCustomStats(),
];
}
}
11 changes: 11 additions & 0 deletions library/Imbo/Model/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ public function setStorageStatus($status) {
public function getStorageStatus() {
return $this->storageStatus;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'date' => $this->getDate(),
'database' => $this->getDatabaseStatus(),
'storage' => $this->getStorageStatus(),
];
}
}
11 changes: 11 additions & 0 deletions library/Imbo/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ public function setLastModified(DateTime $date) {
public function getLastModified() {
return $this->lastModified;
}

/**
* {@inheritdoc}
*/
public function getData() {
return [
'id' => $this->getUserId(),
'numImages' => $this->getNumImages(),
'lastModified' => $this->getLastModified(),
];
}
}
18 changes: 18 additions & 0 deletions tests/phpunit/ImboUnitTest/Model/AccessRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,22 @@ public function testSetAndGetUsers() {
$this->assertSame($this->model, $this->model->setUsers(['u1', 'u2']));
$this->assertSame(['u1', 'u2'], $this->model->getUsers());
}

/**
* @covers Imbo\Model\AccessRule::getData
*/
public function testGetData() {
$this->model
->setId(1)
->setGroup('name')
->setResources(['r1', 'r2'])
->setUsers(['u1', 'u2']);

$this->assertSame([
'id' => 1,
'group' => 'name',
'resources' => ['r1', 'r2'],
'users' => ['u1', 'u2'],
], $this->model->getData());
}
}
3 changes: 3 additions & 0 deletions tests/phpunit/ImboUnitTest/Model/AccessRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public function tearDown() {
/**
* @covers Imbo\Model\AccessRules::getRules
* @covers Imbo\Model\AccessRules::setRules
* @covers Imbo\Model\AccessRules::getData
*/
public function testSetAndGetId() {
$rules = [
['id' => 1, 'group' => 'group', 'users' => ['user']],
['id' => 2, 'resources' => ['image.get', 'image.head'], 'users' => ['user']],
];
$this->assertSame([], $this->model->getRules());
$this->assertSame([], $this->model->getData());
$this->assertSame($this->model, $this->model->setRules($rules));
$this->assertSame($rules, $this->model->getRules());
$this->assertSame($rules, $this->model->getData());
}
}
21 changes: 21 additions & 0 deletions tests/phpunit/ImboUnitTest/Model/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,25 @@ public function testWillUseImageIdentifierFromImageModelIfRequestHasAnImageWhenC
$this->assertSame(123, $model->getImboErrorCode());
$this->assertSame('imageId', $model->getImageIdentifier());
}

/**
* @covers Imbo\Model\Error::getData
*/
public function testGetData() {
$date = new DateTime();

$this->model->setHttpCode(404);
$this->model->setErrorMessage('message');
$this->model->setDate($date);
$this->model->setImboErrorCode(100);
$this->model->setImageIdentifier('identifier');

$this->assertSame([
'httpCode' => 404,
'errorMessage' => 'message',
'date' => $date,
'imboErrorCode' => 100,
'imageIdentifier' => 'identifier',
], $this->model->getData());
}
}
14 changes: 14 additions & 0 deletions tests/phpunit/ImboUnitTest/Model/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,18 @@ public function testSetAndGetResources() {
$this->assertSame($this->model, $this->model->setResources(['image.get', 'image.head']));
$this->assertSame(['image.get', 'image.head'], $this->model->getResources());
}

/**
* @covers Imbo\Model\Group::getData
*/
public function testGetData() {
$this->model
->setName('name')
->setResources(['image.get', 'image.head']);

$this->assertSame([
'name' => 'name',
'resources' => ['image.get', 'image.head'],
], $this->model->getData());
}
}
19 changes: 19 additions & 0 deletions tests/phpunit/ImboUnitTest/Model/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,23 @@ public function testCanCountImages() {
$this->assertSame($this->model, $this->model->setGroups(['group1' => [], 'group2' => []]));
$this->assertSame(2, $this->model->getCount());
}

/**
* @covers Imbo\Model\Groups::getData
*/
public function testGetData() {
$this->model
->setGroups(['group' => [], 'group2' => []])
->setHits(10)
->setPage(10)
->setLimit(10);

$this->assertSame([
'groups' => ['group' => [], 'group2' => []],
'count' => 2,
'hits' => 10,
'limit' => 10,
'page' => 10,
], $this->model->getData());
}
}

0 comments on commit 1da4a2c

Please sign in to comment.