-
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #716 from rgasch/publications-feature
Committing code to 'tag' field type.
- Loading branch information
Showing
10 changed files
with
403 additions
and
267 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
packages/framework/src/Console/Commands/MakePublicationTagCommand.php
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Console\Commands; | ||
|
||
use Hyde\Console\Commands\Interfaces\CommandHandleInterface; | ||
use Hyde\Console\Concerns\ValidatingCommand; | ||
use Hyde\Framework\Features\Publications\PublicationService; | ||
use Hyde\Hyde; | ||
use Illuminate\Support\Str; | ||
use LaravelZero\Framework\Commands\Command; | ||
use function Safe\file_put_contents; | ||
use function Safe\json_encode; | ||
|
||
/** | ||
* Hyde Command to create a new publication type. | ||
* | ||
* @see \Hyde\Framework\Testing\Feature\Commands\MakePublicationTypeCommandTest | ||
*/ | ||
class MakePublicationTagCommand extends ValidatingCommand implements CommandHandleInterface | ||
{ | ||
/** @var string */ | ||
protected $signature = 'make:publicationTag'; | ||
|
||
/** @var string */ | ||
protected $description = 'Create a new publication type tag definition'; | ||
|
||
public function handle(): int | ||
{ | ||
$this->title('Creating a new Publication Type Tag!'); | ||
|
||
$filename = Hyde::pathToRelative('tags.json'); | ||
$tags = PublicationService::getAllTags(); | ||
$tagName = $this->askWithValidation('name', 'Tag name', ['required', 'string']); | ||
if (isset($tags[$tagName])) { | ||
$this->output->error("Tag [$tagName] already exists"); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
$lines = []; | ||
$this->output->writeln('<bg=magenta;fg=white>Enter the tag values (end with an empty line):</>'); | ||
do { | ||
$line = Str::replace(["\n", "\r"], '', fgets(STDIN)); | ||
if ($line === '') { | ||
break; | ||
} | ||
$lines[] = trim($line); | ||
} while (true); | ||
$tags[$tagName] = $lines; | ||
|
||
$this->output->writeln(sprintf('Saving tag data to [%s]', $filename)); | ||
file_put_contents($filename, json_encode($tags, JSON_PRETTY_PRINT)); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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
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.