forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
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 pkp#9918 from touhidurabir/i9895_main
pkp#9895 app key and encryption service provider attached to container
- Loading branch information
Showing
19 changed files
with
870 additions
and
205 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/cliTool/CommandInterface.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @trait CommandInterface | ||
* | ||
* @brief Class to provide IO interface on CLI | ||
*/ | ||
|
||
namespace PKP\cliTool; | ||
|
||
use Illuminate\Console\Concerns\InteractsWithIO; | ||
use Illuminate\Console\OutputStyle; | ||
use Symfony\Component\Console\Input\StringInput; | ||
use Symfony\Component\Console\Output\StreamOutput; | ||
|
||
class CommandInterface | ||
{ | ||
use InteractsWithIO; | ||
|
||
public function __construct() | ||
{ | ||
$output = new OutputStyle( | ||
new StringInput(''), | ||
new StreamOutput(fopen('php://stdout', 'w')) | ||
); | ||
|
||
$this->setOutput($output); | ||
} | ||
|
||
public function errorBlock(array $messages = [], ?string $title = null): void | ||
{ | ||
$this->getOutput()->block( | ||
$messages, | ||
$title, | ||
'fg=white;bg=red', | ||
' ', | ||
true | ||
); | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/cliTool/traits/HasCommandInterface.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @trait HasCommandInterface | ||
* | ||
* @brief A helper trait for CLI tools that provide functionality to read/write on CLI interface | ||
*/ | ||
|
||
namespace PKP\cliTool\traits; | ||
|
||
use PKP\cliTool\CommandInterface; | ||
use Symfony\Component\Console\Helper\Helper; | ||
|
||
trait HasCommandInterface | ||
{ | ||
/** | ||
* CLI interface, this object should extends InteractsWithIO | ||
*/ | ||
protected ?CommandInterface $commandInterface = null; | ||
|
||
/** | ||
* Set the command interface | ||
*/ | ||
public function setCommandInterface(?CommandInterface $commandInterface = null): self | ||
{ | ||
$this->commandInterface = $commandInterface ?? new CommandInterface; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the command interface | ||
*/ | ||
public function getCommandInterface(): CommandInterface | ||
{ | ||
return $this->commandInterface; | ||
} | ||
|
||
/** | ||
* Print given options in a pretty way. | ||
*/ | ||
protected function printCommandList(array $options, bool $shouldTranslate = true): void | ||
{ | ||
$width = (int)collect(array_keys($options)) | ||
->map(fn($command) => Helper::width($command)) | ||
->sort() | ||
->last() + 2; | ||
|
||
foreach ($options as $commandName => $description) { | ||
$spacingWidth = $width - Helper::width($commandName); | ||
$this->getCommandInterface()->line( | ||
sprintf( | ||
' <info>%s</info>%s%s', | ||
$commandName, | ||
str_repeat(' ', $spacingWidth), | ||
$shouldTranslate ? __($description) : $description | ||
) | ||
); | ||
} | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/cliTool/traits/HasParameterList.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @trait HasParameterList | ||
* | ||
* @brief A helper trait manage the params and flags on CLI interface | ||
*/ | ||
|
||
namespace PKP\cliTool\traits; | ||
|
||
trait HasParameterList | ||
{ | ||
/** | ||
* Parameters and arguments from CLI | ||
*/ | ||
protected ?array $parameterList = null; | ||
|
||
/** | ||
* Save the parameter list passed on CLI | ||
* | ||
* @param array $items Array with parameters and arguments passed on CLI | ||
*/ | ||
public function setParameterList(array $items): static | ||
{ | ||
$parameters = []; | ||
|
||
foreach ($items as $param) { | ||
if (strpos($param, '=')) { | ||
[$key, $value] = explode('=', ltrim($param, '-')); | ||
$parameters[$key] = $value; | ||
|
||
continue; | ||
} | ||
|
||
$parameters[] = $param; | ||
} | ||
|
||
$this->parameterList = $parameters; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the parameter list passed on CLI | ||
*/ | ||
public function getParameterList(): ?array | ||
{ | ||
return $this->parameterList; | ||
} | ||
|
||
/** | ||
* Get the value of a specific parameter | ||
*/ | ||
protected function getParameterValue(string $parameter, mixed $default = null): mixed | ||
{ | ||
if (!isset($this->getParameterList()[$parameter])) { | ||
return $default; | ||
} | ||
|
||
return $this->getParameterList()[$parameter]; | ||
} | ||
|
||
/** | ||
* Determined if the given flag set on CLI | ||
*/ | ||
protected function hasFlagSet(string $flag): bool | ||
{ | ||
return in_array($flag, $this->getParameterList()); | ||
} | ||
} |
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
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
Oops, something went wrong.