Skip to content

Commit

Permalink
init Please, cmd to auto-doc Facades, console kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
donwilson committed Sep 11, 2023
1 parent b8e5fcd commit 26b06f3
Show file tree
Hide file tree
Showing 20 changed files with 809 additions and 169 deletions.
31 changes: 0 additions & 31 deletions src/Magnetar/Console/ArgvInput.php

This file was deleted.

23 changes: 23 additions & 0 deletions src/Magnetar/Console/ErrorOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Magnetar\Console;

use \Exception;

use Magnetar\Console\Output;

/**
* Command line output error
*/
class ErrorOutput extends Output {
/**
* Constructor
* @param string|null|null $data The result data from a command line execution
*/
public function __construct(
protected string|null $data=null
) {

}
}
121 changes: 117 additions & 4 deletions src/Magnetar/Console/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,126 @@
* Command line input
*/
class Input {
/**
* Script name
* @var string|null
*/
protected string|null $script_name = null;

/**
* The command line arguments (that aren't flags) that were passed
* @var array Simple array of arguments
*/
protected array $arguments = [];

/**
* The command line flags (eg: -f, --flag)
* @var array Assoc array of flag name => value|true
*/
protected array $flags = [];

/**
* Constructor
* @param array $arguments Command line arguments
* @param array|null $arguments Array of arguments from a $argv-like source or null to use the default $_SERVER['argv']
*/
public function __construct(array|null $arguments=null) {
$arguments ??= $_SERVER['argv'] ?? [];

// parse the arguments
$this->parseArguments($arguments);
}

/**
* Parse the raw arguments array into key/value flags and basic arguments
* @param array $args The raw list of arguments from the command line
* @return void
*/
public function __construct(
protected array $arguments=[]
) {
protected function parseArguments(?array $args): void {
$this->script_name = array_shift($arguments);

foreach($args as $arg) {
if('' === ($arg = trim($arg))) {
continue;
}

// check if it's a flag or argument
if(preg_match("#^(\-|\-\-)([A-Za-z0-9\-_]+)#si", $arg, $arg_match)) {
$flag_name = ltrim($arg_match[2], '-');

if(false !== strpos($flag_name, '=')) {
// key value pair

// flag example: -f=value
// long flag example: --flag=value

[ $flag_name, $flag_value ] = explode('=', $flag_name, 2);

$flag_value = $flag_value;
} else {
// boolean flag

// flag example: -f
// long flag example: --flag

$flag_value = true;
}

$this->flags[ trim($flag_name) ] = $flag_value;
} else {
// argument
$this->arguments[] = trim($arg);
}
}
}

/**
* Get the script name from the command line input
* @return string|null The script name or null if not set
*/
public function getScriptName(): string|null {
return $this->script_name;
}

/**
* Get the arguments
* @return array The command line arguments
*/
public function getArguments(): array {
return $this->arguments;
}

/**
* Get a command line argument by index
* @param int $index The index of the argument
* @return mixed The argument string or null if not set
*/
public function getArgument(int $index): mixed {
return $this->arguments[ $index ] ?? null;
}

/**
* Determine if an argument exists
* @param int $index The index of the argument
* @return mixed The value of the argument or null if not set
*/
public function hasArgument(string $argument): bool {
return in_array($argument, $this->arguments);
}

/**
* Get the defined flags
* @return array The flags as an assoc array of flag name => value|true
*/
public function getFlags(): array {
return $this->flags;
}

/**
* Get a command line flag's value
* @param string $flag_name The value of the flag. eg: f for -f, flag for --flag
* @return mixed The value of the flag or null if not set
*/
public function getFlag(string $flag_name): mixed {
return $this->flags[ $flag_name ] ?? null;
}
}
133 changes: 82 additions & 51 deletions src/Magnetar/Helpers/Facades/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,88 @@
use Magnetar\Helpers\Facades\Facade;

/**
* @method setBasePath(string $base_path): void
* @method basePath(string $rel_path=''): string
* @method hasBeenBootstrapped(): bool
* @method bootstrapWith(array $bootstrappers): void
* @method registerCoreContainerAliases(): void
* @method when($concrete): Magnetar\Container\ContextualBindingBuilder
* @method bound(string $abstract): bool
* @method has(string $id): bool
* @method resolved(string $abstract): bool
* @method isShared(string $abstract): bool
* @method isAlias(string $name): bool
* @method bind(string $abstract, Closure|string|null $concrete=null, bool $shared=false): void
* @method hasMethodBinding(string $method): bool
* @method bindMethod(array|string $method, Closure $callback): void
* @method callMethodBinding(string $method, mixed $instance): mixed
* @method addContextualBinding(string $concrete, string $abstract, Closure|string $implementation): void
* @method bindIf(string $abstract, Closure|string|null $concrete=null, bool $shared=false): void
* @method singleton(string $abstract, Closure|string|null $concrete=null): void
* @method singletonIf(string $abstract, Closure|string|null $concrete=null): void
* @method scoped(string $abstract, Closure|string|null $concrete=null): void
* @method scopedIf(string $abstract, Closure|string|null $concrete=null): void
* @method extend(string $abstract, Closure $closure): void
* @method instance(string $abstract, mixed $instance): mixed
* @method tag(array|string $abstracts, mixed $tags): void
* @method tagged(string $tag): iterable
* @method alias(string $abstract, string $alias): void
* @method rebinding(string $abstract, Closure $callback): mixed
* @method refresh($abstract, $target, $method)
* @method wrap(Closure $callback, array $parameters=[]): Closure
* @method call(callable|string $callback, array $parameters=[], string|null $defaultMethod=null): mixed
* @method factory(string $abstract): Closure
* @method makeWith(string|callable $abstract, array $parameters=[]): mixed
* @method make(string|callable $abstract, array $parameters=[]): mixed
* @method get(string $id): mixed
* @method build(Closure|string $concrete): mixed
* @method beforeResolving(Closure|string $abstract, Closure|null $callback=null): void
* @method resolving(Closure|string $abstract, Closure|null $callback=null): void
* @method afterResolving(Closure|string $abstract, Closure|null $callback=null): void
* @method getBindings(): array
* @method getAlias(string $abstract): string
* @method forgetExtenders(string $abstract): void
* @method forgetInstance(string $abstract): void
* @method forgetInstances(): void
* @method forgetScopedInstances(): void
* @method flush(): void
* @method offsetExists(mixed $key): bool
* @method offsetGet(mixed $key): mixed
* @method offsetSet(mixed $key, mixed $value): void
* @method offsetUnset($key): void
* @method __get(string $key): mixed
* @method __set(string $key, mixed $value): void
* @method setBasePath(string $base_path): void;
* @method pathBase(string $rel_path=''): string;
* @method setAppPath(string $path): self;
* @method pathApp(string $rel_path=''): string;
* @method setConfigPath(string $path): self;
* @method pathConfig(string $rel_path=''): string;
* @method setDataPath(string $path): self;
* @method pathData(string $rel_path=''): string;
* @method setPublicPath(string $path): self;
* @method pathPublic(string $rel_path=''): string;
* @method setAssetsPath(string $path): self;
* @method pathAssets(string $rel_path=''): string;
* @method setStoragePath(string $path): self;
* @method pathStorage(string $rel_path=''): string;
* @method setRoutingPath(string $path): self;
* @method pathRouting(string $rel_path=''): string;
* @method setThemesPath(string $path): self;
* @method pathThemes(string $rel_path=''): string;
* @method joinPath(string $base_path, string $rel_path=''): string;
* @method hasBeenBootstrapped(): bool;
* @method bootstrapWith(array $bootstrappers): void;
* @method hasBootedServiceProviders(): bool;
* @method registerConfiguredServiceProviders(): void;
* @method bootServiceProviders(): void;
* @method bootServiceProvider(Magnetar\Helpers\ServiceProvider|string $provider): void;
* @method registerServiceProvider(Magnetar\Helpers\ServiceProvider|string $provider): Magnetar\Helpers\ServiceProvider;
* @method resolveServiceProvider(string $provider): Magnetar\Helpers\ServiceProvider;
* @method getServiceProvider(Magnetar\Helpers\ServiceProvider|string $provider): ?Magnetar\Helpers\ServiceProvider;
* @method getServiceProviders(Magnetar\Helpers\ServiceProvider|string $provider): array;
* @method registerCoreContainerAliases(): void;
* @method make(callable|string $abstract, array $parameters=[]): mixed;
* @method bound(string $abstract): bool;
* @method flush(): void;
* @method registerTerminateCallback(callable|array|string $callback): void;
* @method terminate(): void;
* @method setEnvironment(string $env): void;
* @method environment(): string;
* @method isDev(): bool;
* @method isProd(): bool;
* @method when( $concrete): Magnetar\Container\ContextualBindingBuilder;
* @method has(string $id): bool;
* @method resolved(string $abstract): bool;
* @method isShared(string $abstract): bool;
* @method isAlias(string $name): bool;
* @method bind(string $abstract, Closure|string|null $concrete=null, bool $shared=false): void;
* @method hasMethodBinding(string $method): bool;
* @method bindMethod(array|string $method, Closure $callback): void;
* @method callMethodBinding(string $method, mixed $instance): mixed;
* @method addContextualBinding(string $concrete, string $abstract, Closure|string $implementation): void;
* @method bindIf(string $abstract, Closure|string|null $concrete=null, bool $shared=false): void;
* @method singleton(string $abstract, Closure|string|null $concrete=null): void;
* @method singletonIf(string $abstract, Closure|string|null $concrete=null): void;
* @method scoped(string $abstract, Closure|string|null $concrete=null): void;
* @method scopedIf(string $abstract, Closure|string|null $concrete=null): void;
* @method extend(string $abstract, Closure $closure): void;
* @method instance(string $abstract, mixed $instance): mixed;
* @method tag(array|string $abstracts, mixed $tags): void;
* @method tagged(string $tag): iterable;
* @method alias(string $abstract, string $alias): void;
* @method rebinding(string $abstract, Closure $callback): mixed;
* @method refresh(string $abstract, mixed $target, string $method): mixed;
* @method wrap(Closure $callback, array $parameters=[]): Closure;
* @method call(callable|array|string $callback, array $parameters=[], ?string $defaultMethod=null): mixed;
* @method factory(string $abstract): Closure;
* @method makeWith(callable|string $abstract, array $parameters=[]): mixed;
* @method get(string $id): mixed;
* @method build(Closure|string $concrete): mixed;
* @method beforeResolving(Closure|string $abstract, ?Closure $callback=null): void;
* @method resolving(Closure|string $abstract, ?Closure $callback=null): void;
* @method afterResolving(Closure|string $abstract, ?Closure $callback=null): void;
* @method getBindings(): array;
* @method getAlias(string $abstract): string;
* @method forgetExtenders(string $abstract): void;
* @method forgetInstance(string $abstract): void;
* @method forgetInstances(): void;
* @method forgetScopedInstances(): void;
* @method getInstance(): static;
* @method setInstance(?Magnetar\Container\Container $container=null): Magnetar\Container\Container|static;
* @method offsetExists(mixed $key): bool;
* @method offsetGet(mixed $key): mixed;
* @method offsetSet(mixed $key, mixed $value): void;
* @method offsetUnset(mixed $key): void;
*
* @see Magnetar\Application
*/
Expand Down
11 changes: 1 addition & 10 deletions src/Magnetar/Helpers/Facades/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
use Magnetar\Helpers\Facades\Facade;

/**
* @method clear(): void;
* @method delete(string $key): bool;
* @method get(string $key): mixed;
* @method getMany(array $keys): array;
* @method increment(string $key, int $step=1): int|false;
* @method decrement(string $key, int $step=1): int|false;
* @method has(string $key): bool;
* @method hasMany(array $keys): array;
* @method set(string $key, $value, int $ttl=0): mixed;
* @method setMany(array $values, int $ttl=0): void;
* @method connection(?string $driver_name=null): Magnetar\Cache\AbstractCacheStore;
*
* @see Magnetar\Cache\StoreManager
*/
Expand Down
24 changes: 12 additions & 12 deletions src/Magnetar/Helpers/Facades/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use Magnetar\Helpers\Facades\Facade;

/**
* @method set(string $key, mixed $value): void
* @method get(string $key, mixed $default=null): mixed
* @method has(string $key): bool
* @method all(): array
* @method setAll(array $values): void
* @method remove(string $key): void
* @method removeAll(): void
* @method load(string $file, string|false $key=false): void
* @method offsetExists(mixed $key): bool
* @method offsetGet(mixed $key): mixed
* @method offsetSet(mixed $key, mixed $value): void
* @method offsetUnset(mixed $key): void
* @method set(string $key, mixed $value): void;
* @method get(string $key, mixed $default=null): mixed;
* @method has(string $key): bool;
* @method all(): array;
* @method setAll(array $values): void;
* @method remove(string $key): void;
* @method removeAll(): void;
* @method load(string $file, string|false $key=false): void;
* @method offsetExists(mixed $key): bool;
* @method offsetGet(mixed $key): mixed;
* @method offsetSet(mixed $key, mixed $value): void;
* @method offsetUnset(mixed $key): void;
*
* @see Magnetar\Config\Config
*/
Expand Down
11 changes: 4 additions & 7 deletions src/Magnetar/Helpers/Facades/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
use Magnetar\Helpers\Facades\Facade;

/**
* @method connection(string|null $driver_name=null): Magnetar\Database\DatabaseAdapter
* @method query(array $sql_query, array $params=[]): int|false;
* @method get_rows(string $sql_query, array $params=[], array|false $column_key=false): array|false;
* @method get_row(string $sql_query, array $params=[]): array|false;
* @method get_col(string $sql_query, array $params=[], string|int $column_key=0): array|false;
* @method get_col_assoc(string $sql_query, array $params=[], string $assoc_key, string|int $column_key=0): array|false;
* @method get_var(string $sql_query, array $params=[], string|int|false $column_key=false): string|int|false;
* @method connection(?string $connection_name=null): Magnetar\Database\DatabaseAdapter;
* @method getDefaultConnectionName(): ?string;
* @method getConnected(): array;
* @method adapter(string $connection_name): Magnetar\Database\DatabaseAdapter;
*
* @see Magnetar\Database\ConnectionManager
*/
Expand Down
Loading

0 comments on commit 26b06f3

Please sign in to comment.