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
4 changes: 2 additions & 2 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Bow\Console\Command\Generator\GenerateNotificationCommand;
use Bow\Console\Command\Generator\GenerateConfigurationCommand;
use Bow\Console\Command\Generator\GenerateEventListenerCommand;
use Bow\Console\Command\Generator\GenerateJobCommand;
use Bow\Console\Command\Generator\GenerateTaskCommand;
use Bow\Console\Command\Generator\GenerateRouterResourceCommand;

class Command extends AbstractCommand
Expand Down Expand Up @@ -57,7 +57,7 @@ class Command extends AbstractCommand
"add:validation" => GenerateValidationCommand::class,
"add:event" => GenerateAppEventCommand::class,
"add:listener" => GenerateEventListenerCommand::class,
"add:job" => GenerateJobCommand::class,
"add:task" => GenerateTaskCommand::class,
"add:command" => GenerateConsoleCommand::class,
"add:notifier" => GenerateNotifierCommand::class,
"run:console" => ReplCommand::class,
Expand Down
38 changes: 0 additions & 38 deletions src/Console/Command/Generator/GenerateJobCommand.php

This file was deleted.

38 changes: 38 additions & 0 deletions src/Console/Command/Generator/GenerateTaskCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Bow\Console\Command\Generator;

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

class GenerateTaskCommand extends AbstractCommand
{
/**
* Add task
*
* @param string $task
* @return void
*/
public function run(string $task): void
{
$generator = new Generator(
$this->setting->getTaskDirectory(),
$task
);

if ($generator->fileExists()) {
echo Color::red("The task already exists");
exit(1);
}

$generator->write('task', [
'baseNamespace' => $this->namespaces['task'] ?? 'App\\Tasks'
]);

echo Color::green("The task has been well created.");
exit(0);
}
}
10 changes: 5 additions & 5 deletions src/Console/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Console
'service',
'exception',
'event',
'job',
'task',
'command',
'listener',
'notifier'
Expand Down Expand Up @@ -540,7 +540,7 @@ private function help(?string $command = null): int
\033[0;33madd:migration\033[00m Create a new migration
\033[0;33madd:event\033[00m Create a new event
\033[0;33madd:listener\033[00m Create a new event listener
\033[0;33madd:job\033[00m Create a new job
\033[0;33madd:task\033[00m Create a new task
\033[0;33madd:command\033[00m Create a new console command
\033[0;33madd:notifier\033[00m Create a new messaging handler

Expand All @@ -564,7 +564,7 @@ private function help(?string $command = null): int
\033[0;32mRUN\033[00m Launch development tools
\033[0;33mrun:console\033[00m Show PsySH PHP REPL for debugging code
\033[0;33mrun:server\033[00m Start local development server
\033[0;33mrun:worker\033[00m Start consumer/worker to handle queue jobs
\033[0;33mrun:worker\033[00m Start consumer/worker to handle queue tasks

USAGE;
echo $usage;
Expand Down Expand Up @@ -593,7 +593,7 @@ private function help(?string $command = null): int
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:seeder name [--seed=n] Create a new seeder
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:migration name Create a new migration
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:event name Create a new event listener
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:job name Create a new queue job
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:task name Create a new queue task
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:command name Create a new console command
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add:notifier name Create a new messaging handler
\033[0;33m$\033[00m php \033[0;34mbow\033[00m add help Display this help
Expand Down Expand Up @@ -642,7 +642,7 @@ private function help(?string $command = null): int

\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:console Show PsySH PHP REPL for debugging code
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:server [option] Start local development server
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:worker [option] Start worker to handle queue jobs
\033[0;33m$\033[00m php \033[0;34mbow\033[00m run:worker [option] Start worker to handle queue tasks

U; // phpcs:enable
break;
Expand Down
18 changes: 9 additions & 9 deletions src/Console/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ class Setting
private string $service_directory;

/**
* The job directory
* The task directory
*
* @var string
*/
private string $job_directory;
private string $task_directory;
/**
* The command directory
*
Expand Down Expand Up @@ -402,24 +402,24 @@ public function setServiceDirectory(string $service_directory): void
}

/**
* Get the job directory
* Get the task directory
*
* @return string
*/
public function getJobDirectory(): string
public function getTaskDirectory(): string
{
return $this->job_directory;
return $this->task_directory;
}

/**
* Set the job directory
* Set the task directory
*
* @param string $job_directory
* @param string $task_directory
* @return void
*/
public function setJobDirectory(string $job_directory): void
public function setTaskDirectory(string $task_directory): void
{
$this->job_directory = $job_directory;
$this->task_directory = $task_directory;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Console/stubs/job.stub → src/Console/stubs/task.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace {baseNamespace}{namespace};

use Bow\Queue\QueueJob;
use Bow\Queue\QueueTask;

class {className} extends QueueJob
class {className} extends QueueTask
{
/**
* {className} constructor
Expand Down
10 changes: 3 additions & 7 deletions src/Database/Barry/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static function retrieveAndDelete(
}

if ($model instanceof Collection) {
$model->delete();
$model->map(fn ($m) => $m->delete());
return $model;
}

Expand Down Expand Up @@ -861,9 +861,7 @@ public function toArray(): array
{
return array_filter(
$this->attributes,
function ($key) {
return !in_array($key, $this->hidden);
},
fn ($key) => !in_array($key, $this->hidden),
ARRAY_FILTER_USE_KEY
);
}
Expand All @@ -875,9 +873,7 @@ public function jsonSerialize(): array
{
return array_filter(
$this->attributes,
function ($key) {
return !in_array($key, $this->hidden);
},
fn ($key) => !in_array($key, $this->hidden),
ARRAY_FILTER_USE_KEY
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,19 @@ public static function inTransaction(): bool
*/
public static function commit(): void
{
static::ensureDatabaseConnection();

static::$adapter->getConnection()->commit();
if (static::inTransaction()) {
static::$adapter->getConnection()->commit();
}
}

/**
* Cancel a transaction
*/
public static function rollback(): void
{
static::ensureDatabaseConnection();

static::$adapter->getConnection()->rollBack();
if (static::inTransaction()) {
static::$adapter->getConnection()->rollBack();
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Event/EventQueueJob.php → src/Event/EventQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Bow\Event\Contracts\EventListener;
use Bow\Event\Contracts\EventShouldQueue;
use Bow\Queue\QueueJob;
use Bow\Queue\QueueTask;

class EventQueueJob extends QueueJob
class EventQueueTask extends QueueTask
{
/**
* EventQueueJob constructor
* EventQueueTask constructor
*
* @param EventListener|EventShouldQueue $event
* @param mixed $payload
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function call(array $data = []): mixed
$instance = app($callable);
if ($instance instanceof EventListener) {
if ($instance instanceof EventShouldQueue) {
queue(new EventQueueJob($instance, $data));
queue(new EventQueueTask($instance, $data));
return null;
}
$callable = [$instance, 'process'];
Expand Down
8 changes: 4 additions & 4 deletions src/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static function queue(string $template, array $data, callable $cb): void

call_user_func_array($cb, [$envelop]);

$producer = new MailQueueJob($template, $data, $envelop);
$producer = new MailQueueTask($template, $data, $envelop);

queue($producer);
}
Expand All @@ -189,7 +189,7 @@ public static function queueOn(string $queue, string $template, array $data, cal

call_user_func_array($cb, [$envelop]);

$producer = new MailQueueJob($template, $data, $envelop);
$producer = new MailQueueTask($template, $data, $envelop);

$producer->setQueue($queue);

Expand All @@ -211,7 +211,7 @@ public static function later(int $delay, string $template, array $data, callable

call_user_func_array($cb, [$envelop]);

$producer = new MailQueueJob($template, $data, $envelop);
$producer = new MailQueueTask($template, $data, $envelop);

$producer->setDelay($delay);

Expand All @@ -234,7 +234,7 @@ public static function laterOn(int $delay, string $queue, string $template, arra

call_user_func_array($cb, [$envelop]);

$producer = new MailQueueJob($template, $data, $envelop);
$producer = new MailQueueTask($template, $data, $envelop);

$producer->setQueue($queue);
$producer->setDelay($delay);
Expand Down
6 changes: 3 additions & 3 deletions src/Mail/MailQueueJob.php → src/Mail/MailQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Bow\Mail;

use Bow\Queue\QueueJob;
use Bow\Queue\QueueTask;
use Bow\View\View;
use Throwable;

class MailQueueJob extends QueueJob
class MailQueueTask extends QueueTask
{
/**
* The message bag
Expand All @@ -16,7 +16,7 @@ class MailQueueJob extends QueueJob
private array $bags = [];

/**
* MailQueueJob constructor
* MailQueueTask constructor
*
* @param string $view
* @param array $data
Expand Down
14 changes: 4 additions & 10 deletions src/Notifier/Adapters/SlackChannelAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Bow\Notifier\Adapters;

use Bow\Database\Barry\Model;
use Bow\Http\Client\HttpClient;
use Bow\Notifier\Contracts\ChannelAdapterInterface;
use Bow\Notifier\Notifier;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class SlackChannelAdapter implements ChannelAdapterInterface
{
Expand All @@ -16,7 +15,7 @@ class SlackChannelAdapter implements ChannelAdapterInterface
* @param Model $context
* @param Notifier $notifier
* @return void
* @throws GuzzleException
* @throws \Exception
*/
public function send(Model $context, Notifier $notifier): void
{
Expand All @@ -36,15 +35,10 @@ public function send(Model $context, Notifier $notifier): void
throw new \InvalidArgumentException('The webhook URL is required for Slack');
}

$client = new Client();
$client = new HttpClient();

try {
$client->post($webhook_url, [
'json' => $data['content'],
'headers' => [
'Content-Type' => 'application/json'
]
]);
$client->acceptJson()->post($webhook_url, $data['content']);
} catch (\Exception $e) {
throw new \RuntimeException('Error while sending Slack notifier: ' . $e->getMessage());
}
Expand Down
Loading
Loading