-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from TheMiller2015/cakephp-4.x
Cakephp 4.x
- Loading branch information
Showing
16 changed files
with
626 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,62 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
- 7.4 | ||
|
||
sudo: false | ||
services: | ||
- mysql | ||
- postgresql | ||
|
||
env: | ||
matrix: | ||
- DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' | ||
- DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test' | ||
- DB=pgsql db_dsn='postgres://[email protected]/cakephp_test' | ||
- DB=sqlite db_dsn='sqlite:///:memory:' | ||
|
||
global: | ||
- DEFAULT=1 | ||
|
||
matrix: | ||
allow_failures: | ||
- php: hhvm | ||
|
||
fast_finish: true | ||
|
||
include: | ||
- php: 5.6 | ||
- php: 7.2 | ||
env: PHPCS=1 DEFAULT=0 | ||
|
||
- php: 5.6 | ||
env: COVERALLS=1 DEFAULT=0 | ||
- php: 7.2 | ||
env: STATIC_ANALYSIS=1 DEFAULT=0 | ||
|
||
- php: hhvm | ||
env: HHVM=1 DB=sqlite db_dsn='sqlite:///:memory:' | ||
|
||
- php: hhvm | ||
env: HHVM=1 DB=mysql db_dsn='mysql://[email protected]/cakephp_test' | ||
- php: 7.2 | ||
env: PREFER_LOWEST=1 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
|
||
- sh -c "if [ '$DB' = 'mysql' ]; then if [ '$DOCKER' = '1' ]; then apt-get -qq install -qq -y mysql-server && service mysql start; fi; mysql -e 'CREATE DATABASE cakephp_test;'; fi" | ||
- if [[ $TRAVIS_PHP_VERSION != 7.4 ]]; then phpenv config-rm xdebug.ini; fi | ||
|
||
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi" | ||
- if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi | ||
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi | ||
|
||
- sh -c "if [ '$PHPCS' = '1' ]; then composer require 'cakephp/cakephp-codesniffer:dev-master'; fi" | ||
- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi | ||
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi | ||
|
||
- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev php-coveralls/php-coveralls; fi" | ||
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" | ||
|
||
- command -v phpenv > /dev/null && phpenv rehash || true | ||
- if [[ $STATIC_ANALYSIS = 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi | ||
|
||
script: | ||
- sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi" | ||
- sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/php-coveralls -v; fi" | ||
- sh -c "if [ '$DEFAULT' = '1' ]; then vendor/bin/phpunit ; fi" | ||
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=docs --ignore=tests/bootstrap.php . ; fi" | ||
|
||
- | | ||
if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.4 ]]; then | ||
mkdir -p build/logs | ||
vendor/bin/phpunit --coverage-clover=build/logs/clover.xml | ||
fi | ||
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.4 ]]; then vendor/bin/phpunit; fi | ||
|
||
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi | ||
|
||
after_success: | ||
- | | ||
if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then | ||
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar | ||
chmod +x php-coveralls.phar | ||
./php-coveralls.phar | ||
fi | ||
notifications: | ||
email: false | ||
|
||
addons: | ||
postgresql: "9.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Class EventListener | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Event | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
|
||
namespace Josegonzalez\Version\Event; | ||
|
||
use Cake\Event\Event as CakeEvent; | ||
use Cake\Event\EventListenerInterface; | ||
use Cake\Event\EventManagerTrait; | ||
|
||
/** | ||
* Class EventListener | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Event | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
abstract class EventListener implements EventListenerInterface | ||
{ | ||
use EventManagerTrait; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Class VersionListener | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Event | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
|
||
namespace Josegonzalez\Version\Event; | ||
|
||
use Cake\Datasource\ConnectionManager; | ||
use Cake\Event\Event; | ||
use Cake\ORM\TableRegistry; | ||
use Cake\Utility\Hash; | ||
|
||
/** | ||
* Class VersionListener | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Event | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
class VersionListener extends EventListener | ||
{ | ||
/** | ||
* Called before the entity template is rendered | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return void | ||
*/ | ||
public function beforeRenderEntity(Event $event) | ||
{ | ||
$this->_checkAssociation($event, 'versions'); | ||
$this->checkAssociation($event, 'versions'); | ||
} | ||
|
||
/** | ||
* Called before the test case template is rendered | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return void | ||
*/ | ||
public function beforeRenderTestCase(Event $event) | ||
|
@@ -39,22 +59,22 @@ public function beforeRenderTestCase(Event $event) | |
/** | ||
* Called before the table template is rendered | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return void | ||
*/ | ||
public function beforeRenderTable(Event $event) | ||
{ | ||
$this->_checkAssociation($event, 'versions'); | ||
$this->_fixVersionTables($event); | ||
$this->checkAssociation($event, 'versions'); | ||
$this->fixVersionTables($event); | ||
} | ||
|
||
/** | ||
* Removes unnecessary associations | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return void | ||
*/ | ||
protected function _fixVersionTables(Event $event) | ||
protected function fixVersionTables(Event $event) | ||
{ | ||
if (!preg_match('/Versions$/', $event->subject->viewVars['name'])) { | ||
return; | ||
|
@@ -71,11 +91,11 @@ protected function _fixVersionTables(Event $event) | |
/** | ||
* Attaches the behavior and modifies associations as necessary | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @param string $tableSuffix a suffix for the primary table | ||
* @return bool true if modified, false otherwise | ||
*/ | ||
protected function _checkAssociation(Event $event, $tableSuffix) | ||
protected function checkAssociation(Event $event, $tableSuffix) | ||
{ | ||
$subject = $event->subject; | ||
$connection = ConnectionManager::get($subject->viewVars['connection']); | ||
|
@@ -90,19 +110,19 @@ protected function _checkAssociation(Event $event, $tableSuffix) | |
sprintf("'versionTable' => '%s'", $versionTable), | ||
]; | ||
|
||
$event->subject->viewVars['associations']['belongsTo'] = $this->_modifyBelongsTo($event); | ||
$event->subject->viewVars['rulesChecker'] = $this->_modifyRulesChecker($event); | ||
$event->subject->viewVars['associations']['belongsTo'] = $this->modifyBelongsTo($event); | ||
$event->subject->viewVars['rulesChecker'] = $this->modifyRulesChecker($event); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Removes unnecessary belongsTo associations | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return array | ||
*/ | ||
protected function _modifyBelongsTo(Event $event) | ||
protected function modifyBelongsTo(Event $event) | ||
{ | ||
$belongsTo = $event->subject->viewVars['associations']['belongsTo']; | ||
|
||
|
@@ -120,10 +140,10 @@ protected function _modifyBelongsTo(Event $event) | |
/** | ||
* Removes unnecessary rulesChecker entries | ||
* | ||
* @param Event $event An Event instance | ||
* @param \Cake\Event\Event $event An Event instance | ||
* @return array | ||
*/ | ||
protected function _modifyRulesChecker(Event $event) | ||
protected function modifyRulesChecker(Event $event) | ||
{ | ||
$rulesChecker = $event->subject->viewVars['rulesChecker']; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Trait VersionTrait | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Model\Behavior\Version | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
|
||
namespace Josegonzalez\Version\Model\Behavior\Version; | ||
|
||
use Cake\Collection\Collection; | ||
use Cake\ORM\TableRegistry; | ||
|
||
/** | ||
* Trait VersionTrait | ||
* | ||
* @category CakePHP-Plugin | ||
* @package Josegonzalez\Version\Model\Behavior\Version | ||
* @author Jose Diaz-Gonzalez <[email protected]> | ||
* @license MIT License (https://github.com/josegonzalez/cakephp-version/blob/master/LICENSE.txt) | ||
* @link https://github.com/josegonzalez/cakephp-version | ||
*/ | ||
trait VersionTrait | ||
{ | ||
/** | ||
* Retrieves a specified version for the current entity | ||
* | ||
* @param int $versionId The version number to retrieve | ||
* @param bool $reset If true, will re-retrieve the related version collection | ||
* @param int $versionId The version number to retrieve | ||
* @param bool $reset If true, will re-retrieve the related version collection | ||
* @return \Cake\ORM\Entity|null | ||
*/ | ||
public function version($versionId, $reset = false) | ||
|
Oops, something went wrong.