Compare commits
No commits in common. "prod" and "v0.0.1" have entirely different histories.
|
@ -2,7 +2,6 @@
|
||||||
/composer.phar
|
/composer.phar
|
||||||
/phpunit.xml
|
/phpunit.xml
|
||||||
/.phpunit.result.cache
|
/.phpunit.result.cache
|
||||||
/.phpunit.cache
|
|
||||||
/phpunit.phar
|
/phpunit.phar
|
||||||
/config/Migrations/schema-dump-default.lock
|
/config/Migrations/schema-dump-default.lock
|
||||||
/vendor/
|
/vendor/
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace CheeseCake\Controller\Traits;
|
|
||||||
|
|
||||||
use Cake\Core\Configure;
|
|
||||||
use Cake\ORM\Table;
|
|
||||||
use Cake\ORM\TableRegistry;
|
|
||||||
|
|
||||||
trait OverrideTableTrait
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This object's default table alias.
|
|
||||||
*
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
protected ?string $defaultTable = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected string $_tableConfigKey = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the table instance
|
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
|
||||||
public function getTable(string $tableName = null)
|
|
||||||
{
|
|
||||||
if ($this->_table instanceof Table) {
|
|
||||||
return $this->_table;
|
|
||||||
}
|
|
||||||
$this->getTableConfigKey();
|
|
||||||
$table = $tableName;
|
|
||||||
if (!isset($table)) {
|
|
||||||
$table = $this->defaultTable;
|
|
||||||
if (Configure::read($this->_tableConfigKey)) {
|
|
||||||
$table = Configure::read($this->_tableConfigKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->_table = TableRegistry::getTableLocator()->get($table);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getTableConfigKey()
|
|
||||||
{
|
|
||||||
if (!$this->_tableConfigKey) {
|
|
||||||
$this->_tableConfigKey = $this->getPlugin() . '.' . $this->defaultTable . '.table';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_tableConfigKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the users table
|
|
||||||
*
|
|
||||||
* @param Table $table table
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setTable(Table $table)
|
|
||||||
{
|
|
||||||
$this->_table = $table;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace CheeseCake\View\Helper;
|
|
||||||
|
|
||||||
use Cake\Log\Log;
|
|
||||||
use Cake\Routing\Router;
|
|
||||||
use Cake\View\Helper;
|
|
||||||
use Cake\View\View;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActiveLink helper
|
|
||||||
*/
|
|
||||||
class ActiveLinkHelper extends Helper
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Default configuration.
|
|
||||||
*
|
|
||||||
* @var array<string, mixed>
|
|
||||||
*/
|
|
||||||
protected array $_defaultConfig = [
|
|
||||||
'activeClass' => 'active',
|
|
||||||
];
|
|
||||||
/**
|
|
||||||
* List of helpers used by this helper
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected array $helpers = [
|
|
||||||
'Html',
|
|
||||||
'Url',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|string $title
|
|
||||||
* @param array|string|null $url
|
|
||||||
* @param array $options
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function link(array|string $title, array|string|null $url = null, array $options = []): string
|
|
||||||
{
|
|
||||||
$currentUrl = Router::parseRequest($this->getView()->getRequest());
|
|
||||||
if (!array_key_exists('target', $options) || !$currentUrl) {
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
$target = $options['target'];
|
|
||||||
unset($options['target']);
|
|
||||||
if (is_string($target)) {
|
|
||||||
return $this->_linkFromStringTarget($currentUrl, $target, $title, $url, $options);
|
|
||||||
}
|
|
||||||
if (!is_array($target)) {
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!array_key_exists('plugin', $currentUrl)) {
|
|
||||||
$currentUrl['plugin'] = false;
|
|
||||||
}
|
|
||||||
if (!array_key_exists('prefix', $currentUrl)) {
|
|
||||||
$currentUrl['prefix'] = false;
|
|
||||||
}
|
|
||||||
if (isset($target['or']) && $target['or']) {
|
|
||||||
foreach ($target['or'] as $singleTargetToMatch) {
|
|
||||||
if ($this->_matchesUrlFromArrayTarget($currentUrl, $singleTargetToMatch)) {
|
|
||||||
$options['class'] = $this->_addClass($options);
|
|
||||||
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->_matchesUrlFromArrayTarget($currentUrl, $target)) {
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$options['class'] = $this->_addClass($options);
|
|
||||||
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $providedOptions
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function _addClass(array $providedOptions): string
|
|
||||||
{
|
|
||||||
$activeClass = array_key_exists('activeClass', $providedOptions) ? $providedOptions['activeClass'] : $this->getConfig('activeClass');
|
|
||||||
|
|
||||||
return array_key_exists('class', $providedOptions) ? $providedOptions['class'] . ' ' . $activeClass : $activeClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _linkFromStringTarget(array $current, string $targetString, string $title, array|string|null $url, array $options)
|
|
||||||
{
|
|
||||||
if (Router::normalize($current) == Router::normalize($targetString)) {
|
|
||||||
$options['class'] = $this->_addClass($options);
|
|
||||||
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->Html->link($title, $url, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _matchesUrlFromArrayTarget(array $current, array $targetUrl)
|
|
||||||
{
|
|
||||||
foreach ($targetUrl as $targetKey => $targetValue) {
|
|
||||||
if (is_array($targetValue)) {
|
|
||||||
if (!in_array($current[$targetKey], $targetValue)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!array_key_exists($targetKey, $current) || $targetValue != $current[$targetKey]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,7 @@
|
||||||
<?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'button float-right']) ?>
|
<?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'button float-right']) ?>
|
||||||
{% set done = [] %}
|
{% set done = [] %}
|
||||||
<h3><?= __('{{ pluralHumanName }}') ?></h3>
|
<h3><?= __('{{ pluralHumanName }}') ?></h3>
|
||||||
<div class="table-responsive" id="table-container">
|
<div class="table-responsive">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace TestApp;
|
|
||||||
|
|
||||||
use Cake\Http\BaseApplication;
|
|
||||||
use Cake\Http\MiddlewareQueue;
|
|
||||||
use Cake\Routing\Middleware\RoutingMiddleware;
|
|
||||||
use Cake\Routing\Route\DashedRoute;
|
|
||||||
use Cake\Routing\RouteBuilder;
|
|
||||||
|
|
||||||
class Application extends BaseApplication {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Cake\Routing\RouteBuilder $routes
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function routes(RouteBuilder $routes): void {
|
|
||||||
$routes->scope('/', function(RouteBuilder $routes) {
|
|
||||||
$routes->fallbacks(DashedRoute::class);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to set in your App Class
|
|
||||||
* @return \Cake\Http\MiddlewareQueue
|
|
||||||
*/
|
|
||||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
|
|
||||||
$middlewareQueue->add(new RoutingMiddleware($this));
|
|
||||||
|
|
||||||
return $middlewareQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue