-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove stub that was previously used for PHP < 7
- Loading branch information
Showing
5 changed files
with
96 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,98 @@ | ||
<?php | ||
/** | ||
* Compatibility stub for Symfony 6 changes. | ||
* | ||
* Symfony 6 (for PHP 8.0+) added return type hints to its interface. But we still support PHP 7.0, which doesn't recognize that syntax. | ||
* Since specifying a return type when the interface doesn't is ok, use the version that always does that for PHP 7+ instead of figuring | ||
* out how to check the actual symfony version. | ||
* Command loader for the changelogger tool CLI. | ||
* | ||
* @package automattic/jetpack-changelogger | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Changelogger; | ||
namespace Automattic\Jetpack\Changelogger\php7; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; | ||
use Symfony\Component\Console\Exception\CommandNotFoundException; | ||
|
||
/** | ||
* Command loader for the changelogger tool CLI. | ||
*/ | ||
class CommandLoader implements CommandLoaderInterface { | ||
/** | ||
* Get the class name for a command. | ||
* | ||
* @param string $name Command name. | ||
* @return string Class name. | ||
*/ | ||
private function get_class_name( $name ) { | ||
return __NAMESPACE__ . '\\' . ucfirst( $name ) . 'Command'; | ||
} | ||
|
||
/** | ||
* Checks if a command exists. | ||
* | ||
* @param string $name Command name. | ||
* @return bool | ||
*/ | ||
protected function doHas( $name ) { | ||
return class_exists( $this->get_class_name( $name ) ); | ||
} | ||
|
||
/** | ||
* Loads a command. | ||
* | ||
* @param string $name Command name. | ||
* @return Command | ||
* @throws CommandNotFoundException If the command is not found. | ||
*/ | ||
protected function doGet( $name ) { | ||
$class = $this->get_class_name( $name ); | ||
if ( ! class_exists( $class ) ) { | ||
throw new CommandNotFoundException( "Command \"$name\" does not exist." ); | ||
} | ||
return new $class(); | ||
} | ||
|
||
/** | ||
* Return all command names. | ||
* | ||
* @return string[] All registered command names | ||
*/ | ||
protected function doGetNames() { | ||
$names = array(); | ||
foreach ( new \DirectoryIterator( __DIR__ ) as $file ) { | ||
if ( substr( $file->getBasename(), -11 ) === 'Command.php' ) { | ||
$names[] = lcfirst( substr( $file->getBasename(), 0, -11 ) ); | ||
} | ||
} | ||
sort( $names ); | ||
return $names; | ||
} | ||
|
||
/** | ||
* Checks if a command exists. | ||
* | ||
* @param string $name Command name. | ||
* @return bool | ||
*/ | ||
public function has( $name ): bool { | ||
return $this->doHas( $name ); | ||
} | ||
|
||
/** | ||
* Loads a command. | ||
* | ||
* @param string $name Command name. | ||
* @return Command | ||
* @throws CommandNotFoundException If the command is not found. | ||
*/ | ||
public function get( $name ): Command { | ||
return $this->doGet( $name ); | ||
} | ||
|
||
class_alias( php7\CommandLoader::class, CommandLoader::class ); | ||
/** | ||
* Return all command names. | ||
* | ||
* @return string[] All registered command names | ||
*/ | ||
public function getNames(): array { | ||
return $this->doGetNames(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
projects/packages/changelogger/src/php7/.phpcs.dir.phpcompatibility.xml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.