Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init Cake5 upgrade. #136

Merged
merged 14 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.stickler.yml export-ignore
.travis.yml export-ignore
phpcs.xml.dist export-ignore
phpcs.xml export-ignore
phpstan.neon export-ignore
phpstan-baseline.neon export-ignore
phpunit.xml.dist export-ignore
Expand Down
102 changes: 8 additions & 94 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,19 @@ on:
push:
branches:
- 4.x
- 5.x
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
testsuite:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.2']
prefer-lowest: ['']
include:
- php-version: '7.4'
prefer-lowest: 'prefer-lowest'

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer Install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
fi

- name: Configure PHPUnit matcher
if: matrix.php-version == '7.4'
uses: mheap/phpunit-matcher-action@main

- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Submit code coverage
if: success() && matrix.php-version == '7.4'
uses: codecov/codecov-action@v3
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: composer stan-setup

- name: Run PHP CodeSniffer
run: composer cs-check

- name: Run phpstan
if: success() || failure()
run: vendor/bin/phpstan analyse --error-format=github
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit
10 changes: 0 additions & 10 deletions .stickler.yml

This file was deleted.

18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Quickly enable CSV output of your model data.

This branch is for CakePHP **4.x**. For details see [version map](https://github.com/FriendsOfCake/cakephp-csvview/wiki#cakephp-version-map).
This branch is for CakePHP **5.x**. For details see [version map](https://github.com/FriendsOfCake/cakephp-csvview/wiki#cakephp-version-map).

## Background

Expand Down Expand Up @@ -182,18 +182,20 @@ to set how null values should be displayed in the CSV.

#### Automatic view class switching

You can use router's extension parsing feature and the `RequestHandlerComponent` to
automatically have the CsvView class switched in as follows.
You can use the controller's content negotiation feature to automatically have
the CsvView class switched in as follows.

Enable `csv` extension parsing for all routes using `Router::extensions('csv')`
in your app's `routes.php` or using `$routes->addExtensions()` within required
scope.
Enable `csv` extension parsing using `$routes->addExtensions(['csv'])` within required
scope in your app's `routes.php`.

```php
// PostsController.php

// In your controller's initialize() method:
$this->loadComponent('RequestHandler');
// Override the viewClasses method of your controller:
public function viewClasses()
{
return ['csv' => 'CsvView.Csv'];
}

// Controller action
public function index()
Expand Down
34 changes: 18 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@
"role": "Maintainer"
},
{
"name":"ADmad",
"role":"Contributor",
"name": "ADmad",
"role": "Contributor",
"homepage": "https://github.com/admad"
},
{
"name":"Mark Scherer",
"role":"Contributor",
"name": "Mark Scherer",
"role": "Contributor",
"homepage": "https://github.com/dereuromark"
},
{
"name":"Joshua Paling",
"role":"Contributor",
"name": "Joshua Paling",
"role": "Contributor",
"homepage": "https://github.com/joshuapaling"
},
{
"name":"Gaurish Sharma",
"role":"Contributor",
"name": "Gaurish Sharma",
"role": "Contributor",
"homepage": "https://github.com/gaurish"
},
{
"name":"Gregory Gaskill",
"role":"Contributor",
"homepage":"https://github.com/chronon"
"name": "Gregory Gaskill",
"role": "Contributor",
"homepage": "https://github.com/chronon"
}
],
"require":{
"php": ">=7.4",
"cakephp/cakephp": "^4.2"
"require": {
"php": ">=8.1",
"cakephp/cakephp": "5.x-dev"
},
"require-dev": {
"phpunit/phpunit": "^9.5.0",
"cakephp/cakephp-codesniffer": "^4.0"
"cakephp/cakephp-codesniffer": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -85,5 +85,7 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Bake">
<ruleset name="CsvView">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
<arg value="nps"/>
<arg value="s"/>
dereuromark marked this conversation as resolved.
Show resolved Hide resolved

<file>src/</file>
<file>tests/</file>
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
bootstrapFiles:
Expand Down
29 changes: 11 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
bootstrap="tests/bootstrap.php"
>
<phpunit bootstrap="tests/bootstrap.php" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<!-- Add any additional test suites you want to run here -->
<testsuites>
Expand All @@ -12,21 +9,17 @@
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>
<extensions>
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension"/>
</extensions>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src/</directory>
<exclude>
<file>src/Plugin.php</file>
</exclude>
</whitelist>
</filter>
</include>
</coverage>

<php>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
</php>
</phpunit>
22 changes: 4 additions & 18 deletions src/Plugin.php → src/CsvViewPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,36 @@

use Cake\Core\BasePlugin;
use Cake\Core\PluginApplicationInterface;
use Cake\Event\EventInterface;
use Cake\Event\EventManager;
use Cake\Http\ServerRequest;

class Plugin extends BasePlugin
class CsvViewPlugin extends BasePlugin
{
/**
* Plugin name.
*
* @var string
*/
protected $name = 'CsvView';
protected ?string $name = 'CsvView';

/**
* Load routes or not
*
* @var bool
*/
protected $routesEnabled = false;
protected bool $routesEnabled = false;

/**
* Console middleware
*
* @var bool
*/
protected $consoleEnabled = false;
protected bool $consoleEnabled = false;

/**
* @inheritDoc
*/
public function bootstrap(PluginApplicationInterface $app): void
{
/**
* Add CsvView to View class map through RequestHandler, if available, on Controller initialisation
*
* @link https://book.cakephp.org/4/en/controllers/components/request-handling.html#using-custom-viewclasses
*/
EventManager::instance()->on('Controller.initialize', function (EventInterface $event) {
$controller = $event->getSubject();
if ($controller->components()->has('RequestHandler')) {
$controller->RequestHandler->setConfig('viewClassMap.csv', 'CsvView.Csv');
}
});

/**
* Add a request detector named "csv" to check whether the request was for a CSV,
* either through accept header or file extension
Expand Down
Loading