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

Allow Symfony 6 and 7 #44

Open
wants to merge 10 commits into
base: 2.3.x
Choose a base branch
from
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"ext-fileinfo" : "*",
"ext-session": "*",
"oscarotero/env": "^2.1",
"symfony/templating": "^4.0|^5.0",
"symfony/twig-bundle": "^4.0|^5.0",
"symfony/asset": "^4.0|^5.0",
"symfony/http-client": "^4.0|^5.0",
"symfony/templating": "^4.0|^5.0|^6.0|^7.0",
"symfony/twig-bundle": "^4.0|^5.0|^6.0|^7.0",
"symfony/asset": "^4.0|^5.0|^6.0|^7.0",
"symfony/http-client": "^4.0|^5.0|^6.0|^7.0",
"metabolism/wordpress-core-installer": "^1.0",
"metabolism/package-actions": "^1.0",
"metabolism/wp-steroids": "^1.3.0",
Expand Down Expand Up @@ -109,5 +109,8 @@
"metabolism/package-actions": true,
"metabolism/wordpress-core-installer": true
}
},
"require-dev": {
"rector/rector": "^2.0"
}
}
32 changes: 32 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/samples/public',
__DIR__ . '/samples/src',
__DIR__ . '/src',
])
->withPreparedSets(symfonyConfigs: true)
->withComposerBased(twig: true, doctrine: true)
//->withPhpSets()
//->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml')
->withSets([
//SymfonySetList::SYMFONY_73,
//SymfonySetList::SYMFONY_74,
//SymfonySetList::SYMFONY_CODE_QUALITY,
//SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
])
->withSkip([
AddClosureVoidReturnTypeWhereNoReturnRector::class
])
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0)
;
30 changes: 15 additions & 15 deletions samples/src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class AppExtension extends AbstractExtension{
public function getFilters()
{
return [
new TwigFilter( 'clean_id', [$this,'cleanID'] ),
new TwigFilter( 'format_number', [$this,'formatNumber'] ),
new TwigFilter( 'll_CC', [$this,'llCC'] ),
new TwigFilter( 'br_to_space', [$this,'brToSpace'] ),
new TwigFilter( 'remove_accent', [$this,'removeAccent'] ),
new TwigFilter( 'typeOf', [$this,'typeOf'] ),
new TwigFilter( 'bind', [$this,'bind'] ),
new TwigFilter( 'implode', [$this,'implode'] ),
new TwigFilter( 'striptag', [$this, 'striptag']),
new TwigFilter( 'br_to_line', [$this, 'brToLine']),
new TwigFilter( 'remove_br', [$this, 'removeBr']),
new TwigFilter( 'file_content', [$this, 'getFileContent']),
new TwigFilter( 'wrap_embed', [$this, 'wrapEmbed']),
new TwigFilter( 'truncate', [$this, 'truncate']) ];
new TwigFilter( 'clean_id', $this->cleanID(...) ),
new TwigFilter( 'format_number', $this->formatNumber(...) ),
new TwigFilter( 'll_CC', $this->llCC(...) ),
new TwigFilter( 'br_to_space', $this->brToSpace(...) ),
new TwigFilter( 'remove_accent', $this->removeAccent(...) ),
new TwigFilter( 'typeOf', $this->typeOf(...) ),
new TwigFilter( 'bind', $this->bind(...) ),
new TwigFilter( 'implode', $this->implode(...) ),
new TwigFilter( 'striptag', $this->striptag(...)),
new TwigFilter( 'br_to_line', $this->brToLine(...)),
new TwigFilter( 'remove_br', $this->removeBr(...)),
new TwigFilter( 'file_content', $this->getFileContent(...)),
new TwigFilter( 'wrap_embed', $this->wrapEmbed(...)),
new TwigFilter( 'truncate', $this->truncate(...)) ];
}

/**
Expand All @@ -44,7 +44,7 @@ public function getFilters()
public function getFunctions()
{
return [
new TwigFunction( 'blank', [$this,'blank'] )
new TwigFunction( 'blank', $this->blank(...) )
];
}

Expand Down
2 changes: 1 addition & 1 deletion samples/src/Twig/TwigGlobalSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function injectGlobalVariables( ControllerEvent $event ) {
$this->twig->addGlobal( 'subsidiaries', $subsidiaries );
}

public static function getSubscribedEvents() {
public static function getSubscribedEvents(): array {
return [ KernelEvents::CONTROLLER => 'injectGlobalVariables' ];
}
}
23 changes: 23 additions & 0 deletions src/ArgumentResolver/BCValueResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Metabolism\WordpressBundle\ArgumentResolver;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* For BC compatibility with Symfony < 6.2
*/
if (interface_exists(ValueResolverInterface::class)) {
interface BCValueResolverInterface extends ValueResolverInterface
{
public function supports(Request $request, ArgumentMetadata $argument): bool;
}
} else {
interface BCValueResolverInterface extends ArgumentValueResolverInterface
{
}
}
7 changes: 5 additions & 2 deletions src/ArgumentResolver/BlogValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Metabolism\WordpressBundle\ArgumentResolver;

use Metabolism\WordpressBundle\Entity\Blog;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Class Metabolism\WordpressBundle Framework
*/
class BlogValueResolver implements ArgumentValueResolverInterface {
class BlogValueResolver implements BCValueResolverInterface {

/**
* @param Request $request
Expand All @@ -29,6 +28,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!$this->supports($request, $argument)) {
return [];
}

yield Blog::getInstance();
}
}
7 changes: 5 additions & 2 deletions src/ArgumentResolver/PostCollectionValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Metabolism\WordpressBundle\Entity\PostCollection;
use Metabolism\WordpressBundle\Repository\PostRepository;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Class Metabolism\WordpressBundle Framework
*/
class PostCollectionValueResolver implements ArgumentValueResolverInterface {
class PostCollectionValueResolver implements BCValueResolverInterface {

private $postRepository;

Expand Down Expand Up @@ -41,6 +40,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!$this->supports($request, $argument)) {
return [];
}

yield $this->postRepository->findQueried($argument->isNullable());
}
}
7 changes: 5 additions & 2 deletions src/ArgumentResolver/PostValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Metabolism\WordpressBundle\Entity\Post;
use Metabolism\WordpressBundle\Repository\PostRepository;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Class Metabolism\WordpressBundle Framework
*/
class PostValueResolver implements ArgumentValueResolverInterface {
class PostValueResolver implements BCValueResolverInterface {

private $postRepository;

Expand Down Expand Up @@ -44,6 +43,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!$this->supports($request, $argument)) {
return [];
}

yield $this->postRepository->findQueried($argument->isNullable());
}
}
7 changes: 5 additions & 2 deletions src/ArgumentResolver/TermValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Metabolism\WordpressBundle\Entity\Term;
use Metabolism\WordpressBundle\Repository\TermRepository;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Class Metabolism\WordpressBundle Framework
*/
class TermValueResolver implements ArgumentValueResolverInterface {
class TermValueResolver implements BCValueResolverInterface {

private $termRepository;

Expand Down Expand Up @@ -41,6 +40,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!$this->supports($request, $argument)) {
return [];
}

yield $this->termRepository->findQueried($argument->isNullable());
}
}
6 changes: 5 additions & 1 deletion src/ArgumentResolver/UserValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Class Metabolism\WordpressBundle Framework
*/
class UserValueResolver implements ArgumentValueResolverInterface {
class UserValueResolver implements BCValueResolverInterface {

private $userRepository;

Expand Down Expand Up @@ -41,6 +41,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!$this->supports($request, $argument)) {
return [];
}

yield $this->userRepository->findQueried($argument->isNullable());
}
}
10 changes: 1 addition & 9 deletions src/DependencyInjection/WordpressExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\Extension;

/**
* Class Metabolism\WordpressBundle Framework
Expand All @@ -33,12 +33,4 @@ public function prepend(ContainerBuilder $container)
{
// TODO: Implement prepend() method.
}

/**
* @return string
*/
public function getAlias()
{
return parent::getAlias();
}
}
2 changes: 1 addition & 1 deletion src/EventSubscriber/KernelEventsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KernelEventsSubscriber implements EventSubscriberInterface
/**
* @return array
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
Expand Down
38 changes: 19 additions & 19 deletions src/Twig/WordpressTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ public function getFilters(): array
{
return [
new TwigFilter( 'handle', 'sanitize_title' ),
new TwigFilter( 'placeholder', [$this, 'placeholder'] ),
new TwigFilter( 'more', [$this, 'more'] ),
new TwigFilter( 'resize', [$this, 'resize'] ),
new TwigFilter( 'picture', [$this, 'picture'] ),
new TwigFilter( 'blurhash', [$this, 'blurhash'] ),
new TwigFilter( 'figure', [$this, 'figure'] ),
new TwigFilter( 'placeholder', $this->placeholder(...) ),
new TwigFilter( 'more', $this->more(...) ),
new TwigFilter( 'resize', $this->resize(...) ),
new TwigFilter( 'picture', $this->picture(...) ),
new TwigFilter( 'blurhash', $this->blurhash(...) ),
new TwigFilter( 'figure', $this->figure(...) ),
new TwigFilter( 'stripshortcodes','strip_shortcodes' ),
new TwigFilter( 'trim_words','wp_trim_words' ),
new TwigFilter( 'function', [$this, 'execFunction'] ),
new TwigFilter( 'function', $this->execFunction(...) ),
new TwigFilter( 'excerpt','wp_trim_words' ),
new TwigFilter( 'sanitize','sanitize_title' ),
new TwigFilter( 'base64_encode','base64_encode' ),
new TwigFilter( 'base64_decode','base64_decode' ),
new TwigFilter( 'shortcodes', [$this, 'doShortcode'] ),
new TwigFilter( 'shortcodes', $this->doShortcode(...) ),
new TwigFilter( 'wpautop','wpautop' ),
new TwigFilter( 'array',[$this, 'toArray'] ),
new TwigFilter( 'file_exists',[$this, 'fileExists'] ),
new TwigFilter( 'array',$this->toArray(...) ),
new TwigFilter( 'file_exists',$this->fileExists(...) ),
];
}

Expand All @@ -57,20 +57,20 @@ public function getFunctions(): array
$blog = Blog::getInstance();

return [
new TwigFunction( 'placeholder', [$this, 'generatePlaceholder'] ),
new TwigFunction( 'pixel', [$this, 'generatePixel'] ),
new TwigFunction( 'fn', [$this, 'execFunction'] ),
new TwigFunction( 'function', [$this, 'execFunction'] ),
new TwigFunction( 'action', [$this, 'doAction'] ),
new TwigFunction( 'placeholder', $this->generatePlaceholder(...) ),
new TwigFunction( 'pixel', $this->generatePixel(...) ),
new TwigFunction( 'fn', $this->execFunction(...) ),
new TwigFunction( 'function', $this->execFunction(...) ),
new TwigFunction( 'action', $this->doAction(...) ),
new TwigFunction( 'shortcode', 'do_shortcode' ),
new TwigFunction( 'login_url', 'wp_login_url' ),
new TwigFunction( 'home_url', 'get_home_url' ),
new TwigFunction( 'search_form', 'get_search_form' ),
new TwigFunction( 'archive_url', [$blog, 'getArchiveLink'] ),
new TwigFunction( 'archive_title', [$blog, 'getArchiveTitle'] ),
new TwigFunction( 'archive_url', $blog->getArchiveLink(...) ),
new TwigFunction( 'archive_title', $blog->getArchiveTitle(...) ),
new TwigFunction( 'attachment_url', 'wp_get_attachment_url' ),
new TwigFunction( 'post_url', [$this, 'getPermalink'] ),
new TwigFunction( 'term_url', [$this, 'getTermLink'] ),
new TwigFunction( 'post_url', $this->getPermalink(...) ),
new TwigFunction( 'term_url', $this->getTermLink(...) ),
new TwigFunction( 'bloginfo', 'get_bloginfo' ),
new TwigFunction( 'dynamic_sidebar', function($id){ return $this->getOutput('dynamic_sidebar', [$id]); }, ['is_safe' => array('html')] ),
new TwigFunction( 'comment_form', function($post_id, $args=[]){ return $this->getOutput('comment_form', [$args, $post_id]); }, ['is_safe' => array('html')] ),
Expand Down