khaihihi
This commit is contained in:
137
wp-content/plugins/wordpress-seo/config/composer/actions.php
Normal file
137
wp-content/plugins/wordpress-seo/config/composer/actions.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\Composer
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\Composer;
|
||||
|
||||
use Composer\Script\Event;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Yoast\WP\SEO\Dependency_Injection\Container_Compiler;
|
||||
|
||||
/**
|
||||
* Class to handle Composer actions and events.
|
||||
*/
|
||||
class Actions {
|
||||
|
||||
/**
|
||||
* Prefixes dependencies if composer install is ran with dev mode.
|
||||
*
|
||||
* Used in composer in the post-install script hook.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param \Composer\Script\Event $event Composer event that triggered this script.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function prefix_dependencies( Event $event ) {
|
||||
$io = $event->getIO();
|
||||
|
||||
if ( ! $event->isDevMode() ) {
|
||||
$io->write( 'Not prefixing dependencies, due to not being in dev move.' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! \file_exists( __DIR__ . '/../../vendor/bin/php-scoper' ) ) {
|
||||
$io->write( 'Not prefixing dependencies, due to PHP scoper not being installed' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->write( 'Prefixing dependencies...' );
|
||||
|
||||
$event_dispatcher = $event->getComposer()->getEventDispatcher();
|
||||
$event_dispatcher->dispatchScript( 'prefix-dependencies', $event->isDevMode() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the dependency injection container.
|
||||
*
|
||||
* Used the composer compile-dependency-injection-container command.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param \Composer\Script\Event $event Composer event that triggered this script.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function compile_dependency_injection_container( Event $event ) {
|
||||
$io = $event->getIO();
|
||||
|
||||
if ( ! \class_exists( ContainerBuilder::class ) ) {
|
||||
$io->write( 'Not compiling dependency injection container, due to the container builder not being installed' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->write( 'Compiling the dependency injection container...' );
|
||||
|
||||
// Pas true as debug to force a recheck of the container.
|
||||
Container_Compiler::compile( true );
|
||||
|
||||
$io->write( 'The dependency injection container has been compiled.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHPCS on the staged files.
|
||||
*
|
||||
* Used the composer check-staged-cs command.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function check_staged_cs() {
|
||||
self::check_cs_for_changed_files( '--staged' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHPCS on the staged files.
|
||||
*
|
||||
* Used the composer check-staged-cs command.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param \Composer\Script\Event $event Composer event that triggered this script.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function check_branch_cs( Event $event ) {
|
||||
$args = $event->getArguments();
|
||||
if ( empty( $args ) ) {
|
||||
self::check_cs_for_changed_files( 'trunk' );
|
||||
return;
|
||||
}
|
||||
self::check_cs_for_changed_files( $args[0] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHPCS on changed files compared to some git reference.
|
||||
*
|
||||
* @param string $compare The git reference.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function check_cs_for_changed_files( $compare ) {
|
||||
\exec( 'git diff --name-only --diff-filter=d ' . \escapeshellarg( $compare ), $files );
|
||||
$files = \array_filter(
|
||||
$files,
|
||||
function ( $file ) {
|
||||
return \substr( $file, -4 ) === '.php';
|
||||
}
|
||||
);
|
||||
|
||||
if ( empty( $files ) ) {
|
||||
echo 'No files to compare! Exiting.';
|
||||
return;
|
||||
}
|
||||
|
||||
\system( 'composer check-cs -- ' . \implode( ' ', \array_map( 'escapeshellarg', $files ) ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\Dependency_Injection
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\Dependency_Injection;
|
||||
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
|
||||
/**
|
||||
* This class is responsible for compiling the dependency injection container.
|
||||
*/
|
||||
class Container_Compiler {
|
||||
|
||||
/**
|
||||
* Compiles the dependency injection container.
|
||||
*
|
||||
* @param boolean $debug If false the container will only be re-compiled if it does not yet already exist.
|
||||
*
|
||||
* @throws \Exception If compiling the container fails.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function compile( $debug ) {
|
||||
$file = __DIR__ . '/../../src/generated/container.php';
|
||||
$cache = new ConfigCache( $file, $debug );
|
||||
|
||||
if ( ! $cache->isFresh() ) {
|
||||
$container_builder = new ContainerBuilder();
|
||||
$container_builder->addCompilerPass( new Loader_Pass() );
|
||||
$loader = new Custom_Loader( $container_builder );
|
||||
$loader->load( 'config/dependency-injection/services.php' );
|
||||
$container_builder->compile();
|
||||
|
||||
$dumper = new PhpDumper( $container_builder );
|
||||
$code = $dumper->dump(
|
||||
[
|
||||
'class' => 'Cached_Container',
|
||||
'namespace' => 'Yoast\WP\SEO\Generated',
|
||||
]
|
||||
);
|
||||
$code = \str_replace( 'Symfony\\Component\\DependencyInjection', 'YoastSEO_Vendor\\Symfony\\Component\\DependencyInjection', $code );
|
||||
$code = \str_replace( 'Symfony\\\\Component\\\\DependencyInjection', 'YoastSEO_Vendor\\\\Symfony\\\\Component\\\\DependencyInjection', $code );
|
||||
|
||||
$cache->write( $code, $container_builder->getResources() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\Dependency_Injection
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\Dependency_Injection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* This class is mostly a direct copy-paste of the symfony PhpFileLoader class.
|
||||
* It's been adapted to allow automatic discovery based on not just PSR-4 but also the Yoast standards.
|
||||
*/
|
||||
class Custom_Loader extends PhpFileLoader {
|
||||
|
||||
/**
|
||||
* Custom_Loader constructor.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The ContainerBuilder to load classes for.
|
||||
*/
|
||||
public function __construct( ContainerBuilder $container ) {
|
||||
parent::__construct( $container, new FileLocator( __DIR__ . '/../..' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a path to a class name using the class map.
|
||||
*
|
||||
* @param string $path The path of the class.
|
||||
*
|
||||
* @return bool|string The classname.
|
||||
*/
|
||||
private function getClassFromClassMap( $path ) {
|
||||
static $class_map;
|
||||
|
||||
if ( ! $class_map ) {
|
||||
$class_map = require __DIR__ . '/../../vendor/composer/autoload_classmap.php';
|
||||
}
|
||||
|
||||
foreach ( $class_map as $class => $class_path ) {
|
||||
if ( $path === $class_path ) {
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of classes as services using PSR-4 for discovery.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $prototype A definition to use as template.
|
||||
* @param string $namespace The namespace prefix of classes
|
||||
* in the scanned directory.
|
||||
* @param string $resource The directory to look for classes,
|
||||
* glob-patterns allowed.
|
||||
* @param string $exclude A globed path of files to exclude.
|
||||
*
|
||||
* @throws InvalidArgumentException If invalid arguments are supplied.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerClasses( Definition $prototype, $namespace, $resource, $exclude = null ) {
|
||||
if ( \substr( $namespace, -1 ) !== '\\' ) {
|
||||
throw new InvalidArgumentException( \sprintf( 'Namespace prefix must end with a "\\": %s.', $namespace ) );
|
||||
}
|
||||
if ( ! \preg_match( '/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+\\\\)++$/', $namespace ) ) {
|
||||
throw new InvalidArgumentException( \sprintf( 'Namespace is not a valid PSR-4 prefix: %s.', $namespace ) );
|
||||
}
|
||||
|
||||
$classes = $this->findClasses( $namespace, $resource, $exclude );
|
||||
// Prepare for deep cloning.
|
||||
$serialized_prototype = \serialize( $prototype );
|
||||
$interfaces = [];
|
||||
$singly_implemented = [];
|
||||
|
||||
foreach ( $classes as $class => $error_message ) {
|
||||
if ( \interface_exists( $class, false ) ) {
|
||||
$interfaces[] = $class;
|
||||
}
|
||||
else {
|
||||
$this->setDefinition( $class, $definition = \unserialize( $serialized_prototype ) );
|
||||
if ( $error_message !== null ) {
|
||||
$definition->addError( $error_message );
|
||||
|
||||
continue;
|
||||
}
|
||||
foreach ( \class_implements( $class, false ) as $interface ) {
|
||||
$singly_implemented[ $interface ] = isset( $singly_implemented[ $interface ] ) ? false : $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $interfaces as $interface ) {
|
||||
if ( ! empty( $singly_implemented[ $interface ] ) ) {
|
||||
$this->container->setAlias( $interface, $singly_implemented[ $interface ] )
|
||||
->setPublic( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a definition in the container with its instanceof-conditionals.
|
||||
*
|
||||
* @param string $id The ID of the definition.
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $definition The definition.
|
||||
*
|
||||
* @throws InvalidArgumentException If invalid arguments were supplied.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setDefinition( $id, Definition $definition ) {
|
||||
$this->container->removeBindings( $id );
|
||||
|
||||
// @codingStandardsIgnoreLine WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar This is from an inherited class not abiding by that standard.
|
||||
if ( $this->isLoadingInstanceof ) {
|
||||
if ( ! $definition instanceof ChildDefinition ) {
|
||||
throw new InvalidArgumentException( \sprintf( 'Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, \get_class( $definition ) ) );
|
||||
}
|
||||
$this->instanceof[ $id ] = $definition;
|
||||
}
|
||||
else {
|
||||
$this->container->setDefinition( $id, ( $definition instanceof ChildDefinition ) ? $definition : $definition->setInstanceofConditionals( $this->instanceof ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds classes based on a given pattern and exclude pattern.
|
||||
*
|
||||
* @param string $namespace The namespace prefix of classes in the scanned directory.
|
||||
* @param string $pattern The directory to look for classes, glob-patterns allowed.
|
||||
* @param string $exclude A globed path of files to exclude.
|
||||
*
|
||||
* @throws InvalidArgumentException If invalid arguments were supplied.
|
||||
*
|
||||
* @return array The found classes.
|
||||
*/
|
||||
private function findClasses( $namespace, $pattern, $exclude ) {
|
||||
$parameter_bag = $this->container->getParameterBag();
|
||||
|
||||
$exclude_paths = [];
|
||||
$exclude_prefix = null;
|
||||
if ( $exclude ) {
|
||||
$exclude = $parameter_bag->unescapeValue( $parameter_bag->resolveValue( $exclude ) );
|
||||
foreach ( $this->glob( $exclude, true, $resource ) as $path => $info ) {
|
||||
if ( $exclude_prefix === null ) {
|
||||
$exclude_prefix = $resource->getPrefix();
|
||||
}
|
||||
|
||||
// Normalize Windows slashes.
|
||||
$exclude_paths[ \str_replace( '\\', '/', $path ) ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$pattern = $parameter_bag->unescapeValue( $parameter_bag->resolveValue( $pattern ) );
|
||||
$classes = [];
|
||||
$ext_regexp = \defined( 'HHVM_VERSION' ) ? '/\\.(?:php|hh)$/' : '/\\.php$/';
|
||||
$prefix_len = null;
|
||||
foreach ( $this->glob( $pattern, true, $resource ) as $path => $info ) {
|
||||
if ( $prefix_len === null ) {
|
||||
$prefix_len = \strlen( $resource->getPrefix() );
|
||||
|
||||
if ( $exclude_prefix && \strpos( $exclude_prefix, $resource->getPrefix() ) !== 0 ) {
|
||||
throw new InvalidArgumentException( \sprintf( 'Invalid "exclude" pattern when importing classes for "%s": make sure your "exclude" pattern (%s) is a subset of the "resource" pattern (%s)', $namespace, $exclude, $pattern ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $exclude_paths[ \str_replace( '\\', '/', $path ) ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! \preg_match( $ext_regexp, $path, $m ) || ! $info->isReadable() ) {
|
||||
continue;
|
||||
}
|
||||
$class = $this->getClassFromClassMap( $path );
|
||||
|
||||
if ( ! $class || ! \preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $class ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$r = $this->container->getReflectionClass( $class );
|
||||
} catch ( \ReflectionException $e ) {
|
||||
$classes[ $class ] = \sprintf(
|
||||
'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".',
|
||||
$namespace,
|
||||
$class,
|
||||
$e->getMessage()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Check to make sure the expected class exists.
|
||||
if ( ! $r ) {
|
||||
throw new InvalidArgumentException( \sprintf( 'Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern ) );
|
||||
}
|
||||
|
||||
if ( $r->isInstantiable() || $r->isInterface() ) {
|
||||
$classes[ $class ] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Track only for new & removed files.
|
||||
if ( $resource instanceof GlobResource ) {
|
||||
$this->container->addResource( $resource );
|
||||
}
|
||||
else {
|
||||
foreach ( $resource as $path ) {
|
||||
$this->container->fileExists( $path, false );
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\Dependency_Injection
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\Dependency_Injection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Yoast\WP\SEO\Conditionals\Conditional;
|
||||
use Yoast\WP\SEO\Loader;
|
||||
use Yoast\WP\SEO\WordPress\Initializer;
|
||||
use Yoast\WP\SEO\WordPress\Integration;
|
||||
|
||||
/**
|
||||
* A pass is a step in the compilation process of the container.
|
||||
*
|
||||
* This step will automatically ensure all classes implementing the Integration interface
|
||||
* are registered with the Loader class.
|
||||
*/
|
||||
class Loader_Pass implements CompilerPassInterface {
|
||||
|
||||
/**
|
||||
* Checks all definitions to ensure all classes implementing the Integration interface
|
||||
* are registered with the Loader class.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container.
|
||||
*/
|
||||
public function process( ContainerBuilder $container ) {
|
||||
if ( ! $container->hasDefinition( Loader::class ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader_definition = $container->getDefinition( Loader::class );
|
||||
$loader_definition->setArgument( 0, new Reference( 'service_container' ) );
|
||||
$loader_definition->setPublic( true );
|
||||
|
||||
$definitions = $container->getDefinitions();
|
||||
|
||||
foreach ( $definitions as $definition ) {
|
||||
$this->process_definition( $definition, $loader_definition );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a definition in the container.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $definition The definition to process.
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $loader_definition The loader definition.
|
||||
*/
|
||||
private function process_definition( Definition $definition, Definition $loader_definition ) {
|
||||
$class = $definition->getClass();
|
||||
|
||||
if ( \is_subclass_of( $class, Initializer::class ) ) {
|
||||
$loader_definition->addMethodCall( 'register_initializer', [ $class ] );
|
||||
$definition->setPublic( true );
|
||||
}
|
||||
|
||||
if ( \is_subclass_of( $class, Integration::class ) ) {
|
||||
$loader_definition->addMethodCall( 'register_integration', [ $class ] );
|
||||
$definition->setPublic( true );
|
||||
}
|
||||
|
||||
if ( \is_subclass_of( $class, Conditional::class ) ) {
|
||||
$definition->setPublic( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\Dependency_Injection
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\Dependency_Injection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Yoast\WP\SEO\Repositories\Indexable_Repository;
|
||||
use Yoast\WP\SEO\Repositories\Primary_Term_Repository;
|
||||
use Yoast\WP\SEO\Repositories\SEO_Links_Repository;
|
||||
use Yoast\WP\SEO\Repositories\SEO_Meta_Repository;
|
||||
use Yoast\WP\SEO\WordPress\Wrapper;
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerBuilder */
|
||||
|
||||
// WordPress factory functions.
|
||||
$container->register( 'wpdb', 'wpdb' )->setFactory( [ Wrapper::class, 'get_wpdb' ] );
|
||||
$container->register( 'wp_query', 'WP_Query' )->setFactory( [ Wrapper::class, 'get_wp_query' ] );
|
||||
|
||||
// Model repository factory functions.
|
||||
$container->register( Indexable_Repository::class, Indexable_Repository::class )->setFactory( [ Indexable_Repository::class, 'get_instance' ] )->setAutowired( true );
|
||||
$container->register( Primary_Term_Repository::class, Primary_Term_Repository::class )->setFactory( [ Primary_Term_Repository::class, 'get_instance' ] )->setAutowired( true );
|
||||
$container->register( SEO_Meta_Repository::class, SEO_Meta_Repository::class )->setFactory( [ SEO_Meta_Repository::class, 'get_instance' ] )->setAutowired( true );
|
||||
$container->register( SEO_Links_Repository::class, SEO_Links_Repository::class )->setFactory( [ SEO_Links_Repository::class, 'get_instance' ] )->setAutowired( true );
|
||||
|
||||
$excluded_files = [
|
||||
'main.php',
|
||||
];
|
||||
|
||||
$excluded_directories = [
|
||||
'models',
|
||||
'loaders',
|
||||
'wordpress',
|
||||
'generated',
|
||||
'orm',
|
||||
];
|
||||
|
||||
$excluded = \implode( ',', \array_merge( $excluded_directories, $excluded_files ) );
|
||||
|
||||
$base_definition = new Definition();
|
||||
|
||||
$base_definition
|
||||
->setAutowired( true )
|
||||
->setAutoconfigured( true )
|
||||
->setPublic( false );
|
||||
|
||||
/* @var $loader \Yoast\WP\SEO\Dependency_Injection\Custom_Loader */
|
||||
$loader->registerClasses( $base_definition, 'Yoast\\WP\\SEO\\', 'src/*', 'src/{' . $excluded . '}' );
|
||||
|
||||
if ( \file_exists( __DIR__ . '/../../premium/config/dependency-injection/services.php' ) ) {
|
||||
include __DIR__ . '/../../premium/config/dependency-injection/services.php';
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\PHP_CodeShift
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\PHP_CodeShift;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
/**
|
||||
* Class Vendor_Prefixing_Visitor
|
||||
*/
|
||||
class Remove_Vendor_Prefixing_Array_Key_Visitor extends NodeVisitorAbstract {
|
||||
|
||||
/**
|
||||
* Removes vendor prefixes from array keys.
|
||||
*
|
||||
* @param \PhpParser\Node $node The node being visited.
|
||||
*
|
||||
* @return \PhpParser\Node The possibly modified node.
|
||||
*/
|
||||
public function leaveNode( Node $node ) {
|
||||
if ( ! $node instanceof ArrayItem ) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ( $node->key instanceof String_ && \strpos( $node->key->value, \YOAST_VENDOR_NS_PREFIX ) !== false ) {
|
||||
$node->key->value = \str_replace( \YOAST_VENDOR_NS_PREFIX . '\\', '', $node->key->value );
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\PHP_CodeShift
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\PHP_CodeShift;
|
||||
|
||||
use Codeshift\AbstractCodemod;
|
||||
|
||||
/**
|
||||
* Class Vendor_Prefixing_Codemod
|
||||
*/
|
||||
class Remove_Vendor_Prefixing_Codemod extends AbstractCodemod {
|
||||
|
||||
/**
|
||||
* Sets up the environment required to do the code modifications.
|
||||
*/
|
||||
public function init() {
|
||||
\define( 'YoastSEO_Vendor\RUCKUSING_BASE', __DIR__ . '/../../fake-ruckusing' );
|
||||
|
||||
\define( 'YOAST_VENDOR_NS_PREFIX', 'YoastSEO_Vendor' );
|
||||
\define( 'YOAST_VENDOR_DEFINE_PREFIX', 'YOASTSEO_VENDOR__' );
|
||||
\define( 'YOAST_VENDOR_PREFIX_DIRECTORY', 'vendor_prefixed' );
|
||||
|
||||
$visitor = new Remove_Vendor_Prefixing_Visitor();
|
||||
$comment_visitor = new Remove_Vendor_Prefixing_Comment_Visitor();
|
||||
$array_key_visitor = new Remove_Vendor_Prefixing_Array_Key_Visitor();
|
||||
$this->addTraversalTransform( $visitor, $comment_visitor, $array_key_visitor );
|
||||
}
|
||||
}
|
||||
|
||||
return 'Yoast\WP\SEO\PHP_CodeShift\Remove_Vendor_Prefixing_Codemod';
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\PHP_CodeShift
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\PHP_CodeShift;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
/**
|
||||
* Class Vendor_Prefixing_Visitor
|
||||
*/
|
||||
class Remove_Vendor_Prefixing_Comment_Visitor extends NodeVisitorAbstract {
|
||||
|
||||
/**
|
||||
* Removes vendor prefixes from comments.
|
||||
*
|
||||
* @param \PhpParser\Node $node The node being visited.
|
||||
*
|
||||
* @return \PhpParser\Node The possibly modified node.
|
||||
*/
|
||||
public function leaveNode( Node $node ) {
|
||||
$comment = $node->getDocComment();
|
||||
|
||||
if ( $comment && \strpos( $comment->getText(), \YOAST_VENDOR_NS_PREFIX ) !== false ) {
|
||||
$updated_text = \str_replace( \YOAST_VENDOR_NS_PREFIX . '\\', '', $comment->getText() );
|
||||
$updated_comment = new Doc( $updated_text, $comment->getLine(), $comment->getFilePos(), $comment->getTokenPos() );
|
||||
$node->setDocComment( $updated_comment );
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Yoast SEO Plugin File.
|
||||
*
|
||||
* @package Yoast\YoastSEO\PHP_CodeShift
|
||||
*/
|
||||
|
||||
namespace Yoast\WP\SEO\PHP_CodeShift;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
/**
|
||||
* Class Vendor_Prefixing_Visitor
|
||||
*/
|
||||
class Remove_Vendor_Prefixing_Visitor extends NodeVisitorAbstract {
|
||||
|
||||
/**
|
||||
* Removes vendor prefixes from use statements.
|
||||
*
|
||||
* @param \PhpParser\Node $node The node being visited.
|
||||
*
|
||||
* @return \PhpParser\Node The possibly modified node.
|
||||
*/
|
||||
public function leaveNode( Node $node ) {
|
||||
if ( ! $node instanceof Name ) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ( $node->getFirst() !== \YOAST_VENDOR_NS_PREFIX ) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
return $node->slice( 1 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => [
|
||||
Finder::create()->files()->in( 'vendor/symfony/dependency-injection' )->name( [
|
||||
'Container.php', 'ContainerInterface.php', 'ResettableContainerInterface.php', 'LICENSE', 'composer.json'
|
||||
] ),
|
||||
Finder::create()->files()->in( 'vendor/symfony/dependency-injection/Argument' )->name( [ 'RewindableGenerator.php' ] ),
|
||||
Finder::create()->files()->in( 'vendor/symfony/dependency-injection/Exception' )->name( [
|
||||
'InvalidArgumentException.php', 'LogicException.php', 'RuntimeException.php',
|
||||
'ServiceCircularReferenceException.php', 'ServiceNotFoundException.php', 'EnvNotFoundException.php',
|
||||
'ParameterCircularReferenceException.php', 'ExceptionInterface.php'
|
||||
] ),
|
||||
Finder::create()->files()->in( 'vendor/symfony/dependency-injection/ParameterBag' )->name( [
|
||||
'FrozenParameterBag.php', 'ParameterBagInterface.php', 'EnvPlaceholderParameterBag.php', 'ParameterBag.php'
|
||||
] ),
|
||||
],
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => [],
|
||||
|
||||
);
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => [
|
||||
Finder::create()->files()->in( 'vendor/guzzlehttp/guzzle' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
Finder::create()->files()->in( 'vendor/guzzlehttp/promises' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
Finder::create()->files()->in( 'vendor/guzzlehttp/psr7' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
],
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => [
|
||||
/**
|
||||
* Replaces the Adapter string references with the prefixed versions.
|
||||
*
|
||||
* @param string $filePath The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
// 18 is the length of the GrantFactory.php file path.
|
||||
if ( substr( $file_path, -18 ) !== 'src/Middleware.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = str_replace(
|
||||
sprintf( '%s\\\\cookies must be an instance of GuzzleHttp\\\\Cookie\\\\CookieJarInterface', $prefix ),
|
||||
sprintf( 'cookies must be an instance of %s\\\\GuzzleHttp\\\\Cookie\\\\CookieJarInterface', $prefix ),
|
||||
$content
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
],
|
||||
|
||||
);
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => array(
|
||||
Finder::create()->files()->in( 'vendor/j4mie/idiorm' )->name( [ 'idiorm.php', 'LICENSE', 'composer.json' ] ),
|
||||
),
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => array(),
|
||||
|
||||
/*
|
||||
* By default, PHP-Scoper will not prefix the user defined constants, classes and functions belonging to the global
|
||||
* namespace. You can however change that setting for them to be prefixed as usual unless explicitly whitelisted.
|
||||
*
|
||||
* https://github.com/humbug/php-scoper#whitelist
|
||||
*/
|
||||
'whitelist-global-classes' => false,
|
||||
);
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => [
|
||||
Finder::create()->files()->in( 'vendor/league/oauth2-client' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
],
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => [
|
||||
/**
|
||||
* Replaces the Adapter string references with the prefixed versions.
|
||||
*
|
||||
* @param string $filePath The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
// 26 is the length of the GrantFactory.php file path.
|
||||
if ( substr( $file_path, -26 ) !== 'src/Grant/GrantFactory.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = str_replace(
|
||||
'$class = \'League\\\\OAuth2\\\\Client\\\\Grant\\\\\' . $class;',
|
||||
sprintf( '$class = \'%s\\\\League\\\\OAuth2\\\\Client\\\\Grant\\\\\' . $class;', $prefix ),
|
||||
$content
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
],
|
||||
|
||||
);
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => [
|
||||
Finder::create()->files()->in( 'vendor/psr/container' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
Finder::create()->files()->in( 'vendor/psr/http-message' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
Finder::create()->files()->in( 'vendor/psr/log' )->exclude( 'Test' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
],
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => [],
|
||||
|
||||
);
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
* By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
||||
* directory. You can however define which files should be scoped by defining a collection of Finders in the
|
||||
* following configuration key.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
||||
*/
|
||||
'finders' => array(
|
||||
Finder::create()->files()->in( 'vendor/ruckusing/ruckusing-migrations' )
|
||||
->exclude( [ 'config', 'tests', 'lib/Task/Hello' ] )
|
||||
->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
|
||||
),
|
||||
|
||||
/*
|
||||
* When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
||||
* original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
||||
* support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
||||
* heart contents.
|
||||
*
|
||||
* For more see: https://github.com/humbug/php-scoper#patchers
|
||||
*/
|
||||
'patchers' => array(
|
||||
/**
|
||||
* Replaces the Adapter string references with the prefixed versions.
|
||||
*
|
||||
* @param string $filePath The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
if ( substr( $file_path, -33 ) !== 'lib/Ruckusing/FrameworkRunner.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = preg_replace(
|
||||
'/\$adapter_class = "Ruckusing_Adapter_(MySQL|PgSQL|Sqlite3)_Base"/',
|
||||
sprintf( '$adapter_class = "\%s\Ruckusing_Adapter_\\1_Base"', $prefix ),
|
||||
$content
|
||||
);
|
||||
|
||||
$replaced = str_replace(
|
||||
"\set_error_handler(array('Ruckusing_Exception', 'errorHandler'), \E_ALL);",
|
||||
sprintf( '\set_error_handler(array(\'\%s\Ruckusing_Exception\', \'errorHandler\'), \E_ALL);', $prefix ),
|
||||
$replaced
|
||||
);
|
||||
|
||||
$replaced = str_replace(
|
||||
"\set_exception_handler(array('Ruckusing_Exception', 'exceptionHandler'));",
|
||||
sprintf( '\set_exception_handler(array(\'\%s\Ruckusing_Exception\', \'exceptionHandler\'));', $prefix ),
|
||||
$replaced
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces a string reference to a class with the prefixed version.
|
||||
*
|
||||
* @param string $file_path The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
if ( substr( $file_path, -27 ) !== 'Ruckusing/Util/Migrator.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = str_replace(
|
||||
'"Ruckusing_Util_Migrator"',
|
||||
sprintf( '"\%s\Ruckusing_Util_Migrator"', $prefix ),
|
||||
$content
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
|
||||
/**
|
||||
* Prefixes the Namespace prefix define.
|
||||
*
|
||||
* @param string $file_path The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
if ( substr( $file_path, -25 ) !== 'Ruckusing/Util/Naming.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = str_replace(
|
||||
'const CLASS_NS_PREFIX = \'Task_\'',
|
||||
sprintf( 'const CLASS_NS_PREFIX = \'\%s\Task_\'', $prefix ),
|
||||
$content
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
|
||||
/**
|
||||
* Escapes the namespace for use in a regex match.
|
||||
*
|
||||
* @param string $file_path The path of the current file.
|
||||
* @param string $prefix The prefix to be used.
|
||||
* @param string $content The content of the specific file.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
function( $file_path, $prefix, $content ) {
|
||||
if ( substr( $file_path, -25 ) !== 'Ruckusing/Util/Naming.php' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$replaced = str_replace(
|
||||
'preg_match(\'/\' . self::CLASS_NS_PREFIX . \'/\'',
|
||||
'preg_match(\'/\' . preg_quote(self::CLASS_NS_PREFIX) . \'/\'',
|
||||
$content
|
||||
);
|
||||
|
||||
return $replaced;
|
||||
},
|
||||
),
|
||||
|
||||
/*
|
||||
* By default, PHP-Scoper will not prefix the user defined constants, classes and functions belonging to the global
|
||||
* namespace. You can however change that setting for them to be prefixed as usual unless explicitly whitelisted.
|
||||
*
|
||||
* https://github.com/humbug/php-scoper#whitelist
|
||||
*/
|
||||
'whitelist-global-constants' => false,
|
||||
'whitelist-global-classes' => false,
|
||||
'whitelist' => [ 'FALSE', 'NULL' ],
|
||||
);
|
||||
Reference in New Issue
Block a user