Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ramsey/uuid": "^4.7",
"ext-ftp": "*",
"ext-openssl": "*",
"ext-pcntl": "*"
"ext-pcntl": "*",
"ext-readline": "*"
},
"require-dev": {
"pda/pheanstalk": "^5.0",
Expand Down
27 changes: 15 additions & 12 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class Application extends Router
*
* @param Request $request
* @param Response $response
* @return void
* @throws BadRequestException
*/
public function __construct(Request $request, Response $response)
Expand Down Expand Up @@ -172,10 +171,11 @@ public function isRunningOnCli(): bool
/**
* Launcher of the application
*
* @return ?bool
* @throws RouterException|ReflectionException
* @return bool
* @throws ReflectionException
* @throws RouterException
*/
public function send(): ?bool
public function send(): bool
{
if ($this->config->isCli()) {
return true;
Expand Down Expand Up @@ -227,21 +227,24 @@ public function send(): ?bool

// Error management
if ($resolved) {
return $this->sendResponse($response);
$this->sendResponse($response);
return true;
}

// We apply the 404 error code
$this->response->status(404);

if (array_key_exists(404, $this->error_code)) {
$response = Action::getInstance()->execute($this->error_code[404], []);

return $this->sendResponse($response, 404);
if (!array_key_exists(404, $this->error_code)) {
throw new RouterException(
sprintf('Route "%s" not found', $this->request->path())
);
}

throw new RouterException(
sprintf('Route "%s" not found', $this->request->path())
);
$response = Action::getInstance()->execute($this->error_code[404], []);

$this->sendResponse($response, 404);

return false;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Auth/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,9 @@ public static function __callStatic(string $method, array $params)
if (method_exists(static::$instance, $method)) {
return call_user_func_array([static::$instance, $method], $params);
}

throw new ErrorException(
"Method [$method] does not exists"
);
}
}
1 change: 0 additions & 1 deletion src/Auth/Guards/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class SessionGuard extends GuardContract
*/
private string $session_key;


/**
* SessionGuard constructor.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function hasTrash(): bool
*/
private function initCommand(string $param): void
{
if (!preg_match('/^[a-z]+:[a-z]+$/', $param)) {
if (!preg_match('/^[a-z-]+[a-z]+:[a-z-]+[a-z]+$/', $param)) {
$this->command = $param;
$this->action = null;
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class Command extends AbstractCommand
"listener" => \Bow\Console\Command\EventListenerCommand::class,
"producer" => \Bow\Console\Command\ProducerCommand::class,
"command" => \Bow\Console\Command\ConsoleCommand::class,
"messaging" => \Bow\Console\Command\MessagingCommand::class,
],
"generator" => [
"key" => \Bow\Console\Command\GenerateKeyCommand::class,
"resource" => \Bow\Console\Command\GenerateResourceControllerCommand::class,
"session" => \Bow\Console\Command\GenerateSessionCommand::class,
"queue" => \Bow\Console\Command\GenerateQueueCommand::class,
"cache" => \Bow\Console\Command\GenerateCacheCommand::class,
"session-table" => \Bow\Console\Command\GenerateSessionCommand::class,
"queue-table" => \Bow\Console\Command\GenerateQueueCommand::class,
"cache-table" => \Bow\Console\Command\GenerateCacheCommand::class,
"notification-table" => \Bow\Console\Command\GenerateCacheCommand::class,
],
"runner" => [
"console" => \Bow\Console\Command\ReplCommand::class,
Expand Down
35 changes: 35 additions & 0 deletions src/Console/Command/GenerateNotificationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Bow\Console\Command;

use Bow\Console\AbstractCommand;
use Bow\Console\Color;
use Bow\Console\Generator;
use Bow\Support\Str;

class GenerateNotificationCommand extends AbstractCommand
{
/**
* Generate session
*
* @return void
*/
public function generate(): void
{
$create_at = date("YmdHis");
$filename = sprintf("Version%s%sTable", $create_at, ucfirst(Str::camel('notification')));

$generator = new Generator(
$this->setting->getMigrationDirectory(),
$filename
);

$generator->write('model/notification', [
'className' => $filename
]);

echo Color::green('Notification migration created.');
}
}
2 changes: 1 addition & 1 deletion src/Console/Command/GenerateQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GenerateQueueCommand extends AbstractCommand
public function generate(): void
{
$create_at = date("YmdHis");
$filename = sprintf("Version%s%sTable", $create_at, ucfirst(Str::camel('queue')));
$filename = sprintf("Version%s%sTable", $create_at, ucfirst(Str::camel('queues')));

$generator = new Generator(
$this->setting->getMigrationDirectory(),
Expand Down
42 changes: 42 additions & 0 deletions src/Console/Command/MessagingCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Bow\Console\Command;

use Bow\Console\AbstractCommand;
use Bow\Console\Color;
use Bow\Console\Generator;
use Bow\Support\Str;
use JetBrains\PhpStorm\NoReturn;

class MessagingCommand extends AbstractCommand
{
/**
* Generate session
*
* @param string $messaging
* @return void
*/
#[NoReturn] public function generate(string $messaging): void
{
$generator = new Generator(
$this->setting->getMessagingDirectory(),
$messaging
);

if ($generator->fileExists()) {
echo Color::red("The messaging already exists");

exit(1);
}

$generator->write('messaging', [
'baseNamespace' => $this->namespaces['messaging'] ?? "App\\Messaging",
]);

echo Color::green("The messaging has been well created.");

exit(0);
}
}
24 changes: 16 additions & 8 deletions src/Console/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private function generate(): void
{
$action = $this->arg->getAction();

if (!in_array($action, ['key', 'resource', 'session', 'cache', 'queue'])) {
if (!in_array($action, ['key', 'resource', 'session-table', 'cache-table', 'queue-table'])) {
$this->throwFailsCommand('This action is not exists', 'help generate');
}

Expand Down Expand Up @@ -476,10 +476,13 @@ private function help(?string $command = null): int
\033[0;33mhelp\033[00m display command helper

\033[0;32mGENERATE\033[00m create a new app key and resources
\033[0;33mgenerate:resource\033[00m Create new REST controller
\033[0;33mgenerate:table\033[00m For generate the preset table for session, cache, queue
\033[0;33mgenerate:key\033[00m Create new app key
\033[0;33mflush:worker\033[00m Flush all queues
\033[0;33mgenerate:resource\033[00m Create new REST controller
\033[0;33mgenerate:session-table\033[00m For generate the preset table for session
\033[0;33mgenerate:cache-table\033[00m For generate the preset table for cache
\033[0;33mgenerate:queue-table\033[00m For generate the preset table for queue
\033[0;33mgenerate:notification-table\033[00m For generate the preset table for notification
\033[0;33mgenerate:key\033[00m Create new app key
\033[0;33mflush:worker\033[00m Flush all queues

\033[0;32mADD\033[00m Create a user class
\033[0;33madd:middleware\033[00m Create new middleware
Expand All @@ -495,6 +498,7 @@ private function help(?string $command = null): int
\033[0;33madd:listener\033[00m Create a new event listener
\033[0;33madd:producer\033[00m Create a new producer
\033[0;33madd:command\033[00m Create a new bow console command
\033[0;33madd:messaging\033[00m Create a new bow messaging

\033[0;32mMIGRATION\033[00m apply a migration in user model
\033[0;33mmigration:migrate\033[00m Make migration
Expand Down Expand Up @@ -538,7 +542,7 @@ private function help(?string $command = null): int

* you can use --no-plain --with-model in same command

\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:controller name [option] For create a new controlleur
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:controller name [option] For create a new controller
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:middleware name For create a new middleware
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:configuration name For create a new configuration
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:service name For create a new service
Expand All @@ -550,6 +554,7 @@ private function help(?string $command = null): int
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:event name For create a new event listener
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:producer name For create a new queue producer
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:command name For create a new bow console command
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:messaging name For create a new bow messaging
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add help For display this

U;
Expand All @@ -564,7 +569,10 @@ private function help(?string $command = null): int
--model=[model_name] Define the usable model

\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:resource name [option] For create a new REST controller
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:table For generate the table for session, cache, queue
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:session-table For generate the table for session
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:cache-table For generate the table for cache
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:queue-table For generate the table for queue
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:notification-table For generate the table for notification
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:key For generate a new APP KEY
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate help For display this

Expand Down Expand Up @@ -592,7 +600,7 @@ private function help(?string $command = null): int
run:worker [--queue=default] [--connexion=beanstalkd,sqs,redis,database] [--tries=duration] [--sleep=duration] [--timeout=duration]

\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:console\033[00m Show psysh php REPL
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:server\033[00m [option] Start local developpement server
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:server\033[00m [option] Start local development server
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:worker\033[00m [option] Start worker/consumer for handle the producer

U; // phpcs:enable
Expand Down
30 changes: 29 additions & 1 deletion src/Console/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ class Setting
*/
private array $namespaces = [];

/**
* The messaging directory
*
* @var string
*/
private string $messaging_directory;

/**
* Command constructor.
*
Expand Down Expand Up @@ -303,6 +310,17 @@ public function setMiddlewareDirectory(string $middleware_directory): void
$this->middleware_directory = $middleware_directory;
}

/**
* Set the messaging directory
*
* @param string $messaging_directory
* @return void
*/
public function setMessagingDirectory(string $messaging_directory): void
{
$this->messaging_directory = $messaging_directory;
}

/**
* Set the application directory
*
Expand Down Expand Up @@ -546,7 +564,7 @@ public function getEventListenerDirectory(): string
}

/**
* Get the service directory
* Get the middleware directory
*
* @return string
*/
Expand All @@ -555,6 +573,16 @@ public function getMiddlewareDirectory(): string
return $this->middleware_directory;
}

/**
* Get the messaging directory
*
* @return string
*/
public function getMessagingDirectory(): string
{
return $this->messaging_directory;
}

/**
* Get the model directory
*
Expand Down
42 changes: 42 additions & 0 deletions src/Console/stubs/messaging.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace {baseNamespace}{namespace};

use Bow\Database\Barry\Model;
use Bow\Messaging\Messaging;

class {className} extends Messaging
{
/**
* Returns the available channels to be used
*
* @param Model $notifiable
* @return array
*/
public function channels(Model $notifiable): array;
{
return ['mail', 'database'];
}

/**
* Send notification to mail
*
* @param Model $notifiable
* @return Message|null
*/
public function toMail(Model $notifiable): ?Message
{
return new Message();
}

/**
* Send notification to database
*
* @param Model $notifiable
* @return array
*/
public function toDatabase(Model $notifiable): array
{
return [];
}
}
4 changes: 2 additions & 2 deletions src/Console/stubs/model/cache.stub
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Bow\Database\Migration\Migration;
use Bow\Database\Migration\SQLGenerator;
use Bow\Database\Migration\SQLGenerator as Table;

class {className} extends Migration
{
Expand All @@ -10,7 +10,7 @@ class {className} extends Migration
*/
public function up(): void
{
$this->create("caches", function (SQLGenerator $table) {
$this->create("caches", function (Table $table) {
$table->addString('keyname', ['primary' => true, 'size' => 500]);
$table->addText('data');
$table->addDatetime('expire', ['nullable' => true]);
Expand Down
Loading
Loading