Skip to content

Commit

Permalink
Update to SF 6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
david BENARD authored and magicbart committed Jul 25, 2024
1 parent 527962e commit 2758c7e
Show file tree
Hide file tree
Showing 34 changed files with 472 additions and 516 deletions.
9 changes: 0 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
###############################################################################
# /!\ Important: User-specific files must not appear in the .gitignore file. #
# Please edit your local ".git/info/exclude" file to ignore #
# user-specific files. #
###############################################################################

## Ignoring backup php files from editors.
*.php~

## Ignoring composer dependencies.
vendor/
composer.lock
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
install: ## install project
composer install

update: ## update project
composer update

test: ## launch tests
./vendor/bin/simple-phpunit

lint: ##
composer run lint

phpstan: ##
composer run lint:phpstan -- --memory-limit=1G

phpcs: ##
composer run lint:phpcs

phpcs-fix:
composer run lint:phpcs:fix
6 changes: 0 additions & 6 deletions Tests/autoload.php

This file was deleted.

48 changes: 35 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,31 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"a2lix/translation-form-bundle": "~3.0",
"api-platform/core": "^2.7",
"doctrine/orm": "^2.13",
"api-platform/core": "^3.2",
"doctrine/orm": "^2.5",
"friendsofsymfony/ckeditor-bundle": "^2.1",
"gedmo/doctrine-extensions": "^3.11",
"knplabs/doctrine-behaviors": "~2.0",
"symfony/dependency-injection": "^5.4",
"symfony/event-dispatcher": "^5.4",
"symfony/http-kernel": "^5.4",
"symfony/security-bundle": "^5.4",
"symfony/validator": "^5.4"
"sonata-project/admin-bundle": "^4.0",
"sonata-project/doctrine-orm-admin-bundle": "^4.8",
"sonata-project/translation-bundle": "^3.3",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/validator": "^6.4",
"webmozart/assert": "^1.11"
},
"suggest": {
"sonata-project/admin-bundle": "To use administration with sonata",
"sonata-project/doctrine-orm-admin-bundle": "To use doctrine orm into sonata admin",
"sonata-project/translation-bundle": "To use transaltion into sonata admin"
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.5",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.4",
"phpstan/phpstan-symfony": "^1.3",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^6.2"
},
"autoload": {
"psr-4": { "ProjetNormandie\\ArticleBundle\\": "src/" }
Expand All @@ -36,6 +45,19 @@
"preferred-install": {
"*": "dist"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"console": "@php bin/console",
"lint:phpstan": "@php vendor/bin/phpstan",
"lint:phpcs": "@php vendor/bin/phpcs src/ -p",
"lint:phpcs:fix": "@php vendor/bin/phpcbf src/ -p",
"lint": [
"@lint:phpcs",
"@lint:phpstan"
]
}
}
17 changes: 17 additions & 0 deletions config/admin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
sonata.admin.article.article:
class: ProjetNormandie\ArticleBundle\Admin\ArticleAdmin
tags:
- name: sonata.admin
model_class: ProjetNormandie\ArticleBundle\Entity\Article
manager_type: orm
group: "group.articles"
label: "label.article"
sonata.admin.article.comment:
class: ProjetNormandie\ArticleBundle\Admin\CommentAdmin
tags:
- name: sonata.admin
model_class: ProjetNormandie\ArticleBundle\Entity\Comment
manager_type: orm
group: "group.articles"
label: "label.comment"
18 changes: 18 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
_defaults:
autowire: true
autoconfigure: true

ProjetNormandie\ArticleBundle\:
resource: '../src/*'
exclude: '../src/{Admin,Entity,DependencyInjection,Migrations,Tests,Kernel.php}'

pn.article.event.entity.article:
class: ProjetNormandie\ArticleBundle\EventListener\Entity\ArticleListener
tags:
- { name: doctrine.orm.entity_listener }

pn.article.event.entity.comment:
class: ProjetNormandie\ArticleBundle\EventListener\Entity\CommentListener
tags:
- { name: doctrine.orm.entity_listener }
5 changes: 5 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<ruleset>
<!-- Code MUST follow all rules outlined in PSR-1. -->
<rule ref="PSR12"/>
</ruleset>
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: 5
paths:
- src
ignoreErrors:
#doctrine
- '#Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata<object>::setIdGeneratorType\(\)#'
#sonata
- '#Call to an undefined method Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface<object>::getRootAliases\(\)#'
- '#Call to an undefined method Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface<object>::leftJoin\(\)#'
55 changes: 9 additions & 46 deletions src/Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

namespace ProjetNormandie\ArticleBundle\Admin;

use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
use DateTime;
use ProjetNormandie\ArticleBundle\ValueObject\ArticleStatus;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Show\ShowMapper;
Expand All @@ -16,24 +18,11 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use ProjetNormandie\ArticleBundle\Entity\Article;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\Security;

/**
* Administration manager for the Article Bundle.
*/
class ArticleAdmin extends AbstractAdmin
{
protected $baseRouteName = 'pnarticlebundle_admin_article';

private Security $security;

public function setSecurity(Security $security)
{
$this->security = $security;
}
protected $baseRouteName = 'pna_article_admin';

/**
* @param RouteCollectionInterface $collection
Expand Down Expand Up @@ -75,7 +64,7 @@ protected function configureFormFields(FormMapper $form): void
ChoiceType::class,
[
'label' => 'label.status',
'choices' => Article::getStatusChoices(),
'choices' => ArticleStatus::getStatusChoices(),
]
)
->add('publishedAt', DateTimeType::class, [
Expand Down Expand Up @@ -105,7 +94,9 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add(
'author', ModelFilter::class, [
'author',
ModelFilter::class,
[
'label' => 'label.author',
'field_type' => ModelAutocompleteType::class,
'field_options' => ['property' => 'username'],
Expand All @@ -129,7 +120,7 @@ protected function configureListFields(ListMapper $list): void
[
'label' => 'label.status',
'editable' => false,
'choices' => Article::getStatusChoices(),
'choices' => ArticleStatus::getStatusChoices(),
]
)
->add('createdAt', null, ['label' => 'label.createdAt'])
Expand All @@ -156,32 +147,4 @@ protected function configureShowFields(ShowMapper $show): void
->add('getDefaultTitle', null, ['label' => 'label.title'])
->add('getDefaultText', null, ['label' => 'label.text', 'safe' => true]);
}


/**
* @param object $object
*/
public function prePersist(object $object): void
{
$object->setAuthor($this->security->getUser());
if ($object->getStatus() === Article::STATUS_PUBLISHED) {
$object->setPublishedAt(new DateTime());
}
}

/**
* @param object $object
*/
public function preUpdate(object $object): void
{
/** @var EntityManager $em */
$em = $this->getModelManager()->getEntityManager($this->getClass());
$originalObject = $em->getUnitOfWork()->getOriginalEntityData($object);

// PUBLISHED
if ($originalObject['status'] === Article::STATUS_UNDER_CONSTRUCTION
&& $object->getStatus() === Article::STATUS_PUBLISHED) {
$object->setPublishedAt(new DateTime());
}
}
}
10 changes: 4 additions & 6 deletions src/Admin/CommentAdmin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ProjetNormandie\ArticleBundle\Admin;

use FOS\CKEditorBundle\Form\Type\CKEditorType;
Expand All @@ -15,12 +17,9 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Sonata\AdminBundle\Form\Type\ModelListType;

/**
* Administration manager for the Article Bundle.
*/
class CommentAdmin extends AbstractAdmin
{
protected $baseRouteName = 'pnarticlebundle_admin_comment';
protected $baseRouteName = 'pna_comment_admin';

/**
* @param RouteCollection $collection
Expand Down Expand Up @@ -73,10 +72,9 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
->add('user', ModelFilter::class, [
'label' => 'label.user',
'field_type' => ModelAutocompleteType::class,
'field_options' => ['property'=>'username'],
'field_options' => ['property' => 'username'],
])
;

}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/Builder/ArticleBuilder.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<?php

declare(strict_types=1);

namespace ProjetNormandie\ArticleBundle\Builder;

use Doctrine\ORM\EntityManagerInterface;
use ProjetNormandie\ArticleBundle\Contracts\ArticleInterface;
use ProjetNormandie\ArticleBundle\Entity\Article;
use ProjetNormandie\ArticleBundle\ValueObject\ArticleStatus;

class ArticleBuilder implements ArticleInterface
class ArticleBuilder
{
private $author;

/**
* @var string[]
*/
private array $titles;

/**
* @var string[]
*/
private array $texts;

private EntityManagerInterface $em;
Expand Down Expand Up @@ -56,11 +64,11 @@ public function setText(string $text, string $lang): ArticleBuilder
return $this;
}

public function send()
public function send(): void
{
$article = new Article();
$article->setAuthor($this->author);
$article->setStatus(self::STATUS_PUBLISHED);
$article->setStatus(ArticleStatus::PUBLISHED);
$article->setPublishedAt(new \Datetime());

foreach ($this->titles as $lang => $value) {
Expand Down
9 changes: 0 additions & 9 deletions src/Contracts/ArticleInterface.php

This file was deleted.

Loading

0 comments on commit 2758c7e

Please sign in to comment.