Skip to content

Commit dd91ff8

Browse files
authored
Merge pull request #485 from raul338/cakephp-deprecations
Prepare for CakePHP 3.6
2 parents d42df95 + 66b7630 commit dd91ff8

File tree

12 files changed

+108
-90
lines changed

12 files changed

+108
-90
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7.0
6+
- 7.1
7+
- 7.2
78

89
sudo: false
910

@@ -22,10 +23,10 @@ matrix:
2223
fast_finish: true
2324

2425
include:
25-
- php: 5.5
26+
- php: 5.6
2627
env: PHPCS=1 DEFAULT=0
2728

28-
- php: 5.5
29+
- php: 5.6
2930
env: COVERALLS=1 DEFAULT=0
3031

3132
- php: hhvm

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[![Build Status](https://img.shields.io/travis/FriendsOfCake/cakephp-upload/master.svg?style=flat-square)](https://travis-ci.org/FriendsOfCake/cakephp-upload)
2-
[![Coverage Status](https://img.shields.io/coveralls/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://coveralls.io/r/FriendsOfCake/cakephp-upload?branch=master)
3-
[![Total Downloads](https://img.shields.io/packagist/dt/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload)
4-
[![Latest Stable Version](https://img.shields.io/packagist/v/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload)
1+
[![Build Status](https://img.shields.io/travis/FriendsOfCake/cakephp-upload/master.svg?style=flat-square)](https://travis-ci.org/FriendsOfCake/cakephp-upload)
2+
[![Coverage Status](https://img.shields.io/coveralls/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://coveralls.io/r/FriendsOfCake/cakephp-upload?branch=master)
3+
[![Total Downloads](https://img.shields.io/packagist/dt/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload)
4+
[![Latest Stable Version](https://img.shields.io/packagist/v/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload)
55
[![Documentation Status](https://readthedocs.org/projects/cakephp-upload/badge/?version=latest&style=flat-square)](https://readthedocs.org/projects/cakephp-upload/?badge=latest)
66
[![Gratipay](https://img.shields.io/gratipay/josegonzalez.svg?style=flat-square)](https://gratipay.com/~josegonzalez/)
77

@@ -15,8 +15,8 @@ See [this blog post](http://josediazgonzalez.com/2015/12/05/uploading-files-and-
1515

1616
## Requirements
1717

18-
* CakePHP 3.x
19-
* PHP 5.4+
18+
* CakePHP 3.4+
19+
* PHP 5.6+
2020

2121
## Documentation
2222
For documentation, please see [the docs](http://cakephp-upload.readthedocs.org/en/latest/).

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
],
1414
"require": {
1515
"cakephp/orm": "3.*",
16-
"php": ">=5.5",
16+
"php": ">=5.6",
1717
"league/flysystem": "*"
1818
},
1919
"require-dev": {
20-
"cakephp/cakephp": "~3.0",
20+
"cakephp/cakephp": "~3.4",
2121
"phpunit/phpunit": "<6.0",
2222
"league/flysystem-vfs": "*",
2323
"cakephp/cakephp-codesniffer": "dev-master",

docs/examples.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ Basic example
6363
*/
6464
?>
6565
<?php echo $this->Form->create($user, ['type' => 'file']); ?>
66-
<?php echo $this->Form->input('username'); ?>
67-
<?php echo $this->Form->input('photo', ['type' => 'file']); ?>
66+
<?php echo $this->Form->control('username'); ?>
67+
<?php echo $this->Form->control('photo', ['type' => 'file']); ?>
68+
// for CakePHP 3.0.x-3.3.x, use the following lines instead of the previous:
69+
// <?php echo $this->Form->input('username'); ?>
70+
// <?php echo $this->Form->input('photo', ['type' => 'file']); ?>
6871
<?php echo $this->Form->end(); ?>
69-
70-
Note: If you used *bake* to generate MVC structure after creating
72+
73+
Note: If you used *bake* to generate MVC structure after creating
7174
the users table, you will need to remove the default scalar validation
72-
for the photos field.
73-
75+
for the photos field.
76+
7477
.. code:: php
7578
public function validationDefault(Validator $validator)
7679
{

phpunit.xml.dist

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
</testsuites>
1919

2020
<filter>
21-
<blacklist>
22-
<directory suffix=".php">./docs</directory>
23-
<directory suffix=".php">./vendor</directory>
24-
<directory suffix=".php">./tests</directory>
25-
<file>./tests/bootstrap.php</file>
26-
</blacklist>
21+
<whitelist>
22+
<directory suffix=".php">./src</directory>
23+
</whitelist>
2724
</filter>
2825

2926
<!-- Setup a listener for fixtures -->

src/Database/Type/FileType.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Josegonzalez\Upload\Database\Type;
33

4+
use Cake\Database\Driver;
45
use Cake\Database\Type;
56

67
class FileType extends Type
@@ -18,4 +19,20 @@ public function marshal($value)
1819
{
1920
return $value;
2021
}
22+
23+
/**
24+
* {@inheritDoc}
25+
*/
26+
public function toDatabase($value, Driver $driver)
27+
{
28+
return $value;
29+
}
30+
31+
/**
32+
* {@inheritDoc}
33+
*/
34+
public function toPHP($value, Driver $driver)
35+
{
36+
return $value;
37+
}
2138
}

src/File/Path/Basepath/DefaultTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public function basepath()
2222
if ($this->entity->isNew()) {
2323
throw new LogicException('{primaryKey} substitution not allowed for new entities');
2424
}
25-
if (is_array($this->table->primaryKey())) {
25+
if (is_array($this->table->getPrimaryKey())) {
2626
throw new LogicException('{primaryKey} substitution not valid for composite primary keys');
2727
}
2828
}
2929

3030
$replacements = [
31-
'{primaryKey}' => $this->entity->get($this->table->primaryKey()),
32-
'{model}' => $this->table->alias(),
33-
'{table}' => $this->table->table(),
31+
'{primaryKey}' => $this->entity->get($this->table->getPrimaryKey()),
32+
'{model}' => $this->table->getAlias(),
33+
'{table}' => $this->table->getTable(),
3434
'{field}' => $this->field,
3535
'{year}' => date("Y"),
3636
'{month}' => date("m"),

src/File/Transformer/SlugTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
namespace Josegonzalez\Upload\File\Transformer;
33

4-
use Cake\Utility\Inflector;
4+
use Cake\Utility\Text;
55
use Josegonzalez\Upload\File\Transformer\DefaultTransformer;
66

77
class SlugTransformer extends DefaultTransformer
88
{
99
/**
1010
* Creates a set of files from the initial data and returns them as key/value
1111
* pairs, where the path on disk maps to name which each file should have.
12-
* The file name will be sluggified (using Inflector::slug()) and lowercased.
12+
* The file name will be sluggified (using Text::slug()) and lowercased.
1313
*
1414
* Example:
1515
*
@@ -25,7 +25,7 @@ class SlugTransformer extends DefaultTransformer
2525
public function transform()
2626
{
2727
$filename = pathinfo($this->data['name'], PATHINFO_FILENAME);
28-
$filename = Inflector::slug($filename, '-');
28+
$filename = Text::slug($filename, '-');
2929

3030
$ext = pathinfo($this->data['name'], PATHINFO_EXTENSION);
3131
if (!empty($ext)) {

src/Model/Behavior/UploadBehavior.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public function initialize(array $config)
3737
}
3838
}
3939

40-
$this->config($configs);
41-
$this->config('className', null);
40+
$this->setConfig($configs);
41+
$this->setConfig('className', null);
4242

4343
Type::map('upload.file', 'Josegonzalez\Upload\Database\Type\FileType');
44-
$schema = $this->_table->schema();
45-
foreach (array_keys($this->config()) as $field) {
46-
$schema->columnType($field, 'upload.file');
44+
$schema = $this->_table->getSchema();
45+
foreach (array_keys($this->getConfig()) as $field) {
46+
$schema->setColumnType($field, 'upload.file');
4747
}
48-
$this->_table->schema($schema);
48+
$this->_table->setSchema($schema);
4949
}
5050

5151
/**
@@ -58,9 +58,9 @@ public function initialize(array $config)
5858
*/
5959
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
6060
{
61-
$validator = $this->_table->validator();
61+
$validator = $this->_table->getValidator();
6262
$dataArray = $data->getArrayCopy();
63-
foreach (array_keys($this->config()) as $field) {
63+
foreach (array_keys($this->getConfig(null, [])) as $field) {
6464
if (!$validator->isEmptyAllowed($field, false)) {
6565
continue;
6666
}
@@ -82,15 +82,15 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti
8282
*/
8383
public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
8484
{
85-
foreach ($this->config() as $field => $settings) {
85+
foreach ($this->getConfig(null, []) as $field => $settings) {
8686
if (in_array($field, $this->protectedFieldNames)) {
8787
continue;
8888
}
8989

9090
if (Hash::get((array)$entity->get($field), 'error') !== UPLOAD_ERR_OK) {
9191
if (Hash::get($settings, 'restoreValueOnFailure', true)) {
9292
$entity->set($field, $entity->getOriginal($field));
93-
$entity->dirty($field, false);
93+
$entity->setDirty($field, false);
9494
}
9595
continue;
9696
}
@@ -128,7 +128,7 @@ public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
128128
{
129129
$result = true;
130130

131-
foreach ($this->config() as $field => $settings) {
131+
foreach ($this->getConfig(null, []) as $field => $settings) {
132132
if (in_array($field, $this->protectedFieldNames) || Hash::get($settings, 'keepFilesOnDelete', true)) {
133133
continue;
134134
}

tests/TestCase/File/Path/Basepath/DefaultTraitTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function testNoSpecialConfiguration()
1717
$mock->data = ['name' => 'filename'];
1818
$mock->field = 'field';
1919
$mock->entity->expects($this->once())->method('get')->will($this->returnValue(1));
20-
$mock->table->expects($this->once())->method('alias')->will($this->returnValue('Table'));
21-
$mock->table->expects($this->once())->method('primaryKey')->will($this->returnValue('id'));
20+
$mock->table->expects($this->once())->method('getAlias')->will($this->returnValue('Table'));
21+
$mock->table->expects($this->once())->method('getPrimaryKey')->will($this->returnValue('id'));
2222
$this->assertEquals('webroot/files/Table/field/', $mock->basepath());
2323
}
2424

@@ -31,8 +31,8 @@ public function testCustomPath()
3131
$mock->data = ['name' => 'filename'];
3232
$mock->field = 'field';
3333
$mock->entity->expects($this->once())->method('get')->will($this->returnValue(1));
34-
$mock->table->expects($this->once())->method('alias')->will($this->returnValue('Table'));
35-
$mock->table->expects($this->once())->method('primaryKey')->will($this->returnValue('id'));
34+
$mock->table->expects($this->once())->method('getAlias')->will($this->returnValue('Table'));
35+
$mock->table->expects($this->once())->method('getPrimaryKey')->will($this->returnValue('id'));
3636
$this->assertEquals('webroot/files/Table-field/', $mock->basepath());
3737
}
3838

@@ -45,8 +45,8 @@ public function testExistingEntityWithPrimaryKey()
4545
$mock->data = ['name' => 'filename'];
4646
$mock->field = 'field';
4747
$mock->entity->expects($this->once())->method('get')->will($this->returnValue(1));
48-
$mock->table->expects($this->once())->method('alias')->will($this->returnValue('Table'));
49-
$mock->table->expects($this->exactly(2))->method('primaryKey')->will($this->returnValue('id'));
48+
$mock->table->expects($this->once())->method('getAlias')->will($this->returnValue('Table'));
49+
$mock->table->expects($this->exactly(2))->method('getPrimaryKey')->will($this->returnValue('id'));
5050
$this->assertEquals('webroot/files/Table-field/1/', $mock->basepath());
5151
}
5252

@@ -75,7 +75,7 @@ public function testExitingEntityWithCompositePrimaryKey()
7575
$mock->data = ['name' => 'filename'];
7676
$mock->field = 'field';
7777
$mock->entity->expects($this->once())->method('isNew')->will($this->returnValue(false));
78-
$mock->table->expects($this->once())->method('primaryKey')->will($this->returnValue(['id', 'other_id']));
78+
$mock->table->expects($this->once())->method('getPrimaryKey')->will($this->returnValue(['id', 'other_id']));
7979
$mock->basepath();
8080
}
8181

@@ -113,7 +113,7 @@ public function testModelFieldYearWithMonthAndDayPath()
113113
$mock->data = ['name' => 'filename'];
114114
$mock->field = 'field';
115115
$mock->entity->expects($this->once())->method('get')->will($this->returnValue(1));
116-
$mock->table->expects($this->once())->method('alias')->will($this->returnValue('Table'));
116+
$mock->table->expects($this->once())->method('getAlias')->will($this->returnValue('Table'));
117117

118118
$this->assertEquals('webroot/files/Table/field/' . date("Y") . '/' . date("m") . '/' . date("d") . '/', $mock->basepath());
119119
}
@@ -169,7 +169,7 @@ public function testFieldValue()
169169
$mock->data = ['name' => 'filename'];
170170
$mock->field = 'field';
171171
$mock->entity->expects($this->any())->method('get')->will($this->returnValue('value'));
172-
$mock->table->expects($this->once())->method('alias')->will($this->returnValue('Table'));
172+
$mock->table->expects($this->once())->method('getAlias')->will($this->returnValue('Table'));
173173
$this->assertEquals('webroot/files/Table/value/', $mock->basepath());
174174
}
175175
}

0 commit comments

Comments
 (0)