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
1 change: 1 addition & 0 deletions src/App/Traits/AppTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected function loadComponentHelperFunctions(): void
'Environment',
'Config',
'Router',
'Service',
'Model',
'Hook',
'Http',
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/Auth/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.7
* @since 2.9.9
*/

namespace Quantum\Libraries\Auth;
Expand All @@ -21,7 +21,7 @@
/**
* Class Auth
* @package Quantum\Libraries\Auth
* @method mixed signin(string $username, string $password)
* @method mixed signin(string $username, string $password, bool $remember = false)
* @method bool signout()
* @method bool check()
* @method User user()
Expand Down
10 changes: 0 additions & 10 deletions src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ class SleekDbal implements DbalInterface
use Reducer;
use Join;

/**
* Join type join to
*/
const JOINTO = 'joinTo';

/**
* Join type join through
*/
const JOINTHROUGH = 'joinThrough';

/**
* @var bool
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/QtModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @method bool delete()
* @method bool deleteMany()
* @method static joinTo(QtModel $model, bool $switch = true)
* @method static joinThrough(QtModel $model, bool $switch = true)
* @method static isNull(string $column)
* @method static isNotNull(string $column)
*/
Expand Down Expand Up @@ -115,6 +114,7 @@ public function relations(): array

/**
* @return ModelCollection
* @throws BaseException
*/
public function get(): ModelCollection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\Libraries\Auth\Exceptions\AuthException;
use Quantum\Service\Factories\ServiceFactory;
use {{MODULE_NAMESPACE}}\Services\AuthService;
use Quantum\Libraries\Hasher\Hasher;
use Quantum\Http\Response;
Expand All @@ -38,7 +37,7 @@ class AccountController extends BaseController
*/
public function __before()
{
$this->authService = ServiceFactory::create(AuthService::class);
$this->authService = service(AuthService::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\Libraries\Auth\Exceptions\AuthException;
use Quantum\Http\Enums\StatusCode;
use {{MODULE_NAMESPACE}}\Enums\Role;
use Quantum\Http\Response;
use Quantum\Http\Request;
use {{MODULE_NAMESPACE}}\Enums\Role;

/**
* Class AuthController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\Service\Factories\ServiceFactory;
use Quantum\Service\Exceptions\ServiceException;
use Quantum\App\Exceptions\BaseException;
use {{MODULE_NAMESPACE}}\Services\CommentService;
use Quantum\Di\Exceptions\DiException;
use Quantum\Http\Response;
use Quantum\Http\Request;

Expand All @@ -31,9 +33,15 @@ class CommentController extends BaseController
*/
public $commentService;

/**
* @throws ReflectionException
* @throws BaseException
* @throws DiException
* @throws ServiceException
*/
public function __before()
{
$this->commentService = ServiceFactory::create(CommentService::class);
$this->commentService = service(CommentService::class);
}

/**
Expand All @@ -45,13 +53,11 @@ class CommentController extends BaseController
*/
public function create(Request $request, Response $response, ?string $lang, string $uuid)
{
$data = [
$comment = $this->commentService->addComment([
'post_uuid' => $uuid,
'user_uuid' => auth()->user()->uuid,
'content' => trim($request->get('content')),
];

$comment = $this->commentService->addComment($data);
]);

$response->json([
'status' => 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\Service\Factories\ServiceFactory;
use Quantum\Service\Exceptions\ServiceException;
use Quantum\App\Exceptions\BaseException;
use Quantum\Di\Exceptions\DiException;
use Quantum\Http\Enums\StatusCode;
use {{MODULE_NAMESPACE}}\Services\CommentService;
use {{MODULE_NAMESPACE}}\Services\PostService;
Expand Down Expand Up @@ -44,11 +46,14 @@ class PostController extends BaseController
public $postService;

/**
* Works before an action
* @throws ReflectionException
* @throws BaseException
* @throws DiException
* @throws ServiceException
*/
public function __before()
{
$this->postService = ServiceFactory::create(PostService::class);
$this->postService = service(PostService::class);
}

/**
Expand Down Expand Up @@ -97,7 +102,8 @@ class PostController extends BaseController

$postData = current($this->postService->transformData([$post]));

$commentService = ServiceFactory::create(CommentService::class);
$commentService = service(CommentService::class);

$comments = $commentService->getCommentsByPost($postUuid);

$commentsData = $commentService->transformData($comments->all());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\Service\Factories\ServiceFactory;
use Quantum\Service\Exceptions\ServiceException;
use Quantum\App\Exceptions\BaseException;
use {{MODULE_NAMESPACE}}\Services\PostService;
use Quantum\Di\Exceptions\DiException;
use Quantum\Http\Response;
use Quantum\Http\Request;

Expand All @@ -35,9 +37,16 @@ class PostManagementController extends BaseController
/**
* Works before an action
*/

/**
* @throws ReflectionException
* @throws BaseException
* @throws DiException
* @throws ServiceException
*/
public function __before()
{
$this->postService = ServiceFactory::create(PostService::class);
$this->postService = service(PostService::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace {{MODULE_NAMESPACE}}\Middlewares;

use Quantum\Service\Factories\ServiceFactory;
use {{MODULE_NAMESPACE}}\Services\CommentService;
use Quantum\Libraries\Validation\Rule;
use Quantum\Http\Response;
Expand Down Expand Up @@ -66,7 +65,7 @@ class CommentOwner extends BaseMiddleware
private function registerCustomRules(): void
{
$this->validator->addRule('commentOwner', function ($commentUuid) {
$comment = ServiceFactory::get(CommentService::class)->getComment($commentUuid);
$comment = service(CommentService::class)->getComment($commentUuid);
return !$comment->isEmpty() && $comment->user_uuid === auth()->user()->uuid;
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/Module/Templates/DemoApi/src/Middlewares/Password.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.8
* @since 2.9.9
*/

namespace {{MODULE_NAMESPACE}}\Middlewares;

use Quantum\Model\Factories\ModelFactory;
use Quantum\Libraries\Validation\Rule;
use Quantum\Libraries\Hasher\Hasher;
use {{MODULE_NAMESPACE}}\Models\User;
Expand Down Expand Up @@ -73,7 +72,7 @@ class Password extends BaseMiddleware
private function registerCustomRules(Request $request)
{
$this->validator->addRule('passwordCheck', function () use ($request) {
$user = ModelFactory::get(User::class)->findOneBy('uuid', auth()->user()->uuid);
$user = model(User::class)->findOneBy('uuid', auth()->user()->uuid);
return $user && (new Hasher())->check($request->get('current_password'), $user->password);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace {{MODULE_NAMESPACE}}\Middlewares;

use Quantum\Service\Factories\ServiceFactory;
use Quantum\Libraries\Validation\Rule;
use {{MODULE_NAMESPACE}}\Services\PostService;
use Quantum\Http\Response;
Expand Down Expand Up @@ -66,7 +65,7 @@ class PostOwner extends BaseMiddleware
private function registerCustomRules(): void
{
$this->validator->addRule('postOwner', function ($postUuid) {
$post = ServiceFactory::get(PostService::class)->getPost($postUuid);
$post = service(PostService::class)->getPost($postUuid);
return !$post->isEmpty() && $post->user_uuid === auth()->user()->uuid;
});
}
Expand Down
32 changes: 15 additions & 17 deletions src/Module/Templates/DemoApi/src/Models/Comment.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace {{MODULE_NAMESPACE}}\Models;

use Quantum\Libraries\Database\Enums\Relation;
use Quantum\Model\Traits\SoftDeletes;
use Quantum\Model\QtModel;

Expand All @@ -38,34 +39,31 @@ class Comment extends QtModel
*/
public $table = 'comments';

/**
* Fillable properties
* @var array
*/
public $fillable = [
'uuid',
'post_uuid',
'user_uuid',
'content',
'created_at',
'updated_at'
];

/**
* Model relations configuration
* @return array[]
*/
public function relations(): array
{
return [
Post::class => [
'foreign_key' => 'post_uuid',
'local_key' => 'uuid',
],
User::class => [
'type' => Relation::BELONGS_TO,
'foreign_key' => 'user_uuid',
'local_key' => 'uuid',
]
];
}

/**
* Fillable properties
* @var array
*/
public $fillable = [
'uuid',
'post_uuid',
'user_uuid',
'content',
'created_at',
'updated_at'
];
}
30 changes: 16 additions & 14 deletions src/Module/Templates/DemoApi/src/Models/Post.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace {{MODULE_NAMESPACE}}\Models;

use Quantum\Libraries\Database\Enums\Relation;
use Quantum\Model\Traits\SoftDeletes;
use Quantum\Model\QtModel;

Expand All @@ -38,20 +39,6 @@ class Post extends QtModel
*/
public $table = 'posts';

/**
* Model relations configuration
* @return array[]
*/
public function relations(): array
{
return [
User::class => [
'foreign_key' => 'user_uuid',
'local_key' => 'uuid',
]
];
}

/**
* Fillable properties
* @var array
Expand All @@ -65,4 +52,19 @@ class Post extends QtModel
'created_at',
'updated_at',
];

/**
* Model relations configuration
* @return array[]
*/
public function relations(): array
{
return [
User::class => [
'type' => Relation::BELONGS_TO,
'foreign_key' => 'user_uuid',
'local_key' => 'uuid',
]
];
}
}
6 changes: 3 additions & 3 deletions src/Module/Templates/DemoApi/src/Services/AuthService.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ use Quantum\Config\Exceptions\ConfigException;
use Quantum\Model\Exceptions\ModelException;
use Quantum\Libraries\Auth\User as AuthUser;
use Quantum\App\Exceptions\BaseException;
use Quantum\Model\Factories\ModelFactory;
use {{MODULE_NAMESPACE}}\Models\User;
use Quantum\Di\Exceptions\DiException;
use Quantum\Model\ModelCollection;
use Quantum\Service\QtService;
use {{MODULE_NAMESPACE}}\Models\User;
use Quantum\Model\QtModel;
use ReflectionException;

Expand All @@ -40,11 +39,12 @@ class AuthService extends QtService implements AuthServiceInterface
private $model;

/**
* @throws BaseException
* @throws ModelException
*/
public function __construct()
{
$this->model = ModelFactory::get(User::class);
$this->model = model(User::class);
}

/**
Expand Down
Loading