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

PHP 8.2 and Symfony 7.2 compatible #134

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ matrix:
env:
- SYMFONY_VERSION="5.0.*"
- CHECK_PHP_SYNTAX="yes"
- php: 8.2
env:
- SYMFONY_VERSION="6.2.*"
- CHECK_PHP_SYNTAX="yes"
allow_failures:
- php: nightly

Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "easycorp/easy-deploy-bundle",
"name": "gangsidestep/easy-deploy-bundle",
"type": "symfony-bundle",
"description": "The easiest way to deploy Symfony applications",
"keywords": ["deploy", "deployment", "deployer"],
Expand All @@ -12,15 +12,15 @@
}
],
"require": {
"php": ">=7.2.0",
"symfony/console": "~2.3|~3.0|~4.0|~5.0",
"symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0",
"symfony/expression-language": "~2.4|~3.0|~4.0|~5.0",
"symfony/filesystem": "~2.3|~3.0|~4.0|~5.0",
"symfony/http-foundation": "~2.3|~3.0|~4.0|~5.0",
"symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0",
"php": ">=8.2",
"symfony/console": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/expression-language": "~2.4|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/filesystem": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/http-foundation": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2",
"symfony/polyfill-mbstring": "^1.3",
"symfony/process": "~2.3|~3.0|~4.0|~5.0"
"symfony/process": "~2.3|~3.0|~4.0|~5.0|~6.2|~7.2"
},
"require-dev": {
"phpunit/phpunit": "^6.1"
Expand Down
8 changes: 2 additions & 6 deletions src/Command/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@

class DeployCommand extends Command
{
private $fileLocator;
private $projectDir;
private $logDir;
private $configFilePath;

public function __construct(FileLocator $fileLocator, string $projectDir, string $logDir)
public function __construct(private readonly FileLocator $fileLocator, string $projectDir, private readonly string $logDir)
{
$this->fileLocator = $fileLocator;
$this->projectDir = realpath($projectDir);
$this->logDir = $logDir;

parent::__construct();
}
Expand Down Expand Up @@ -69,7 +65,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->createDefaultConfigFile($input, $output, $defaultConfigPath, $input->getArgument('stage'));
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
Expand Down
9 changes: 2 additions & 7 deletions src/Command/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@

class RollbackCommand extends Command
{
private $projectDir;
private $logDir;
private $configFilePath;

public function __construct(string $projectDir, string $logDir)
public function __construct(private readonly string $projectDir, private readonly string $logDir)
{
$this->projectDir = $projectDir;
$this->logDir = $logDir;

parent::__construct();
}

Expand Down Expand Up @@ -64,7 +59,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath));
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
Expand Down
11 changes: 4 additions & 7 deletions src/Configuration/ConfigurationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
* in a consistent manner, even if the configuration of each deployer is
* completely different and defined using incompatible objects.
*/
final class ConfigurationAdapter
final class ConfigurationAdapter implements \Stringable
{
private $config;
/** @var ParameterBag */
private $options;
private ?ParameterBag $options = null;

public function __construct(AbstractConfiguration $config)
public function __construct(private readonly AbstractConfiguration $config)
{
$this->config = $config;
}

public function __toString(): string
Expand Down Expand Up @@ -60,7 +57,7 @@ private function getOptions(): ParameterBag
try {
$property->setAccessible(true);
$options->set($property->getName(), $property->getValue($this->config));
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
// ignore this error
}
}
Expand Down
74 changes: 35 additions & 39 deletions src/Configuration/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,45 @@
final class DefaultConfiguration extends AbstractConfiguration
{
// variables starting with an underscore are for internal use only
private $_symfonyEnvironmentEnvVarName; // SYMFONY_ENV or APP_ENV
private ?string $_symfonyEnvironmentEnvVarName = null; // SYMFONY_ENV or APP_ENV

// properties are defined as private so the developer doesn't see them when using
// their IDE autocompletion. To simplify things, the builder defines setter
// methods named the same as each option.
private $symfonyEnvironment = 'prod';
private $keepReleases = 5;
private $repositoryUrl;
private $repositoryBranch = 'master';
private $remotePhpBinaryPath = 'php';
private $updateRemoteComposerBinary = false;
private $remoteComposerBinaryPath = '/usr/local/bin/composer';
private $composerInstallFlags = '--no-dev --prefer-dist --no-interaction --quiet';
private $composerOptimizeFlags = '--optimize';
private $installWebAssets = true;
private $dumpAsseticAssets = false;
private $warmupCache = true;
private $consoleBinaryPath;
private $localProjectDir;
private $binDir;
private $configDir;
private $cacheDir;
private $deployDir;
private $logDir;
private $srcDir;
private $templatesDir;
private $webDir;
private $controllersToRemove = [];
private $writableDirs = [];
private $permissionMethod = 'chmod';
private $permissionMode = '0777';
private $permissionUser;
private $permissionGroup;
private $sharedFiles = [];
private $sharedDirs = [];
private $resetOpCacheFor;

public function __construct(string $localProjectDir)
private string $symfonyEnvironment = 'prod';
private int $keepReleases = 5;
private ?string $repositoryUrl = null;
private string $repositoryBranch = 'master';
private string $remotePhpBinaryPath = 'php';
private bool $updateRemoteComposerBinary = false;
private string $remoteComposerBinaryPath = '/usr/local/bin/composer';
private string $composerInstallFlags = '--no-dev --prefer-dist --no-interaction --quiet';
private string $composerOptimizeFlags = '--optimize';
private bool $installWebAssets = true;
private bool $dumpAsseticAssets = false;
private bool $warmupCache = true;
private ?string $consoleBinaryPath = null;
private ?string $binDir = null;
private ?string $configDir = null;
private ?string $cacheDir = null;
private ?string $deployDir = null;
private ?string $logDir = null;
private ?string $srcDir = null;
private ?string $templatesDir = null;
private ?string $webDir = null;
private array $controllersToRemove = [];
private array $writableDirs = [];
private string $permissionMethod = 'chmod';
private string $permissionMode = '0777';
private ?string $permissionUser = null;
private ?string $permissionGroup = null;
private array $sharedFiles = [];
private array $sharedDirs = [];
private ?string $resetOpCacheFor = null;

public function __construct(private readonly string $localProjectDir)
{
parent::__construct();
$this->localProjectDir = $localProjectDir;
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
}

Expand Down Expand Up @@ -264,9 +262,7 @@ public function webDir(string $path): self
// the $paths can be glob() patterns, so this method needs to resolve them
public function controllersToRemove(array $paths): self
{
$absoluteGlobPaths = array_map(function ($globPath) {
return $this->localProjectDir.DIRECTORY_SEPARATOR.$globPath;
}, $paths);
$absoluteGlobPaths = array_map(fn($globPath) => $this->localProjectDir.DIRECTORY_SEPARATOR.$globPath, $paths);

$localAbsolutePaths = [];
foreach ($absoluteGlobPaths as $path) {
Expand Down Expand Up @@ -337,7 +333,7 @@ public function sharedFilesAndDirs(array $paths = []): self
foreach ($paths as $path) {
$this->validatePathIsRelativeToProject($path, __METHOD__);
if (is_dir($this->localProjectDir.DIRECTORY_SEPARATOR.$path)) {
$this->sharedDirs[] = rtrim($path, DIRECTORY_SEPARATOR);
$this->sharedDirs[] = rtrim((string) $path, DIRECTORY_SEPARATOR);
} else {
$this->sharedFiles[] = $path;
}
Expand Down
66 changes: 33 additions & 33 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@
*/
final class Option
{
const binDir = 'binDir';
const cacheDir = 'cacheDir';
const composerInstallFlags = 'composerInstallFlags';
const composerOptimizeFlags = 'composerOptimizeFlags';
const configDir = 'configDir';
const consoleBinaryPath = 'consoleBinaryPath';
const context = 'context';
const controllersToRemove = 'controllersToRemove';
const deployDir = 'deployDir';
const dumpAsseticAssets = 'dumpAsseticAssets';
const installWebAssets = 'installWebAssets';
const keepReleases = 'keepReleases';
const logDir = 'logDir';
const permissionMethod = 'permissionMethod';
const permissionMode = 'permissionMode';
const permissionUser = 'permissionUser';
const permissionGroup = 'permissionGroup';
const remotePhpBinaryPath = 'remotePhpBinaryPath';
const remoteComposerBinaryPath = 'remoteComposerBinaryPath';
const repositoryBranch = 'repositoryBranch';
const repositoryUrl = 'repositoryUrl';
const resetOpCacheFor = 'resetOpCacheFor';
const servers = 'servers';
const sharedFiles = 'sharedFiles';
const sharedDirs = 'sharedDirs';
const srcDir = 'srcDir';
const symfonyEnvironment = 'symfonyEnvironment';
const templatesDir = 'templatesDir';
const updateRemoteComposerBinary = 'updateRemoteComposerBinary';
const useSshAgentForwarding = 'useSshAgentForwarding';
const warmupCache = 'warmupCache';
const webDir = 'webDir';
const writableDirs = 'writableDirs';
public const binDir = 'binDir';
public const cacheDir = 'cacheDir';
public const composerInstallFlags = 'composerInstallFlags';
public const composerOptimizeFlags = 'composerOptimizeFlags';
public const configDir = 'configDir';
public const consoleBinaryPath = 'consoleBinaryPath';
public const context = 'context';
public const controllersToRemove = 'controllersToRemove';
public const deployDir = 'deployDir';
public const dumpAsseticAssets = 'dumpAsseticAssets';
public const installWebAssets = 'installWebAssets';
public const keepReleases = 'keepReleases';
public const logDir = 'logDir';
public const permissionMethod = 'permissionMethod';
public const permissionMode = 'permissionMode';
public const permissionUser = 'permissionUser';
public const permissionGroup = 'permissionGroup';
public const remotePhpBinaryPath = 'remotePhpBinaryPath';
public const remoteComposerBinaryPath = 'remoteComposerBinaryPath';
public const repositoryBranch = 'repositoryBranch';
public const repositoryUrl = 'repositoryUrl';
public const resetOpCacheFor = 'resetOpCacheFor';
public const servers = 'servers';
public const sharedFiles = 'sharedFiles';
public const sharedDirs = 'sharedDirs';
public const srcDir = 'srcDir';
public const symfonyEnvironment = 'symfonyEnvironment';
public const templatesDir = 'templatesDir';
public const updateRemoteComposerBinary = 'updateRemoteComposerBinary';
public const useSshAgentForwarding = 'useSshAgentForwarding';
public const warmupCache = 'warmupCache';
public const webDir = 'webDir';
public const writableDirs = 'writableDirs';
}
19 changes: 3 additions & 16 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,12 @@
* It implements the "Context Object" pattern to encapsulate the global state of
* the deployment in an immutable object.
*/
class Context
class Context implements \Stringable
{
private $localHost;
private $dryRun;
private $debug;
private $input;
private $output;
private $projectDir;
private $logFilePath;
private readonly Server $localHost;

public function __construct(InputInterface $input, OutputInterface $output, string $projectDir, string $logFilePath, bool $isDryRun, bool $isVerbose)
public function __construct(private readonly InputInterface $input, private readonly OutputInterface $output, private readonly string $projectDir, private readonly string $logFilePath, private readonly bool $dryRun, private readonly bool $debug)
{
$this->input = $input;
$this->output = $output;
$this->projectDir = $projectDir;
$this->logFilePath = $logFilePath;
$this->dryRun = $isDryRun;
$this->debug = $isVerbose;

$this->localHost = $this->createLocalHost();
}

Expand Down
12 changes: 4 additions & 8 deletions src/Deployer/AbstractDeployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@

abstract class AbstractDeployer
{
/** @var Context */
private $context;
/** @var TaskRunner */
private $taskRunner;
/** @var Logger */
private $logger;
/** @var ConfigurationAdapter */
private $config;
private ?Context $context = null;
private ?TaskRunner $taskRunner = null;
private ?Logger $logger = null;
private ?ConfigurationAdapter $config = null;

abstract public function getRequirements(): array;

Expand Down
Loading