Skip to content
Closed

5.x #35

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
20 changes: 8 additions & 12 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ jobs:
strategy:
matrix:
php-version:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'

symfony-version:
- '5.3'
- '5.4'
- '6.0'
- '6.4'
- '7.3'

exclude:
- php-version: 7.3
symfony-version: 6.0
- php-version: 7.4
symfony-version: 6.0
- { php-version: 8.1, symfony-version: 7.3 }

name: PHP ${{ matrix.php-version }} and Symfony ${{ matrix.symfony-version }}
steps:
Expand All @@ -39,15 +35,15 @@ jobs:
- id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Update Symfony version
run: |
sed -i composer.json -e 's/\^5\.0\(.[0-9]\+\)\?[|]\^6\.0/${{ matrix.symfony-version }}.*/g'
sed -i composer.json -e 's/\^5.3[|]\^6.0[|]\^7.0/${{ matrix.symfony-version }}.*/g'

- run: composer install

Expand Down
105 changes: 105 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Agate Apps package.
*
* (c) Alexandre Rock Ancelet <pierstoval@gmail.com> and Studio Agate.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$header = <<<'HEADER'
This file is part of the OrbitaleCmsBundle package.

(c) Alexandre Rock Ancelet <alex@orbitale.io>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
HEADER;

$finder = PhpCsFixer\Finder::create()
->exclude([
'.idea/',
'build/',
'vendor',
])
->in([
__DIR__.'/Controller/',
__DIR__.'/DependencyInjection/',
__DIR__.'/Entity/',
__DIR__.'/EventListener/',
__DIR__.'/Repository/',
__DIR__.'/Resources/',
__DIR__.'/templates/',
__DIR__.'/Tests/',
__DIR__.'/Twig/',
])
->files([
__DIR__.'/OrbitaleCmsBundle.php',
])
;

return (new PhpCsFixer\Config())
->setRules([
'header_comment' => [
'header' => $header,
],
// Enabled rules
'@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PhpCsFixer' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHP73Migration' => true,
'compact_nullable_typehint' => true,
'fully_qualified_strict_types' => true,
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'logical_operators' => true,
'native_function_invocation' => [
'include' => ['@all'],
'exclude' => ['uuid_create'],
],
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'echo_tag_syntax' => ['format' => 'long'],
'no_superfluous_phpdoc_tags' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'simplified_null_return' => true,
'strict_param' => true,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'static',
],
'array_syntax' => [
'syntax' => 'short',
],
// Overrides default doctrine rule using ":" as character
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'new_line_for_chained_calls',
],

// Disabled rules
'mb_str_functions' => false, // When we know the input, it's okay to not use mb_, because it's less performant
'increment_style' => false, // Because "++$i" is not always necessary…
'non_printable_character' => false, // Because I love using non breakable spaces in test methods ♥
'php_unit_test_class_requires_covers' => false, // Because we don't use @covers
'php_unit_internal_class' => false, // Why would this be necessary?
'heredoc_indentation' => false, // Well, it breaks the "visual" aspects of some strings...
])
->setRiskyAllowed(true)
->setIndent(' ')
->setLineEnding("\n")
->setUsingCache(true)
->setFinder($finder)
;
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#v4.1.0
# v5.0.0

* Add support for Symfony 7.
* Drop support for Symfony 5, support starts at Symfony 6.4 now.
* Drop support for PHP 7 and 8.0, support starts at PHP 8.1 now.
* Base entities mapping is now in XML instead of annotations/attributes.
* Base entities validations rules are now in XML instead of annotations/attributes.
* Fix some PHP deprecations in types.
* Tests: revamp setup a bit, for modernisation.
* Dev: add CS fix setup

# v4.1.0

* Make the project compatible with Symfony 6.0
* Test multiple versions of PHP and Symfony in CI
Expand Down
38 changes: 20 additions & 18 deletions Controller/AbstractCmsController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

/*
* This file is part of the OrbitaleCmsBundle package.
*
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of the OrbitaleCmsBundle package.
*
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Orbitale\Bundle\CmsBundle\Controller;

Expand All @@ -24,35 +26,35 @@ abstract class AbstractCmsController extends AbstractController
* This also prevents things like /children/parent to work,
* as it should be /parent/children.
*
* @param array $slugs
* @param Page[]|Category[] $elements
* @param Category[]|Page[] $elements
*
* @return Category|Page
*/
protected function getFinalTreeElement(array $slugs, array $elements)
{
// Will check that slugs and elements match
$slugsElements = array_keys($elements);
$sortedSlugs = $slugs;
sort($sortedSlugs);
sort($slugsElements);
$slugsElements = \array_keys($elements);
$sortedSlugs = $slugs;
\sort($sortedSlugs);
\sort($slugsElements);

if ($sortedSlugs !== $slugsElements || !count($slugs) || count($slugs) !== count($elements)) {
if ($sortedSlugs !== $slugsElements || !\count($slugs) || \count($slugs) !== \count($elements)) {
throw $this->createNotFoundException();
}

/** @var Page|Category $element */
/** @var Category|Page $element */
$element = null;
/** @var Page|Category $previousElement */

/** @var Category|Page $previousElement */
$previousElement = null;

foreach ($slugs as $slug) {
$element = $elements[$slug] ?? null;
$match = false;
$match = false;
if ($element) {
// Only for the first iteration
$match = $previousElement
? $element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug()
? ($element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug())
: true;

$previousElement = $element;
Expand Down
54 changes: 25 additions & 29 deletions Controller/CategoryController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

/*
* This file is part of the OrbitaleCmsBundle package.
*
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of the OrbitaleCmsBundle package.
*
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Orbitale\Bundle\CmsBundle\Controller;

Expand All @@ -27,32 +29,26 @@ public function __construct(CategoryRepository $categoryRepository, PageReposito
$this->pageRepository = $pageRepository;
}

/**
* @param string $slugs
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request, string $slugs = ''): Response
{
if (preg_match('#/$#', $slugs)) {
return $this->redirect($this->generateUrl('orbitale_cms_category', ['slugs' => rtrim($slugs, '/')]));
if (\preg_match('#/$#', $slugs)) {
return $this->redirect($this->generateUrl('orbitale_cms_category', ['slugs' => \rtrim($slugs, '/')]));
}

$slugsArray = preg_split('~/~', $slugs, -1, PREG_SPLIT_NO_EMPTY);
$slugsArray = \preg_split('~/~', $slugs, -1, \PREG_SPLIT_NO_EMPTY);

$categories = $this->categoryRepository->findFrontCategories($slugsArray);

$category = $this->getFinalTreeElement($slugsArray, $categories);

$validOrderFields = ['createdAt', 'id', 'title', 'content'];

$limit = $request->query->get('limit', 10);
$page = $request->query->get('page', 1);
$order = $request->query->get('order', 'asc');
$orderBy = $request->query->get('order_by', current($validOrderFields));
if (!in_array($orderBy, $validOrderFields, true)) {
$orderBy = current($validOrderFields);
$limit = $request->query->get('limit', 10);
$page = $request->query->get('page', 1);
$order = $request->query->get('order', 'asc');
$orderBy = $request->query->get('order_by', \current($validOrderFields));
if (!\in_array($orderBy, $validOrderFields, true)) {
$orderBy = \current($validOrderFields);
}

$pages = $this->pageRepository->findByCategory(
Expand All @@ -64,15 +60,15 @@ public function indexAction(Request $request, string $slugs = ''): Response
);

return $this->render('@OrbitaleCms/Front/category.html.twig', [
'category' => $category,
'category' => $category,
'categories' => $categories,
'pages' => $pages,
'pagesCount' => count($pages),
'filters' => [
'page' => $page,
'limit' => $limit,
'pages' => $pages,
'pagesCount' => \count($pages),
'filters' => [
'page' => $page,
'limit' => $limit,
'orderBy' => $orderBy,
'order' => $order,
'order' => $order,
],
]);
}
Expand Down
Loading
Loading