Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
"type": "project",
"license": "MIT",
"require": {
"php": ">=7.2",
"cakephp/cakephp": "^4.0",
"cakephp/migrations": "~3.0",
"cakephp/authorization": "~2.0",
"cakephp/authentication": "~2.0",
"cakephp/plugin-installer": "~1.0",
"php": ">=8.1",
"cakephp/cakephp": "^5.0",
"cakephp/migrations": "~4.0",
"cakephp/authorization": "~3.0",
"cakephp/authentication": "~3.0",
"cakephp/plugin-installer": "~2.0",
"josegonzalez/dotenv": "2.*"
},
"require-dev": {
"psy/psysh": "@stable",
"cakephp/debug_kit": "^4.0",
"cakephp/bake": "^2.0",
"cakephp/cakephp-codesniffer": "^4.0"
"cakephp/debug_kit": "^5.0",
"cakephp/bake": "^3.0",
"cakephp/repl": "^2.0",
"cakephp/cakephp-codesniffer": "^5.0"
},
"suggest": {
"markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
Expand All @@ -39,7 +40,6 @@
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
"check": [
"@test",
"@cs-check"
Expand All @@ -50,5 +50,11 @@
"test": "phpunit --colors=always"
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"cakephp/plugin-installer": true
}
}
}
1,449 changes: 786 additions & 663 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
declare(strict_types=1);

use Cake\Cache\Engine\FileEngine;
use Cake\Database\Connection;
use Cake\Database\Driver\Mysql;
use Cake\Error\ExceptionRenderer;
use Cake\Log\Engine\FileLog;
use Cake\Mailer\Transport\MailTransport;
use function Cake\Core\env;

return [
/*
Expand All @@ -17,7 +19,7 @@
* Development Mode:
* true: Errors and warnings shown.
*/
'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),
'debug' => true, //filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),

/*
* Configure basic information about the application.
Expand Down
3 changes: 3 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
use Cake\Routing\Router;
use Cake\Utility\Security;

require_once CAKE . 'Core/functions_global.php';
require_once CAKE . 'I18n/functions_global.php';

/*
* See https://github.com/josegonzalez/php-dotenv for API details.
*
Expand Down
10 changes: 1 addition & 9 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public function bootstrap(): void
}
$this->addPlugin('Authentication');
$this->addPlugin('Authorization');

// Load more plugins here
}

/**
Expand Down Expand Up @@ -114,13 +112,7 @@ public function middleware($middlewareQueue): \Cake\Http\MiddlewareQueue
->add(new AuthorizationMiddleware($this));

if (Configure::read('debug')) {
// Disable authz for debugkit
$middlewareQueue->add(function ($req, $res, $next) {
if ($req->getParam('plugin') === 'DebugKit') {
$req->getAttribute('authorization')->skipAuthorization();
}
return $next($req, $res);
});
Configure::write('DebugKit.ignoreAuthorization', true);
}

return $middlewareQueue;
Expand Down
86 changes: 0 additions & 86 deletions src/Command/ConsoleCommand.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class AppController extends Controller
public function initialize(): void
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Authentication.Authentication');
$this->loadComponent('Authorization.Authorization');
Expand Down
10 changes: 2 additions & 8 deletions src/Controller/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,12 @@ public function delete($slug)
}
}

public function tags()
public function tags(array $tags = [])
{
$this->Authorization->skipAuthorization();

// The 'pass' key is provided by CakePHP and contains all
// the passed URL path segments in the request.
$tags = $this->request->getParam('pass');

// Use the ArticlesTable to find tagged articles.
$articles = $this->Articles->find('tagged', [
'tags' => $tags
]);
$articles = $this->Articles->find('tagged', tags: $tags);

// Pass variables into the view template context.
$this->set([
Expand Down
10 changes: 0 additions & 10 deletions src/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
*/
class ErrorController extends AppController
{
/**
* Initialization hook method.
*
* @return void
*/
public function initialize(): void
{
$this->loadComponent('RequestHandler');
}

/**
* beforeFilter callback.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
namespace App\Controller;

use Cake\Core\Configure;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\NotFoundException;
use Cake\Http\Exception\ForbiddenException;
use Cake\Http\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Controller/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public function index()
*/
public function view($id = null)
{
$tag = $this->Tags->get($id, [
'contain' => ['Articles'],
]);
$tag = $this->Tags->get($id, contain: ['Articles']);

$this->set(compact('tag'));
}
Expand Down Expand Up @@ -69,9 +67,7 @@ public function add()
*/
public function edit($id = null)
{
$tag = $this->Tags->get($id, [
'contain' => ['Articles'],
]);
$tag = $this->Tags->get($id, contain: ['Articles']);
if ($this->request->is(['patch', 'post', 'put'])) {
$tag = $this->Tags->patchEntity($tag, $this->request->getData());
if ($this->Tags->save($tag)) {
Expand Down
8 changes: 2 additions & 6 deletions src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function logout()
*/
public function view($id = null)
{
$user = $this->Users->get($id, [
'contain' => ['Articles']
]);
$user = $this->Users->get($id, contain: ['Articles']);

$this->set('user', $user);
$this->set('_serialize', ['user']);
Expand Down Expand Up @@ -115,9 +113,7 @@ public function add()
*/
public function edit($id = null)
{
$user = $this->Users->get($id, [
'contain' => []
]);
$user = $this->Users->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
Expand Down
32 changes: 29 additions & 3 deletions src/Model/Entity/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace App\Model\Entity;

use Cake\Collection\Collection;
use Cake\ORM\Entity;
use Cake\Utility\Text;

/**
* Article Entity
Expand All @@ -14,8 +16,8 @@
* @property string $slug
* @property string|null $body
* @property bool|null $published
* @property \Cake\I18n\FrozenTime|null $created
* @property \Cake\I18n\FrozenTime|null $modified
* @property \Cake\I18n\DateTime|null $created
* @property \Cake\I18n\DateTime|null $modified
*
* @property \App\Model\Entity\User $user
* @property \App\Model\Entity\Tag[] $tags
Expand All @@ -31,7 +33,7 @@ class Article extends Entity
*
* @var array
*/
protected $_accessible = [
protected array $_accessible = [
'user_id' => true,
'title' => true,
'slug' => true,
Expand All @@ -41,5 +43,29 @@ class Article extends Entity
'modified' => true,
'user' => true,
'tags' => true,
'tag_string' => true,
];

protected function _setTitle(string $title): string
{
$this->slug = Text::slug($title);

return $title;
}

protected function _getTagString(): string
{
if (isset($this->_fields['tag_string'])) {
return $this->_fields['tag_string'];
}
if (empty($this->tags)) {
return '';
}
$tags = new Collection($this->tags);
$str = $tags->reduce(function ($string, $tag) {
return $string . $tag->title . ', ';
}, '');

return trim($str, ', ');
}
}
2 changes: 1 addition & 1 deletion src/Model/Entity/ArticlesTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ArticlesTag extends Entity
*
* @var array
*/
protected $_accessible = [
protected array $_accessible = [
'article' => true,
'tag' => true,
];
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*
* @property int $id
* @property string|null $title
* @property \Cake\I18n\FrozenTime|null $created
* @property \Cake\I18n\FrozenTime|null $modified
* @property \Cake\I18n\DateTime|null $created
* @property \Cake\I18n\DateTime|null $modified
*
* @property \App\Model\Entity\Article[] $articles
*/
Expand All @@ -26,7 +26,7 @@ class Tag extends Entity
*
* @var array
*/
protected $_accessible = [
protected array $_accessible = [
'title' => true,
'created' => true,
'modified' => true,
Expand Down
Loading