Skip to content

Commit 6076271

Browse files
committed
Starting to update to 4.4
1 parent de52810 commit 6076271

22 files changed

Lines changed: 1952 additions & 1240 deletions

‎composer.lock‎

Lines changed: 1459 additions & 787 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/bootstrap.php‎

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
use Cake\Core\Configure;
3636
use Cake\Core\Configure\Engine\PhpConfig;
3737
use Cake\Datasource\ConnectionManager;
38-
use Cake\Error\ConsoleErrorHandler;
39-
use Cake\Error\ErrorHandler;
38+
use Cake\Error\ErrorTrap;
39+
use Cake\Error\ExceptionTrap;
4040
use Cake\Http\ServerRequest;
4141
use Cake\Log\Log;
4242
use Cake\Mailer\Mailer;
@@ -120,17 +120,13 @@
120120
/*
121121
* Register application error and exception handlers.
122122
*/
123-
$isCli = PHP_SAPI === 'cli';
124-
if ($isCli) {
125-
(new ConsoleErrorHandler(Configure::read('Error')))->register();
126-
} else {
127-
(new ErrorHandler(Configure::read('Error')))->register();
128-
}
123+
(new ErrorTrap())->register();
124+
(new ExceptionTrap())->register();
129125

130126
/*
131127
* Include the CLI bootstrap overrides.
132128
*/
133-
if ($isCli) {
129+
if (PHP_SAPI == 'cli') {
134130
require __DIR__ . '/bootstrap_cli.php';
135131
}
136132

@@ -176,40 +172,3 @@
176172

177173
return $detector->isTablet();
178174
});
179-
180-
/*
181-
* You can set whether the ORM uses immutable or mutable Time types.
182-
* The default changed in 4.0 to immutable types. You can uncomment
183-
* below to switch back to mutable types.
184-
*
185-
* You can enable default locale format parsing by adding calls
186-
* to `useLocaleParser()`. This enables the automatic conversion of
187-
* locale specific date formats. For details see
188-
* @link https://book.cakephp.org/4/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
189-
*/
190-
// TypeFactory::build('time')
191-
// ->useMutable();
192-
// TypeFactory::build('date')
193-
// ->useMutable();
194-
// TypeFactory::build('datetime')
195-
// ->useMutable();
196-
// TypeFactory::build('timestamp')
197-
// ->useMutable();
198-
// TypeFactory::build('datetimefractional')
199-
// ->useMutable();
200-
// TypeFactory::build('timestampfractional')
201-
// ->useMutable();
202-
// TypeFactory::build('datetimetimezone')
203-
// ->useMutable();
204-
// TypeFactory::build('timestamptimezone')
205-
// ->useMutable();
206-
207-
/*
208-
* Custom Inflector rules, can be set to correctly pluralize or singularize
209-
* table, model, controller names or whatever other string is passed to the
210-
* inflection functions.
211-
*/
212-
//Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
213-
//Inflector::rules('irregular', ['red' => 'redlings']);
214-
//Inflector::rules('uninflected', ['dontinflectme']);
215-
//Inflector::rules('transliteration', ['/å/' => 'aa']);

‎config/routes.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
Router::defaultRouteClass(DashedRoute::class);
4545

46-
Router::scope('/', function (RouteBuilder $routes) {
46+
$routes->scope('/', function (RouteBuilder $routes) {
4747
// Register scoped middleware for in scopes.
4848
$routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
4949
'httponly' => true

‎phpcs.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4+
5+
<rule ref="CakePHP" />
6+
7+
<!-- Necessary for class aliases used for backwards compat -->
8+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
9+
<severity>0</severity>
10+
</rule>
11+
12+
<file>./src</file>
13+
<file>./tests</file>
14+
15+
<arg name="extensions" value="php"/>
16+
</ruleset>

‎src/Application.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Cake\Http\BaseApplication;
3030
use Cake\Routing\Middleware\AssetMiddleware;
3131
use Cake\Routing\Middleware\RoutingMiddleware;
32+
use Cake\Routing\Router;
3233

3334
/**
3435
* Application setup class.
@@ -128,7 +129,7 @@ public function middleware($middlewareQueue): \Cake\Http\MiddlewareQueue
128129
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
129130
{
130131
$authenticationService = new AuthenticationService([
131-
'unauthenticatedRedirect' => '/users/login',
132+
'unauthenticatedRedirect' => Router::url('/users/login'),
132133
'queryParam' => 'redirect',
133134
]);
134135

@@ -137,7 +138,7 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
137138
'fields' => [
138139
'username' => 'email',
139140
'password' => 'password',
140-
]
141+
],
141142
]);
142143

143144
// Load the authenticators, you want session first

‎src/Controller/TagsController.php‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,52 @@
11
<?php
2-
namespace App\Controller;
2+
declare(strict_types=1);
33

4-
use App\Controller\AppController;
4+
namespace App\Controller;
55

66
/**
77
* Tags Controller
88
*
99
* @property \App\Model\Table\TagsTable $Tags
10-
*
11-
* @method \App\Model\Entity\Tag[] paginate($object = null, array $settings = [])
10+
* @method \App\Model\Entity\Tag[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
1211
*/
1312
class TagsController extends AppController
1413
{
15-
1614
/**
1715
* Index method
1816
*
19-
* @return \Cake\Http\Response|void
17+
* @return \Cake\Http\Response|null|void Renders view
2018
*/
2119
public function index()
2220
{
2321
$tags = $this->paginate($this->Tags);
2422

2523
$this->set(compact('tags'));
26-
$this->set('_serialize', ['tags']);
2724
}
2825

2926
/**
3027
* View method
3128
*
3229
* @param string|null $id Tag id.
33-
* @return \Cake\Http\Response|void
30+
* @return \Cake\Http\Response|null|void Renders view
3431
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
3532
*/
3633
public function view($id = null)
3734
{
3835
$tag = $this->Tags->get($id, [
39-
'contain' => ['Articles']
36+
'contain' => ['Articles'],
4037
]);
4138

42-
$this->set('tag', $tag);
43-
$this->set('_serialize', ['tag']);
39+
$this->set(compact('tag'));
4440
}
4541

4642
/**
4743
* Add method
4844
*
49-
* @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
45+
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
5046
*/
5147
public function add()
5248
{
53-
$tag = $this->Tags->newEntity();
49+
$tag = $this->Tags->newEmptyEntity();
5450
if ($this->request->is('post')) {
5551
$tag = $this->Tags->patchEntity($tag, $this->request->getData());
5652
if ($this->Tags->save($tag)) {
@@ -62,20 +58,19 @@ public function add()
6258
}
6359
$articles = $this->Tags->Articles->find('list', ['limit' => 200]);
6460
$this->set(compact('tag', 'articles'));
65-
$this->set('_serialize', ['tag']);
6661
}
6762

6863
/**
6964
* Edit method
7065
*
7166
* @param string|null $id Tag id.
72-
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
73-
* @throws \Cake\Network\Exception\NotFoundException When record not found.
67+
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
68+
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
7469
*/
7570
public function edit($id = null)
7671
{
7772
$tag = $this->Tags->get($id, [
78-
'contain' => ['Articles']
73+
'contain' => ['Articles'],
7974
]);
8075
if ($this->request->is(['patch', 'post', 'put'])) {
8176
$tag = $this->Tags->patchEntity($tag, $this->request->getData());
@@ -88,14 +83,13 @@ public function edit($id = null)
8883
}
8984
$articles = $this->Tags->Articles->find('list', ['limit' => 200]);
9085
$this->set(compact('tag', 'articles'));
91-
$this->set('_serialize', ['tag']);
9286
}
9387

9488
/**
9589
* Delete method
9690
*
9791
* @param string|null $id Tag id.
98-
* @return \Cake\Http\Response|null Redirects to index.
92+
* @return \Cake\Http\Response|null|void Redirects to index.
9993
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
10094
*/
10195
public function delete($id = null)

‎src/Model/Entity/Article.php‎

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
<?php
2-
// src/Model/Entity/Article.php
2+
declare(strict_types=1);
3+
34
namespace App\Model\Entity;
45

5-
use Cake\Collection\Collection;
66
use Cake\ORM\Entity;
77

8+
/**
9+
* Article Entity
10+
*
11+
* @property int $id
12+
* @property int $user_id
13+
* @property string $title
14+
* @property string $slug
15+
* @property string|null $body
16+
* @property bool|null $published
17+
* @property \Cake\I18n\FrozenTime|null $created
18+
* @property \Cake\I18n\FrozenTime|null $modified
19+
*
20+
* @property \App\Model\Entity\User $user
21+
* @property \App\Model\Entity\Tag[] $tags
22+
*/
823
class Article extends Entity
924
{
25+
/**
26+
* Fields that can be mass assigned using newEntity() or patchEntity().
27+
*
28+
* Note that when '*' is set to true, this allows all unspecified fields to
29+
* be mass assigned. For security purposes, it is advised to set '*' to false
30+
* (or remove it), and explicitly make individual fields accessible as needed.
31+
*
32+
* @var array
33+
*/
1034
protected $_accessible = [
11-
'*' => true,
12-
'id' => false,
13-
'slug' => false,
35+
'user_id' => true,
36+
'title' => true,
37+
'slug' => true,
38+
'body' => true,
39+
'published' => true,
40+
'created' => true,
41+
'modified' => true,
42+
'user' => true,
43+
'tags' => true,
1444
];
15-
16-
protected function _getTagString()
17-
{
18-
if (isset($this->_fields['tag_string'])) {
19-
return $this->_fields['tag_string'];
20-
}
21-
if (empty($this->tags)) {
22-
return '';
23-
}
24-
$tags = new Collection($this->tags);
25-
$str = $tags->reduce(function ($string, $tag) {
26-
return $string . $tag->title . ', ';
27-
}, '');
28-
return trim($str, ', ');
29-
}
3045
}

‎src/Model/Entity/ArticlesTag.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Model\Entity;
5+
6+
use Cake\ORM\Entity;
7+
8+
/**
9+
* ArticlesTag Entity
10+
*
11+
* @property int $article_id
12+
* @property int $tag_id
13+
*
14+
* @property \App\Model\Entity\Article $article
15+
* @property \App\Model\Entity\Tag $tag
16+
*/
17+
class ArticlesTag extends Entity
18+
{
19+
/**
20+
* Fields that can be mass assigned using newEntity() or patchEntity().
21+
*
22+
* Note that when '*' is set to true, this allows all unspecified fields to
23+
* be mass assigned. For security purposes, it is advised to set '*' to false
24+
* (or remove it), and explicitly make individual fields accessible as needed.
25+
*
26+
* @var array
27+
*/
28+
protected $_accessible = [
29+
'article' => true,
30+
'tag' => true,
31+
];
32+
}

‎src/Model/Entity/Tag.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace App\Model\Entity;
35

46
use Cake\ORM\Entity;
@@ -7,15 +9,14 @@
79
* Tag Entity
810
*
911
* @property int $id
10-
* @property string $title
11-
* @property \Cake\I18n\FrozenTime $created
12-
* @property \Cake\I18n\FrozenTime $modified
12+
* @property string|null $title
13+
* @property \Cake\I18n\FrozenTime|null $created
14+
* @property \Cake\I18n\FrozenTime|null $modified
1315
*
1416
* @property \App\Model\Entity\Article[] $articles
1517
*/
1618
class Tag extends Entity
1719
{
18-
1920
/**
2021
* Fields that can be mass assigned using newEntity() or patchEntity().
2122
*
@@ -26,7 +27,9 @@ class Tag extends Entity
2627
* @var array
2728
*/
2829
protected $_accessible = [
29-
'*' => true,
30-
'id' => false
30+
'title' => true,
31+
'created' => true,
32+
'modified' => true,
33+
'articles' => true,
3134
];
3235
}

0 commit comments

Comments
 (0)