diff --git a/src/Commands/OAuthSetup.php b/src/Commands/OAuthSetup.php new file mode 100644 index 0000000..968c97a --- /dev/null +++ b/src/Commands/OAuthSetup.php @@ -0,0 +1,101 @@ + + */ + protected $options = [ + '-f' => 'Force overwrite ALL existing files in destination.', + ]; + + /** + * The path to `Datamweb\ShieldOAuth\` src directory. + * + * @var string + */ + protected $sourcePath; + + protected $distPath = APPPATH; + private ContentReplacer $replacer; + + /** + * Displays the help for the spark cli script itself. + */ + public function run(array $params): void + { + $this->replacer = new ContentReplacer(); + + $this->sourcePath = __DIR__ . '/../'; + + $file = 'Config/ShieldOAuthConfig.php'; + $replaces = [ + 'namespace Datamweb\ShieldOAuth\Config;' => 'namespace Config;', + 'use CodeIgniter\\Config\\BaseConfig;' => 'use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig as OAuthConfig;', + 'extends BaseConfig' => 'extends OAuthConfig', + ]; + + $this->copyAndReplace($file, $replaces); + } + + /** + * @param string $file Relative file path like 'Config/ShieldOAuthConfig.php'. + * @param array $replaces [search => replace] + */ + protected function copyAndReplace(string $file, array $replaces): void + { + $path = "{$this->sourcePath}/{$file}"; + + $content = file_get_contents($path); + + $content = $this->replacer->replace($content, $replaces); + + $this->writeFile($file, $content); + } + +}