Skip to content

Commit 2cde9b6

Browse files
authored
Merge pull request #40 from CakeDC/3.4
3.4
2 parents d2c9b29 + 0cefd19 commit 2cde9b6

File tree

166 files changed

+2995
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+2995
-942
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ vendor/
77
composer.lock
88
tmp
99
pmip
10-
webroot/coverage
10+
webroot/coverage
11+
.php_cs.cache

.travis.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
php:
44
- 5.6
55
- 7.0
6-
6+
- 7.1
77
sudo: false
88

99
env:
@@ -18,11 +18,11 @@ matrix:
1818
fast_finish: true
1919

2020
include:
21-
- php: 5.6
21+
- php: 7.1
2222
env: PHPCS=1 DEFAULT=0
2323

24-
- php: 5.6
25-
env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://[email protected]/cakephp_test'
24+
- php: 7.1
25+
env: CODECOVERAGE=1 DEFAULT=0 DB=mysql db_dsn='mysql://[email protected]/cakephp_test'
2626

2727
before_script:
2828
- composer self-update
@@ -33,14 +33,12 @@ before_script:
3333

3434
- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"
3535

36-
- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
37-
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"
38-
3936
script:
40-
- sh -c "if [ '$DEFAULT' = '1' ]; then vendor/bin/phpunit --stderr; fi"
37+
- sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit --stderr; fi"
4138
- sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p -n --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
42-
- sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/phpunit --stderr --coverage-clover build/logs/clover.xml; fi"
43-
- sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi"
39+
- sh -c "if [ '$CODECOVERAGE' = '1' ]; then phpunit --coverage-clover=clover.xml || true; fi"
40+
- sh -c "if [ '$CODECOVERAGE' = '1' ]; then wget -O codecov.sh https://codecov.io/bash; fi"
41+
- sh -c "if [ '$CODECOVERAGE' = '1' ]; then bash codecov.sh; fi"
4442

4543
notifications:
4644
email: false

composer.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"cakephp",
77
"api",
88
"rest",
9-
"hateaos",
9+
"hateoas",
1010
"crud"
1111
],
1212
"homepage": "https://github.com/CakeDC/cakephp-api",
@@ -28,16 +28,12 @@
2828
},
2929
"require": {
3030
"php": ">=5.4.16",
31-
"cakephp/cakephp": "3.*",
32-
"cakedc/users": "^5.0"
31+
"cakephp/cakephp": "^3.4",
32+
"cakedc/users": "^5.0|^6.0"
3333
},
3434
"require-dev": {
35-
"cakedc/users": "*" ,
3635
"phpunit/phpunit": "<6.0"
3736
},
38-
"suggest": {
39-
"cakedc/users": "Users Plugin for CakePHP"
40-
},
4137
"autoload": {
4238
"psr-4": {
4339
"CakeDC\\Api\\": "src",

config/api.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

@@ -68,5 +68,11 @@
6868
],
6969
],
7070
],
71+
'Log' => [
72+
'className' => 'File',
73+
'scopes' => ['api'],
74+
'levels' => ['error', 'info'],
75+
'file' => 'api.log',
76+
]
7177
]
7278
];

config/bootstrap.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
<?php/** * Copyright 2016, Cake Development Corporation (http://cakedc.com) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */use Cake\Core\Configure;Configure::load('CakeDC/Api.api');collection((array)Configure::read('Api.config'))->each(function ($file) { Configure::load($file);});
1+
<?php
2+
/**
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
4+
*
5+
* Licensed under The MIT License
6+
* Redistributions of files must retain the above copyright notice.
7+
*
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
9+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10+
*/
11+
12+
use Cake\Core\Configure;
13+
use Cake\Log\Log;
14+
15+
Configure::load('CakeDC/Api.api');
16+
collection((array)Configure::read('Api.config'))->each(function ($file) {
17+
Configure::load($file);
18+
});
19+
20+
if (!Log::engine('api')) {
21+
Log::setConfig('api', [
22+
'className' => Configure::read('Api.Log.className'),
23+
'path' => LOGS,
24+
'scopes' => Configure::read('Api.Log.scopes'),
25+
'levels' => Configure::read('Api.Log.levels'),
26+
'file' => Configure::read('Api.Log.file'),
27+
]);
28+
}

config/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

docs/Documentation/collections.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Collections
2+
==========
3+
4+
Collection actions allow to process many entities on the same endpoint call.
5+
This feature was created to allow easy integration with bulk actions, allowing to
6+
delete/edit/add many entities.
7+
8+
Adding collections to your own service is easy, use the `initialize()` method of your Service class.
9+
10+
* Use mapAction, map 3 routes to cover add/edit/delete
11+
12+
```php
13+
$this->mapAction('bulkAdd', AddEditAction::class, [
14+
'method' => ['POST'],
15+
'mapCors' => true,
16+
'path' => 'bulk'
17+
]);
18+
$this->mapAction('bulkEdit', AddEditAction::class, [
19+
'method' => ['PUT'],
20+
'mapCors' => true,
21+
'path' => 'bulk'
22+
]);
23+
$this->mapAction('bulkDelete', DeleteAction::class, [
24+
'method' => ['DELETE'],
25+
'mapCors' => true,
26+
'path' => 'bulk'
27+
]);
28+
```
29+
30+
If you need additional features, you can extend the specific actions
31+
and override the mapping configuration to use your own implementation.
32+
33+
* Using collection endpoints
34+
35+
Here are a couple examples, curl based
36+
37+
* Edit post with id 15, and add a new post
38+
39+
```
40+
curl --request POST \
41+
--url http://collections.3dev/api/posts/bulk \
42+
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
43+
--form '0[title]=edit existing post title for id 15' \
44+
--form '1[title]=this is a new post' \
45+
--form '0[id]=15'
46+
```
47+
48+
* Delete 2 entities with id's 14 and 15
49+
50+
```
51+
curl --request DELETE \
52+
--url http://collections.3dev/api/posts/bulk \
53+
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
54+
--form '1[id]=14' \
55+
--form '0[id]=15'
56+
```

docs/Documentation/crud.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ curl -i https://myapi.com/api/blogs?limit=1
6363
"name": "mark",
6464
"description": "",
6565
"created": null
66-
},
66+
}
6767
],
6868
"pagination": {
6969
"page": 1,
@@ -155,7 +155,7 @@ curl --data "description=Jorge best blog" https://myapi.com/api/blogs/25
155155
{
156156
"status": "error",
157157
"message": "A route matching \"\/blogs\/26\" could not be found.",
158-
"code": 404,
158+
"code": 404
159159
}
160160
```
161161

docs/home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Documentation
2121
* [Renderers](Documentation/renderers.md)
2222
* [Statuses](Documentation/status.md)
2323
* [Versioning](Documentation/versioning.md)
24+
* [Collections](Documentation/collections.md)
2425

2526

2627

src/Controller/ApiController.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

@@ -42,7 +42,7 @@ public function initialize()
4242
/**
4343
* Process api request
4444
*
45-
* @return \Cake\Http\Client\Response|\Cake\Network\Response|null
45+
* @return \Cake\Http\Client\Response|\Cake\Http\Response|null
4646
*/
4747
public function process()
4848
{
@@ -81,7 +81,7 @@ public function describe()
8181
* Process api request
8282
*
8383
* @param array $options Options
84-
* @return \Cake\Http\Client\Response|\Cake\Network\Response|null
84+
* @return \Cake\Http\Client\Response|\Cake\Http\Response|null
8585
*/
8686
protected function _process($options = [])
8787
{
@@ -95,8 +95,8 @@ protected function _process($options = [])
9595
}
9696

9797
$url = '/' . $service;
98-
if (!empty($this->request->params['pass'])) {
99-
$url .= '/' . join('/', $this->request->params['pass']);
98+
if (!empty($this->request->getParam('pass'))) {
99+
$url .= '/' . join('/', $this->request->getParam('pass'));
100100
}
101101
$options += [
102102
'version' => $version,
@@ -111,11 +111,9 @@ protected function _process($options = [])
111111

112112
return $Service->respond($result);
113113
}
114-
$this->response->statusCode(404);
115-
$this->response->body(__('Service not found'));
114+
$this->response = $this->response->withStringBody(__('Service not found'))->withStatus(404);
116115
} catch (Exception $e) {
117-
$this->response->statusCode(400);
118-
$this->response->body($e->getMessage());
116+
$this->response = $this->response->withStringBody($e->getMessage())->withStatus(400);
119117
}
120118

121119
return $this->response;

src/Controller/AppController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

src/Exception/MethodNotAllowedException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

src/Exception/ServiceException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

src/Exception/UnauthenticatedException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

@@ -29,7 +29,7 @@ class UnauthenticatedException extends Exception
2929
* @param int $code The code of the error
3030
* @param \Exception|null $previous the previous exception.
3131
*/
32-
public function __construct($message = null, $code = 403, $previous = null)
32+
public function __construct($message = null, $code = 401, $previous = null)
3333
{
3434
if (empty($message)) {
3535
$message = 'Unauthenticated';

src/Exception/UnauthorizedException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

@@ -28,7 +28,7 @@ class UnauthorizedException extends Exception
2828
* @param int $code The code of the error
2929
* @param \Exception|null $previous the previous exception.
3030
*/
31-
public function __construct($message = null, $code = 401, $previous = null)
31+
public function __construct($message = null, $code = 403, $previous = null)
3232
{
3333
if (empty($message)) {
3434
$message = 'Unauthorized';

src/Exception/ValidationException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/**
3-
* Copyright 2016, Cake Development Corporation (http://cakedc.com)
3+
* Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
44
*
55
* Licensed under The MIT License
66
* Redistributions of files must retain the above copyright notice.
77
*
8-
* @copyright Copyright 2016, Cake Development Corporation (http://cakedc.com)
8+
* @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
99
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1010
*/
1111

0 commit comments

Comments
 (0)