Skip to content

Commit

Permalink
improve package
Browse files Browse the repository at this point in the history
  • Loading branch information
voltan committed Mar 20, 2022
1 parent 785b0be commit 5abb8e4
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/Factory/Repository/AccountRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use User\Model\Account;
use User\Model\Credential;
use User\Model\Account\Account;
use User\Model\Account\Credential;
use User\Repository\AccountRepository;

class AccountRepositoryFactory implements FactoryInterface
Expand Down
12 changes: 6 additions & 6 deletions src/Factory/Repository/PermissionRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use User\Model\PermissionPage;
use User\Model\PermissionResource;
use User\Model\PermissionRole;
use User\Model\Permission\Page;
use User\Model\Permission\Resource;
use User\Model\Permission\Role;
use User\Repository\PermissionRepository;

class PermissionRepositoryFactory implements FactoryInterface
Expand All @@ -29,9 +29,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
return new PermissionRepository(
$container->get(AdapterInterface::class),
new ReflectionHydrator(),
new PermissionResource('', '','','', ''),
new PermissionRole('', '','',''),
new PermissionPage('', '','','','','','','','')
new Resource('', '','','', ''),
new Role('', '','',''),
new Page('', '','','','','','','','')
);
}
}
2 changes: 1 addition & 1 deletion src/Factory/Repository/ProfileRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use User\Model\Profile;
use User\Model\Profile\Profile;
use User\Repository\ProfileRepository;

class ProfileRepositoryFactory implements FactoryInterface
Expand Down
6 changes: 3 additions & 3 deletions src/Factory/Repository/RoleRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use User\Model\Role;
use User\Model\RoleAccount;
use User\Model\Role\Role;
use User\Model\Role\Account;
use User\Repository\RoleRepository;

class RoleRepositoryFactory implements FactoryInterface
Expand All @@ -29,7 +29,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$container->get(AdapterInterface::class),
new ReflectionHydrator(),
new Role('', '', ''),
new RoleAccount(0, '', '')
new Account(0, '', '')
);
}
}
2 changes: 1 addition & 1 deletion src/Model/Account.php → src/Model/Account/Account.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace User\Model;
namespace User\Model\Account;

class Account
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace User\Model;
namespace User\Model\Account;

class Credential
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace User\Model;
namespace User\Model\Permission;

class PermissionPage
class Page
{
private $id;
private string $title;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace User\Model;
namespace User\Model\Permission;

class PermissionResource
class Resource
{
private $id;
private string $title;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace User\Model;
namespace User\Model\Permission;

class PermissionRole
class Role
{
private $id;
private string $resource;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Profile.php → src/Model/Profile/Profile.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace User\Model;
namespace User\Model\Profile;

class Profile
{
Expand Down
4 changes: 2 additions & 2 deletions src/Model/RoleAccount.php → src/Model/Role/Account.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace User\Model;
namespace User\Model\Role;

class RoleAccount
class Account
{
private $id;
private ?int $user_id;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Role.php → src/Model/Role/Role.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace User\Model;
namespace User\Model\Role;

class Role
{
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/AccountRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Laminas\Db\Sql\Update;
use Laminas\Hydrator\HydratorInterface;
use RuntimeException;
use User\Model\Account;
use User\Model\Credential;
use User\Model\Account\Account;
use User\Model\Account\Credential;

class AccountRepository implements AccountRepositoryInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/AccountRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Laminas\Authentication\AuthenticationService;
use Laminas\Db\ResultSet\HydratingResultSet;
use User\Model\Account;
use User\Model\Account\Account;

interface AccountRepositoryInterface
{
Expand Down
41 changes: 22 additions & 19 deletions src/Repository/PermissionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Hydrator\HydratorInterface;
use User\Model\PermissionPage;
use User\Model\PermissionResource;
use User\Model\PermissionRole;
use User\Model\Permission\Page;
use User\Model\Permission\Resource;
use User\Model\Permission\Role;

class PermissionRepository implements PermissionRepositoryInterface
{
/**
* Permission resource Table name
*
* @var string
*/
private string $tablePermissionResource = 'permission_resource';
private string $tableresource = 'permission_resource';

/**
* Permission rule Table name
*
* @var string
*/
private string $tablePermissionRule = 'permission_rule';

/**
* Permission page Table name
*
* @var string
*/
private string $tablePermissionPage = 'permission_page';
private string $tablepage = 'permission_page';

/**
* @var AdapterInterface
Expand All @@ -39,31 +42,31 @@ class PermissionRepository implements PermissionRepositoryInterface
private HydratorInterface $hydrator;

/**
* @var PermissionResource
* @var Resource
*/
private PermissionResource $permissionResourcePrototype;
private Resource $resourcePrototype;

/**
* @var PermissionRole
* @var Role
*/
private PermissionRole $permissionRolePrototype;
private Role $rolePrototype;

/**
* @var PermissionPage
* @var Page
*/
private PermissionPage $permissionPagePrototype;
private Page $pagePrototype;

public function __construct(
AdapterInterface $db,
HydratorInterface $hydrator,
PermissionResource $permissionResourcePrototype,
PermissionRole $permissionRolePrototype,
PermissionPage $permissionPagePrototype
Resource $resourcePrototype,
Role $rolePrototype,
Page $pagePrototype
) {
$this->db = $db;
$this->hydrator = $hydrator;
$this->permissionResourcePrototype = $permissionResourcePrototype;
$this->permissionRolePrototype = $permissionRolePrototype;
$this->permissionPagePrototype = $permissionPagePrototype;
$this->db = $db;
$this->hydrator = $hydrator;
$this->resourcePrototype = $resourcePrototype;
$this->rolePrototype = $rolePrototype;
$this->pagePrototype = $pagePrototype;
}
}
2 changes: 1 addition & 1 deletion src/Repository/ProfileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Hydrator\HydratorInterface;
use User\Model\Profile;
use User\Model\Profile\Profile;

class ProfileRepository implements AccountRoleRepositoryInterface
{
Expand Down
32 changes: 17 additions & 15 deletions src/Repository/RoleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
use Laminas\Db\Sql\Sql;
use Laminas\Db\Sql\Update;
use Laminas\Hydrator\HydratorInterface;
use User\Model\Role;
use User\Model\RoleAccount;
use User\Model\Role\Role;
use User\Model\Role\Account;
use RuntimeException;
use InvalidArgumentException;

class RoleRepository implements RoleRepositoryInterface
{
/**
* Role Table name
*
* @var string
*/
private string $tableRole = 'role';

/**
* Role Account Table name
*
* @var string
*/
private string $tableRoleAccount = 'role_account';
private string $tableaccount = 'role_account';

/**
* @var AdapterInterface
Expand All @@ -45,20 +47,20 @@ class RoleRepository implements RoleRepositoryInterface
private Role $rolePrototype;

/**
* @var RoleAccount
* @var Account
*/
private RoleAccount $roleAccountPrototype;
private Account $accountPrototype;

public function __construct(
AdapterInterface $db,
HydratorInterface $hydrator,
Role $rolePrototype,
RoleAccount $roleAccountPrototype
Account $accountPrototype
) {
$this->db = $db;
$this->hydrator = $hydrator;
$this->rolePrototype = $rolePrototype;
$this->roleAccountPrototype = $roleAccountPrototype;
$this->db = $db;
$this->hydrator = $hydrator;
$this->rolePrototype = $rolePrototype;
$this->accountPrototype = $accountPrototype;
}

public function getRoleList($params = []): HydratingResultSet
Expand Down Expand Up @@ -180,7 +182,7 @@ public function deleteRole(string $roleName): void
}

// Delete from role_account table
$delete = new Delete($this->tableRoleAccount);
$delete = new Delete($this->tableaccount);
$delete->where(['role' => $roleName]);

$sql = new Sql($this->db);
Expand All @@ -203,7 +205,7 @@ public function getUserRole($userId, $section = ''): HydratingResultSet
}

$sql = new Sql($this->db);
$select = $sql->select($this->tableRoleAccount)->where($where);
$select = $sql->select($this->tableaccount)->where($where);
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();

Expand All @@ -216,7 +218,7 @@ public function getUserRole($userId, $section = ''): HydratingResultSet
);
}

$resultSet = new HydratingResultSet($this->hydrator, $this->roleAccountPrototype);
$resultSet = new HydratingResultSet($this->hydrator, $this->accountPrototype);
$resultSet->initialize($result);

return $resultSet;
Expand All @@ -230,7 +232,7 @@ public function addUserRole(int $userId, string $roleName, string $section = 'ap
'section' => $section,
];

$insert = new Insert($this->tableRoleAccount);
$insert = new Insert($this->tableaccount);
$insert->values($value);

$sql = new Sql($this->db);
Expand All @@ -246,7 +248,7 @@ public function addUserRole(int $userId, string $roleName, string $section = 'ap

public function deleteUserRole(int $userId, string $roleName): void
{
$delete = new Delete($this->tableRoleAccount);
$delete = new Delete($this->tableaccount);
$delete->where(['user_id' => $userId, 'role' => $roleName]);

$sql = new Sql($this->db);
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/RoleRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace User\Repository;

use Laminas\Db\ResultSet\HydratingResultSet;
use User\Model\Role;
use User\Model\RoleAccount;
use User\Model\Role\Role;

interface RoleRepositoryInterface
{
Expand Down

0 comments on commit 5abb8e4

Please sign in to comment.