Skip to content

Commit

Permalink
Merge pull request #2 from the-kbA-team/1-build-cakephp-5-version
Browse files Browse the repository at this point in the history
1 build cakephp 5 version
  • Loading branch information
tigerduck42 authored Aug 21, 2024
2 parents 4a01234 + 4ba2f3c commit e8f8d0a
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 76 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.github export-ignore
composer.* export-ignore
phpunit.* export-ignore
phpstan.neon export-ignore
phpstan_classes.php export-ignore
README.md export-ignore
73 changes: 73 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events
push:
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Composer config validation
composer:
name: "Composer config validation"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: "Validate composer.json"
run: "composer validate --strict"

# PHP syntax validation
php:
name: "PHP syntax validation"
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.1, 8.2, 8.3 ]
steps:
- uses: "actions/checkout@v3"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php_version }}"

- name: "Check PHP syntax of package"
run: |
php -l src/
php -l tests/
phpunit:
name: "PHPUnit tests"
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.1, 8.2, 8.3 ]
steps:
- uses: "actions/checkout@v3"
- uses: "php-actions/composer@v6"
with:
php_version: "${{ matrix.php_version }}"
php_extensions: intl
- run: "vendor/bin/phpunit"

# phpstan for several php versions
phpstan:
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.1, 8.2, 8.3 ]
steps:
- uses: "actions/checkout@v3"
- uses: "php-actions/composer@v6"
with:
php_version: "${{ matrix.php_version }}"
php_extensions: intl
- name: "PHPStan Static Analysis"
uses: "php-actions/phpstan@v3"
with:
php_version: "${{ matrix.php_version }}"
configuration: "phpstan.neon"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/composer.lock
/phpunit.xml
/vendor
/.phpunit.result.cache
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "maiconpinto/cakephp-adminlte-theme",
"description": "CakePHP 4.x AdminLTE Theme.",
"name": "kba-team/cakephp-adminlte-theme",
"description": "CakePHP 5.x AdminLTE Theme.",
"type": "cakephp-plugin",
"keywords": ["cakephp", "templates", "plugin"],
"homepage": "https://github.com/maiconpinto/cakephp-adminlte-theme",
"homepage": "https://github.com/the-kbA-team/cakephp-adminlte-theme",
"license": "MIT",
"authors": [
{
Expand All @@ -14,19 +14,19 @@
}
],
"require": {
"php": ">=7.2.0",
"cakephp/cakephp": "^4.0"
"php": ">=8.1",
"cakephp/cakephp": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "~8.5.0"
"phpunit/phpunit": "^10.1.0"
},
"autoload": {
"psr-4": {
"AdminLTE\\": "src"
}
},
"support": {
"issues": "https://github.com/maiconpinto/cakephp-adminlte-theme/issues",
"source": "https://github.com/maiconpinto/cakephp-adminlte-theme"
"issues": "https://github.com/the-kbA-team/cakephp-adminlte-theme/issues",
"source": "https://github.com/the-kbA-team/cakephp-adminlte-theme"
}
}
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 9
checkGenericClassInNonGenericObjectType: false
bootstrapFiles:
- phpstan_classes.php
paths:
- src/
- tests/
29 changes: 29 additions & 0 deletions phpstan_classes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace App\View;

use Cake\View\View;


define('ROOT', "");
/**
* Application View
*
* Your application's default view class
*
* @link https://book.cakephp.org/3.0/en/views.html#the-app-view
*/
class AppView extends View
{
}
48 changes: 23 additions & 25 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="AdminLTE">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
cacheResult="false"
cacheDirectory=".phpunit.cache"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="AdminLTE">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
</phpunit>
21 changes: 12 additions & 9 deletions src/Model/Behavior/DatepickerBehavior.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace AdminLTE\Model\Behavior;

use \Cake\ORM\Behavior;
Expand All @@ -10,9 +11,9 @@
class DatepickerBehavior extends Behavior
{
/**
* @var array
* @var array<string, mixed>
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'fields' => [],
'date_separator' => '/',
];
Expand All @@ -22,9 +23,10 @@ class DatepickerBehavior extends Behavior
* also adds and merges config settings (direct + configure)
*
* @param \Cake\ORM\Table $table
* @param array $config
* @param array<string, mixed> $config
*/
public function __construct(Table $table, array $config = []) {
public function __construct(Table $table, array $config = [])
{
$config += $this->_defaultConfig;
parent::__construct($table, $config);
}
Expand All @@ -37,20 +39,21 @@ public function __construct(Table $table, array $config = []) {
* @param \ArrayObject $options
* @return void
*/
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) {
if (!empty($this->_config) && !empty($this->_config['fields'])) {
$separator = $this->_config['date_separator'] ? : '/';
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
{
if (!empty($this->_config) && !empty($this->_config['fields']) && is_array($this->_config['fields'])) {
$separator = is_string($this->_config['date_separator']) && !empty($this->_config['date_separator']) ? $this->_config['date_separator'] : '/';
$locale = Configure::read('App.defaultLocale');

foreach ($this->_config['fields'] as $key) {
if (isset($data[$key])) {
if (isset($data[$key]) && is_string($data[$key])) {
if ($locale == 'pt_BR') {
list($d, $m, $y) = explode($separator, $data[$key]);
} else {
list($m, $d, $y) = explode($separator, $data[$key]);
}

$data[$key] = $y .'-'. $m .'-'. $d;
$data[$key] = $y . '-' . $m . '-' . $d;
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/View/AdminLTEView.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace AdminLTE\View;

use \App\View\AppView;
Expand All @@ -9,30 +10,31 @@ class AdminLTEView extends AppView
{
protected function _paths(?string $plugin = NULL, bool $cached = true): array
{
$prefix = $this->request->getParam('prefix') ? Inflector::camelize($this->request->getParam('prefix')) : false;
$prefix = is_string($this->request->getParam('prefix')) ? Inflector::camelize($this->request->getParam('prefix')) : false;
$theme = $this->theme;

$templatePaths = App::path(static::NAME_TEMPLATE);

$pluginPaths = [];
$themePaths = [];

foreach ($templatePaths as $templateCurrent) {
if (!empty($theme)) {
if (!empty($plugin)) {
for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
if ($prefix) {
$pluginPaths[] = $templatePaths[$i] . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR;
$pluginPaths[] = $templatePaths[$i] . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR;
}

$pluginPaths[] = $templatePaths[$i] . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
$pluginPaths[] = $templatePaths[$i] . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
}
}

if ($prefix) {
$themePaths[] = $templateCurrent . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR;
$themePaths[] = $templateCurrent . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR;
}

$themePaths[] = $templateCurrent . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR;
$themePaths[] = $templateCurrent . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR;
}
}

Expand Down
Loading

0 comments on commit e8f8d0a

Please sign in to comment.