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
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contribution

- [Contribution](#contribution)
- [Introduction](#introduction)
- [Cutting the project](#cutting-the-project)
- [How to make the commits](#how-to-make-the-commits)
- [Contact](#contact)
- [Introduction](#introduction)
- [Cutting the project](#cutting-the-project)
- [How to make the commits](#how-to-make-the-commits)
- [Contact](#contact)

## Introduction

Expand Down
41 changes: 41 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,54 @@ To use this package, please create an application from this package [bowphp/app]
- The native authentication system
- Producer/Consumer with beanstalkd, database, Redis, SQS backend

## Project Structure

The project is organized into the following directories, each representing an independent module:

- **src/**: Source code for the Bow Framework.
- **Application/**: Main application logic and configuration.
- **Auth/**: Authentication and authorization management.
- **Cache/**: Caching mechanisms.
- **Configuration/**: Configuration settings management.
- **Console/**: Console commands and utilities.
- **Container/**: Dependency injection and service container.
- **Contracts/**: Interfaces and contracts for various components.
- **Database/**: Database connections and ORM.
- **Event/**: Event management and dispatching.
- **Http/**: HTTP requests and responses management.
- **Mail/**: Email sending and configuration.
- **Messaging/**: Messaging and notifications.
- **Middleware/**: Middleware classes for request handling.
- **Queue/**: Job queues and background processing.
- **Router/**: HTTP request routing.
- **Security/**: Security features like encryption and hashing.
- **Session/**: User session management.
- **Storage/**: File storage and retrieval.
- **Support/**: Utility classes and helper functions.
- **Testing/**: Unit testing classes and utilities.
- **Translate/**: Translation and localization.
- **Validation/**: Data validation.
- **View/**: View rendering and templating.
- **tests/**: Unit tests for the project.

## Contributing

Thank you for considering contributing to Bow Framework! The contribution guide is in the framework documentation.

- [Franck DAKIA](https://github.com/papac)
- [Thank's collaborators](https://github.com/bowphp/framework/graphs/contributors)

### Contribution Guidelines

We welcome contributions from the community! To contribute to the project, please follow these steps:

1. Fork the project and clone it to your local machine.
2. Create a new branch for your changes.
3. Make your changes and commit them.
4. Push your changes to your fork and create a pull request.

For more detailed information, refer to the `CONTRIBUTING.md` file.

## Contact

[papac@bowphp.com](mailto:papac@bowphp.com) - [@papacdev](https://twitter.com/papacdev)
Expand Down
22 changes: 11 additions & 11 deletions src/Cache/Adapters/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function add(string $key, mixed $data, ?int $time = null): bool

$time = date("Y-m-d H:i:s");

return $this->query->insert(['keyname' => $key, "data" => serialize($content), "expire" => $time]);
return $this->query->insert(['key_name' => $key, "data" => serialize($content), "expire" => $time]);
}

/**
Expand All @@ -71,7 +71,7 @@ public function add(string $key, mixed $data, ?int $time = null): bool
*/
public function has(string $key): bool
{
return $this->query->where("keyname", $key)->exists();
return $this->query->where("key_name", $key)->exists();
}

/**
Expand All @@ -91,14 +91,14 @@ public function update(string $key, mixed $data, ?int $time = null): mixed
$content = $data;
}

$result = $this->query->where("keyname", $key)->first();
$result = $this->query->where("key_name", $key)->first();
$result->data = serialize($content);

if (!is_null($time)) {
$result->expire = date("Y-m-d H:i:s", strtotime($result->expire) + $time);
}

return $this->query->where("keyname", $key)->update((array)$result);
return $this->query->where("key_name", $key)->update((array)$result);
}

/**
Expand Down Expand Up @@ -135,12 +135,12 @@ public function push(string $key, array $data): bool
throw new Exception("The key $key is not found");
}

$result = $this->query->where("keyname", $key)->first();
$result = $this->query->where("key_name", $key)->first();

$value = (array)unserialize($result->data);
$result->data = serialize(array_merge($value, $data));

return (bool)$this->query->where("keyname", $key)->update((array)$result);
return (bool)$this->query->where("key_name", $key)->update((array)$result);
}

/**
Expand All @@ -154,11 +154,11 @@ public function addTime(string $key, int $time): bool
throw new Exception("The key $key is not found");
}

$result = $this->query->where("keyname", $key)->first();
$result = $this->query->where("key_name", $key)->first();

$result->expire = date("Y-m-d H:i:s", strtotime($result->expire) + $time);

return (bool)$this->query->where("keyname", $key)->update((array)$result);
return (bool)$this->query->where("key_name", $key)->update((array)$result);
}

/**
Expand All @@ -172,7 +172,7 @@ public function timeOf(string $key): int|bool|string
throw new Exception("The key $key is not found");
}

$result = $this->query->where("keyname", $key)->first();
$result = $this->query->where("key_name", $key)->first();

return $result->expire;
}
Expand All @@ -188,7 +188,7 @@ public function forget(string $key): bool
throw new Exception("The key $key is not found");
}

return $this->query->where("keyname", $key)->delete();
return $this->query->where("key_name", $key)->delete();
}

/**
Expand All @@ -210,7 +210,7 @@ public function get(string $key, mixed $default = null): mixed
return is_callable($default) ? $default() : $default;
}

$result = $this->query->where("keyname", $key)->first();
$result = $this->query->where("key_name", $key)->first();

$value = unserialize($result->data);

Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/model/cache.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class {className} extends Migration
public function up(): void
{
$this->create("caches", function (Table $table) {
$table->addString('keyname', ['primary' => true, 'size' => 500]);
$table->addString('key_name', ['primary' => true, 'size' => 500]);
$table->addText('data');
$table->addDatetime('expire', ['nullable' => true]);
$table->addTimestamps();
Expand Down
17 changes: 17 additions & 0 deletions src/Database/Migration/Shortcut/DateColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ public function addTimestamps(): Table
return $this;
}

/**
* Add default timestamps
*
* @return Table
* @throws SQLGeneratorException
*/
public function addSoftDelete(): Table
{
if ($this->adapter == 'pgsql') {
$this->addTimestamp('deleted_at', ['default' => 'CURRENT_TIMESTAMP', 'nullable' => true]);
} else {
$this->addColumn('updated_at', 'datetime', ['nullable' => true]);
}

return $this;
}

/**
* Change datetime column
*
Expand Down
8 changes: 8 additions & 0 deletions src/Database/Notification/WithNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function notifications()
->where('concern_type', get_class($this));
}

/**
* @throws ConnectionException|Exception\QueryBuilderException
*/
public function unreadNotifications()
{
return $this->notifications()->whereNull('read_at');
}

/**
* @throws ConnectionException|Exception\QueryBuilderException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Messaging/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function process(Model $context): void
foreach ($channels as $channel) {
if (array_key_exists($channel, static::$channels)) {
$target_channel = new static::$channels[$channel]();
$target_channel->send($context);
$target_channel->send($context, $this);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,17 +1220,17 @@ function app_mode(): string
*/
function app_in_debug(): bool
{
return (bool)app_env('APP_DEBUG');
return (bool) app_env('APP_DEBUG');
}
}

if (!function_exists('client_locale')) {
/**
* Get client request language
*
* @return string
* @return ?string
*/
function client_locale(): string
function client_locale(): ?string
{
return request()->lang();
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ function old(string $key, mixed $fullback = null): mixed
* @throws AuthenticationException
* @deprecated
*/
function auth(string $guard = null): GuardContract
function auth(?string $guard = null): GuardContract
{
$auth = Auth::getInstance();

Expand All @@ -1279,7 +1279,7 @@ function auth(string $guard = null): GuardContract
* @return GuardContract
* @throws AuthenticationException
*/
function app_auth(string $guard = null): GuardContract
function app_auth(?string $guard = null): GuardContract
{
$auth = Auth::getInstance();

Expand Down
10 changes: 5 additions & 5 deletions tests/Cache/CacheDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public static function setUpBeforeClass(): void

Database::configure($config["database"]);

Database::statement("drop table if exists caches;");
Database::statement("DROP TABLE IF EXISTS caches;");
Database::statement("
create table if not exists caches (
`keyname` varchar(500) not null primary key,
`data` text null,
`expire` datetime null
CREATE TABLE IF NOT EXISTS caches (
key_name varchar(500) not null primary key,
data text null,
expire datetime null
)");

Cache::configure($config["cache"]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Config/stubs/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'cache' => TESTING_RESOURCE_BASE_DIRECTORY . '/cache',

// Le repertoire des vues.
'path' => __DIR__ . '/../../View/stubs',
'path' => realpath(__DIR__ . '/../../View/stubs'),

'additionnal_options' => [
'auto_reload' => true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FakeCacheMigration extends Migration
public function up(): void
{
$this->create("caches", function (Table $table) {
$table->addString('keyname', ['primary' => true, 'size' => 500]);
$table->addString('key_name', ['primary' => true, 'size' => 500]);
$table->addText('data');
$table->addDatetime('expire', ['nullable' => true]);
$table->addTimestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FakeCacheMigration extends Migration
public function up(): void
{
$this->create("caches", function (SQLGenerator $table) {
$table->addString('keyname', ['primary' => true, 'size' => 500]);
$table->addString('key_name', ['primary' => true, 'size' => 500]);
$table->addText('data');
$table->addDatetime('expire', ['nullable' => true]);
$table->addTimestamps();
Expand Down
73 changes: 73 additions & 0 deletions tests/Notification/NotificationDatabaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Bow\Tests\Notification;

use Bow\Database\Database;
use Bow\Tests\Config\TestingConfiguration;

class NotificationDatabaseTest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
$config = TestingConfiguration::getConfig();

Database::configure($config["database"]);

Database::statement("drop table if exists notifications;");
Database::statement("create table if not exists notifications (
id int not null primary key auto_increment,
type text null,
concern_id int,
concern_type varchar(500),
data text null,
read_at datetime null
);");
}

public function testInsertNotification()
{
$result = Database::table('notifications')->insert([
'type' => 'info',
'concern_id' => 1,
'concern_type' => 'user',
'data' => json_encode(['message' => 'Test notification']),
'read_at' => null
]);

$this->assertTrue($result);
}

public function testRetrieveNotification()
{
$notification = Database::table('notifications')->where('id', 1)->first();

$this->assertNotNull($notification);
$this->assertEquals('info', $notification->type);
$this->assertEquals(1, $notification->concern_id);
$this->assertEquals('user', $notification->concern_type);
$this->assertEquals(json_encode(['message' => 'Test notification']), $notification->data);
$this->assertNull($notification->read_at);
}

public function testUpdateNotification()
{
$result = Database::table('notifications')->where('id', 1)->update([
'read_at' => date('Y-m-d H:i:s')
]);

$this->assertTrue($result);

$notification = Database::table('notifications')->where('id', 1)->first();
$this->assertNotNull($notification->read_at);
}

public function testDeleteNotification()
{
$result = Database::table('notifications')->where('id', 1)->delete();

$this->assertTrue($result);

$notification = Database::table('notifications')->where('id', 1)->first();
$this->assertNull($notification);
}
}
2 changes: 1 addition & 1 deletion tests/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
public static function setUpBeforeClass(): void
{
$config = TestingConfiguration::getConfig();

View::configure($config["view"]);
}

Expand Down
Loading