Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
95d734a
Added event/extension support to base command
jaxwilko Dec 19, 2024
5d60632
Added support for module service provider instances to be bound to th…
jaxwilko Dec 19, 2024
93882da
Migrated code from winter to storm
jaxwilko Dec 20, 2024
407e842
Added local remember function to avoid system cache
jaxwilko Jan 4, 2025
48eddec
Added base methods for modules to inherit
jaxwilko Jan 4, 2025
b1d4f06
Added packager to storm deps
jaxwilko Jan 4, 2025
6b03b16
Added identifier and path logic to module provider
jaxwilko Jan 5, 2025
43f0339
Added method for retrieving packages from composer api
jaxwilko Jan 6, 2025
ce22bcf
Update src/Console/Command.php
jaxwilko Mar 12, 2025
6071790
Update src/Console/Command.php
jaxwilko Mar 12, 2025
1faeaf0
Manual merge develop
jaxwilko Jul 9, 2025
156529d
Added fix for symfony compatibility
jaxwilko Jul 9, 2025
d8f6d8b
Added helper to composer to allow fetching of installed winter packag…
jaxwilko Jul 28, 2025
eaf25e1
Merge branch 'develop' into wip/support-uploading-packages-update-man…
LukeTowers Jul 28, 2025
1ce4f4b
Update src/Console/Command.php
LukeTowers Jul 28, 2025
90ba47a
Revert change to HandlesCleanup
LukeTowers Jul 28, 2025
ecafe94
Cleanup
LukeTowers Jul 28, 2025
6c2872c
Fixes for latest version of packager
LukeTowers Jul 28, 2025
835d803
Added useful data to return from getAvailableUpdates
jaxwilko Jul 28, 2025
82c251d
Added fixes for show command
jaxwilko Jul 28, 2025
3a6a7e1
Added fix to prevent empty data being cached and removed the show com…
jaxwilko Jul 28, 2025
699951e
Added fixes to command and added helper for updating package version …
jaxwilko Aug 1, 2025
1dd8e84
Update src/Packager/Commands/InfoCommand.php
LukeTowers Aug 6, 2025
b0de374
Remove unnecessary packager overrides
LukeTowers Aug 6, 2025
0803397
Remove unused Search command
LukeTowers Aug 6, 2025
6f2b4f7
Replace customized RequireCommand with Composer::getLatestSupportedVe…
LukeTowers Aug 6, 2025
2f6f264
Remove customized Update command
LukeTowers Aug 6, 2025
4d90597
Update composer.json
LukeTowers Aug 6, 2025
acc4eef
Rename command beforeRun local event to command.beforeRun and documen…
LukeTowers Aug 6, 2025
b34c72f
Merge branch 'wip/support-uploading-packages-update-manager-changes' …
LukeTowers Aug 6, 2025
dc4b910
Update imports
LukeTowers Aug 6, 2025
bdbb0a0
Update src/Packager/Composer.php
LukeTowers Aug 7, 2025
4e93a98
Move listPackages to Bazaar
LukeTowers Aug 7, 2025
6f0b906
Merge branch 'wip/support-uploading-packages-update-manager-changes' …
LukeTowers Aug 7, 2025
d1aa548
Tidying
LukeTowers Aug 7, 2025
79abfb7
Static analysis fixes
LukeTowers Aug 7, 2025
969a1a7
Tidying
LukeTowers Aug 8, 2025
2594bdf
Improve performance of working with Composer
LukeTowers Aug 8, 2025
ad5ca6c
Fix getting composer package version
LukeTowers Aug 8, 2025
55ef0af
Fix usage of composer
LukeTowers Aug 8, 2025
4760936
Fix PHP Stan
LukeTowers Aug 8, 2025
cb77bd5
Update src/Support/ModuleServiceProvider.php
LukeTowers Aug 13, 2025
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
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"twig/twig": "^3.14",
"wikimedia/less.php": "^5.0",
"wikimedia/minify": "~2.2",
"winter/laravel-config-writer": "^1.0.1"
"winter/laravel-config-writer": "^1.0.1",
"winter/packager": "^0.4.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5.8",
Expand Down Expand Up @@ -99,5 +100,10 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
Comment on lines +104 to +108
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully we can eliminate the need for this.

}
137 changes: 136 additions & 1 deletion src/Console/Command.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
<?php namespace Winter\Storm\Console;
<?php

namespace Winter\Storm\Console;

use Illuminate\Console\Command as BaseCommand;
use Illuminate\Console\OutputStyle;
use Illuminate\Console\View\Components\Factory;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Command\SignalableCommandInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Termwind\Termwind;
use Winter\Storm\Extension\ExtendableTrait;
use Winter\Storm\Support\Traits\Emitter;
use function Termwind\renderUsing;

/**
* Command base class
* Contains utilities to make developing CLI commands nicer
*
* @author Luke Towers
*
* @method static mixed extend(callable $callback, bool $scoped = false, ?object $outerScope = null)
*/
abstract class Command extends BaseCommand implements PromptsForMissingInput, SignalableCommandInterface
{
use Traits\HandlesCleanup;
use Traits\ProvidesAutocompletion;
use ExtendableTrait;
use Emitter;

/**
* @var string|array|null Extensions implemented by this class.
*/
public $implement = null;

/**
* @var \Winter\Storm\Foundation\Application
Expand All @@ -35,6 +55,56 @@ public function __construct()
if (!empty($this->replaces)) {
$this->setAliases($this->replaces);
}

$this->extendableConstruct();
}

/**
* Override the laravel run function to allow us to run callbacks on the command prior to excution.
* Run the console command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
public function run(InputInterface $input, OutputInterface $output): int
{
$this->output = $this->laravel->make(
OutputStyle::class,
['input' => $input, 'output' => $output]
);

$this->components = $this->laravel->make(Factory::class, ['output' => $this->output]);

/**
* @event command.beforeRun
* Called before the command is run; useful for intercepting the output of the command or auditing the commands run
*
* Example usage:
*
* Command::extend(function (Command $command) {
* $command->bindEvent('command.beforeRun', function () use ($command) {
* MyTaskManager::instance()->setOutput($command->getOutput());
* });
* });
*
*/
$this->fireEvent('command.beforeRun', [$this]);

$renderer = Termwind::getRenderer();
renderUsing($this->output->getOutput());

try {
// Calling the grandparent run() method, see: https://www.php.net/manual/en/language.oop5.inheritance.php#100005
return SymfonyCommand::run(
$this->input = $input,
$this->output
);
} finally {
$this->untrap();
// Restore the original termwind renderer
renderUsing($renderer);
}
}

/**
Expand All @@ -60,4 +130,69 @@ public function error($string, $verbosity = null)
{
$this->components->error($string, $this->parseVerbosity($verbosity));
}

/**
* Magic allowing for extendable properties
*
* @param $name
* @return mixed|null
*/
public function __get($name)
{
return $this->extendableGet($name);
}

/**
* Magic allowing for extendable properties
*
* @param $name
* @param $value
* @return void
*/
public function __set($name, $value)
{
$this->extendableSet($name, $value);
}

/**
* Magic allowing for dynamic extension
*
* @param $name
* @param $params
* @return mixed
*/
public function __call($name, $params)
{
if ($name === 'extend') {
if (empty($params[0]) || !is_callable($params[0])) {
throw new \InvalidArgumentException('The extend() method requires a callback parameter or closure.');
}
if ($params[0] instanceof \Closure) {
return $params[0]->call($this, $params[1] ?? $this);
}
return \Closure::fromCallable($params[0])->call($this, $params[1] ?? $this);
}

return $this->extendableCall($name, $params);
}

/**
* Magic allowing for dynamic static extension
*
* @param $name
* @param $params
* @return mixed|void
*/
public static function __callStatic($name, $params)
{
if ($name === 'extend') {
if (empty($params[0])) {
throw new \InvalidArgumentException('The extend() method requires a callback parameter or closure.');
}
self::extendableExtendCallback($params[0], $params[1] ?? false, $params[2] ?? null);
return;
}

return parent::__callStatic($name, $params);
}
}
16 changes: 16 additions & 0 deletions src/Foundation/Extension/WinterExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Winter\Storm\Foundation\Extension;

interface WinterExtension
{
public function getPath(): string;

public function getVersion(): string;

public function getIdentifier(): string;

public function getComposerPackageName(): ?string;

public function getComposerPackageVersion(): ?string;
}
Loading
Loading