-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from moderntribe/feature/xdebug-command
Feature/xdebug command
- Loading branch information
Showing
6 changed files
with
1,208 additions
and
510 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
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php declare( strict_types=1 ); | ||
|
||
namespace App\Commands\LocalDocker; | ||
|
||
use App\Commands\DockerCompose; | ||
use App\Services\Docker\Local\Config; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
/** | ||
* Enable/Disable Xdebug in the php-fpm container. | ||
* | ||
* @package App\Commands\LocalDocker | ||
*/ | ||
class Xdebug extends BaseLocalDocker { | ||
|
||
/** | ||
* The path to the xdebug.ini in the container. | ||
*/ | ||
public const XDEBUG_CONFIG_PATH = '/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini'; | ||
|
||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'xdebug {action? : on|off}'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Enable/disable Xdebug in the php-fpm container to increase performance on MacOS'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @param \App\Services\Docker\Local\Config $config | ||
* | ||
* @return int | ||
*/ | ||
public function handle( Config $config ) { | ||
$action = $this->argument( 'action' ); | ||
|
||
chdir( $config->getDockerDir() ); | ||
|
||
if ( empty( $action ) ) { | ||
$result = Artisan::call( DockerCompose::class, [ | ||
'--project-name', | ||
$config->getProjectName(), | ||
'exec', | ||
'--user', | ||
'root', | ||
'php-fpm', | ||
'bash', | ||
'-c', | ||
sprintf( '[[ -f %s ]]', self::XDEBUG_CONFIG_PATH ), | ||
] ); | ||
|
||
if ( self::EXIT_SUCCESS === $result ) { | ||
$this->info( 'xdebug is on' ); | ||
} else { | ||
$this->info( 'xdebug is off' ); | ||
} | ||
|
||
return self::EXIT_SUCCESS; | ||
} | ||
|
||
if ( 'on' === $action ) { | ||
$this->enable( $config ); | ||
$this->reload( $config ); | ||
$this->info( 'xdebug enabled' ); | ||
} elseif ( 'off' === $action ) { | ||
$this->disable( $config ); | ||
$this->reload( $config ); | ||
$this->info( 'xdebug disabled' ); | ||
} else { | ||
$this->error( sprintf( 'Invalid argument: %s. Allowed values: on|off', $action ) ); | ||
} | ||
|
||
return self::EXIT_SUCCESS; | ||
} | ||
|
||
/** | ||
* Enable xdebug by renaming the .ini file. | ||
* | ||
* @param \App\Services\Docker\Local\Config $config | ||
*/ | ||
protected function enable( Config $config ): void { | ||
Artisan::call( DockerCompose::class, [ | ||
'--project-name', | ||
$config->getProjectName(), | ||
'exec', | ||
'-T', | ||
'--user', | ||
'root', | ||
'php-fpm', | ||
'mv', | ||
sprintf( '%s', self::XDEBUG_CONFIG_PATH . '.disabled' ), | ||
sprintf( '%s', self::XDEBUG_CONFIG_PATH ), | ||
] ); | ||
} | ||
|
||
/** | ||
* Disable xdebug by renaming the .ini file back. | ||
* | ||
* @param \App\Services\Docker\Local\Config $config | ||
*/ | ||
protected function disable( Config $config ): void { | ||
Artisan::call( DockerCompose::class, [ | ||
'--project-name', | ||
$config->getProjectName(), | ||
'exec', | ||
'-T', | ||
'--user', | ||
'root', | ||
'php-fpm', | ||
'mv', | ||
sprintf( '%s', self::XDEBUG_CONFIG_PATH ), | ||
sprintf( '%s', self::XDEBUG_CONFIG_PATH . '.disabled' ), | ||
] ); | ||
} | ||
|
||
/** | ||
* Reload PHP in the container. | ||
* | ||
* @param \App\Services\Docker\Local\Config $config | ||
*/ | ||
protected function reload( Config $config ): void { | ||
Artisan::call( DockerCompose::class, [ | ||
'--project-name', | ||
$config->getProjectName(), | ||
'exec', | ||
'--user', | ||
'root', | ||
'php-fpm', | ||
'kill', | ||
'-USR2', | ||
'1', | ||
] ); | ||
} | ||
|
||
} |
Oops, something went wrong.