Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #257 from davidyell/develop
Browse files Browse the repository at this point in the history
Merge for release
  • Loading branch information
davidyell authored Apr 17, 2018
2 parents e7894b0 + c9013b4 commit a96b6de
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"require-dev": {
"phpunit/phpunit": "^5.5",
"cakephp/cakephp": "~3.0",
"cakephp/cakephp": "^3.4.0",
"cakephp/cakephp-codesniffer": "^2.0"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Proffer\Database\Type;

use Cake\Database\Type;
use Cake\Database\Type\StringType;

class FileType extends Type
class FileType extends StringType
{
/**
* Prevent the marhsaller changing the upload array into a string
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/ProfferPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Table $table, Entity $entity, $field, array $setting
$this->setRoot(WWW_ROOT . 'files');
}

$this->setTable($table->alias());
$this->setTable($table->getAlias());
$this->setField($field);
$this->setSeed($this->generateSeed($entity->get($settings['dir'])));

Expand Down
24 changes: 12 additions & 12 deletions src/Model/Behavior/ProfferBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class ProfferBehavior extends Behavior
public function initialize(array $config)
{
Type::map('proffer.file', '\Proffer\Database\Type\FileType');
$schema = $this->_table->schema();
foreach (array_keys($this->config()) as $field) {
$schema->columnType($field, 'proffer.file');
$schema = $this->_table->getSchema();
foreach (array_keys($this->getConfig()) as $field) {
$schema->setColumnType($field, 'proffer.file');
}
$this->_table->schema($schema);
$this->_table->setSchema($schema);
}

/**
Expand All @@ -55,8 +55,8 @@ public function initialize(array $config)
*/
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
{
foreach ($this->config() as $field => $settings) {
if ($this->_table->validator()->isEmptyAllowed($field, false) &&
foreach ($this->getConfig() as $field => $settings) {
if ($this->_table->getValidator()->isEmptyAllowed($field, false) &&
isset($data[$field]['error']) && $data[$field]['error'] === UPLOAD_ERR_NO_FILE
) {
unset($data[$field]);
Expand All @@ -81,8 +81,8 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options, ProfferPathInterface $path = null)
{

foreach ($this->config() as $field => $settings) {
$tableEntityClass = $this->_table->entityClass();
foreach ($this->getConfig() as $field => $settings) {
$tableEntityClass = $this->_table->getEntityClass();

if ($entity->has($field) && is_array($entity->get($field)) && $entity->get($field)['error'] === UPLOAD_ERR_OK) {
$this->process($field, $settings, $entity, $path);
Expand Down Expand Up @@ -169,7 +169,7 @@ protected function createPath(EntityInterface $entity, $field, array $settings,
}

$event = new Event('Proffer.afterPath', $entity, ['path' => $path]);
$this->_table->eventManager()->dispatch($event);
$this->_table->getEventManager()->dispatch($event);
if (!empty($event->result)) {
$path = $event->result;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ protected function createThumbnails(EntityInterface $entity, array $settings, Pr

$eventData = ['path' => $path, 'images' => $imagePaths];
$event = new Event('Proffer.afterCreateImage', $entity, $eventData);
$this->_table->eventManager()->dispatch($event);
$this->_table->getEventManager()->dispatch($event);
}
}

Expand All @@ -228,7 +228,7 @@ protected function createThumbnails(EntityInterface $entity, array $settings, Pr
*/
public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $options, ProfferPathInterface $path = null)
{
foreach ($this->config() as $field => $settings) {
foreach ($this->getConfig() as $field => $settings) {
$dir = $entity->get($settings['dir']);

if (!empty($entity) && !empty($dir)) {
Expand All @@ -239,7 +239,7 @@ public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $
}

$event = new Event('Proffer.beforeDeleteFolder', $entity, ['path' => $path]);
$this->_table->eventManager()->dispatch($event);
$this->_table->getEventManager()->dispatch($event);
$path->deleteFiles($path->getFolder(), true);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/TestPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(Table $table, Entity $entity, $field, array $setting
{
$this->setRoot(TMP . 'ProfferTests');

$this->setTable($table->alias());
$this->setTable($table->getAlias());
$this->setField($field);
$this->setSeed('proffer_test');

Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Lib/ProfferPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ public function pathDataProvider()
public function testConstructedFullPath($data, $expected)
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['alias'])
->setMethods(['getAlias'])
->getMock();
$table->method('alias')
$table->method('getAlias')
->willReturn('ProfferTest');

$entity = new Entity($data['entity']);
Expand All @@ -136,9 +136,9 @@ public function testConstructedFullPath($data, $expected)
public function testGetFolder()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['alias'])
->setMethods(['getAlias'])
->getMock();
$table->method('alias')
$table->method('getAlias')
->willReturn('ProfferTest');

$entity = new Entity([
Expand All @@ -165,9 +165,9 @@ public function testGetFolder()
public function testPrefixes()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['alias'])
->setMethods(['getAlias'])
->getMock();
$table->method('alias')
$table->method('getAlias')
->willReturn('ProfferTest');

$entity = new Entity([
Expand All @@ -194,9 +194,9 @@ public function testPrefixes()
public function testDeleteFiles()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['alias'])
->setMethods(['getAlias'])
->getMock();
$table->method('alias')
$table->method('getAlias')
->willReturn('ProfferTest');

$entity = new Entity([
Expand All @@ -220,7 +220,7 @@ public function testDeleteFiles()

$path->expects($this->any())
->method('getFolder')
->willReturn(TMP . 'ProfferTests' . DS . $table->alias() . DS . 'photo' . DS . 'proffer_test' . DS);
->willReturn(TMP . 'ProfferTests' . DS . $table->getAlias() . DS . 'photo' . DS . 'proffer_test' . DS);

$path = new ProfferPath($table, $entity, 'photo', $settings);

Expand Down Expand Up @@ -258,9 +258,9 @@ public function testDeleteFiles()
public function testCreatingPathFolderWhichExists()
{
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['alias'])
->setMethods(['getAlias'])
->getMock();
$table->method('alias')
$table->method('getAlias')
->willReturn('ProfferTest');

$entity = new Entity([
Expand Down
Loading

0 comments on commit a96b6de

Please sign in to comment.