Skip to content

Commit

Permalink
Merge pull request #10 from Maykonn/psr4
Browse files Browse the repository at this point in the history
Fixed autoload psr-4 and bug fix
  • Loading branch information
Maykonn authored May 28, 2018
2 parents 5693d86 + b8132f6 commit d2d612c
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
test/
vendor/
130 changes: 0 additions & 130 deletions Entity.php

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "maykonn/rapid-authorization",
"type": "library",
"description": "RapidAuthorization is a PHP framework for Access Control, based in Role-based Access Control (RBAC)",
"keywords": ["access control", "role-based access control", "role based access control", "rbac", "framework"],
"keywords": ["PHP", "access control", "role-based access control", "role based access control", "rbac", "framework"],
"homepage": "https://github.com/Maykonn/RapidAuthorization",
"license": "MIT",
"authors": [
Expand All @@ -15,8 +15,8 @@
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"RapidAuthorization": ""
"psr-4": {
"RapidAuthorization\\": "src/"
}
}
}
19 changes: 19 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 126 additions & 0 deletions src/AbstractEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

/**
* Entity
*
* @author Maykonn Welington Candido<[email protected]>
*/

namespace RapidAuthorization;

use \PDO;
use \ArrayObject;

abstract class AbstractEntity implements IEntity
{
/**
* @var ClientPreferences
*/
protected $preferences;

/**
* @var ArrayObject
*/
protected $preferencesList;

/**
* @var $this
*/
protected static $instance;


/**
* @var PDO
*/
protected $db;

public $id = 0;
public $name = '';
public $business_name = '';
public $description = null;

protected function __construct(ClientPreferences $preferences, PDO $pdo)
{
$this->preferences = $preferences;
$this->preferencesList = $this->preferences->getPreferencesList();
$this->db = $pdo;
}

public static function getInstance()
{
return self::$instance;
}

public function create($businessName, $name = null, $description = null)
{
$this->name = $name;
$this->business_name = $businessName;
$this->description = $description;

return $this->save();
}

/**
* <p>Set '' to $description to set NULL on database</p>
*/
public function update($id, $businessName, $name = null, $description = null)
{
if ($this->populateById($id)) {
$this->id = $id;
$this->business_name = $businessName;

if ($name !== null) {
$this->name = $name;
}

if ($description !== null) {
$this->description = $description;
}

return $this->save();
}

return 0;
}

/**
* <p>Populate object with values from record on database</p>
*/
private function populateById($roleId)
{
$task = $this->findById($roleId);

if ($task) {
$this->id = (int) $task['id'];
$this->name = $task['name'];
$this->business_name = $task['business_name'];
$this->description = $task['description'];

return true;
}

return false;
}

protected function saveFromSQL($sql)
{
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $this->id, PDO::PARAM_INT);
$stmt->bindParam(':businessName', $this->business_name, PDO::PARAM_STR);

$name = ($this->name ? $this->name : null);
$stmt->bindParam(':name', $name);

$description = ($this->description ? $this->description : null);
$stmt->bindParam(':description', $description);

$stmt->execute();

if ( ! $this->id) {
$this->id = (int) $this->db->lastInsertId();
}

return $this->id = (int) $this->id;
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions src/IEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* IEntity
*
* @author Maykonn Welington Candido<[email protected]>
*/

namespace RapidAuthorization;

interface IEntity
{
public static function instance(ClientPreferences $preferences, \PDO $pdo);
}
16 changes: 9 additions & 7 deletions Operation.php → src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
use \Exception;
use RapidAuthorization\Database\MySQL;

class Operation extends Entity
class Operation extends AbstractEntity
{

public $id = 0;
public $name = '';
public $business_name = '';
public $description = null;

/**
* Verify if needs to check the authorization, see Operation::populateById()
* @var Enum '1', '0'
*/
public $needs_authorization = '1';

/**
* @return $this
*/
public static function instance(ClientPreferences $preferences, PDO $pdo)
{
return self::$instance = new self($preferences, $pdo);
}

/**
* <p>An Operation can be, e.g. Create Product or Edit Customer</p>
*/
Expand Down
4 changes: 2 additions & 2 deletions RapidAuthorization.php → src/RapidAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace RapidAuthorization;

// Necessárias antes do Autoload
require_once 'ClientPreferences.php';
/*require_once 'ClientPreferences.php';
require_once 'AvailablePreferences.php';
require_once 'Autoload.php';

*/
use RapidAuthorization\Database\MySQL;
use RapidAuthorization\Database\MySQLSchemaHandler;

Expand Down
10 changes: 9 additions & 1 deletion Role.php → src/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
use \Exception;
use RapidAuthorization\Database\MySQL;

class Role extends Entity
class Role extends AbstractEntity
{
/**
* @return $this
*/
public static function instance(ClientPreferences $preferences, PDO $pdo)
{
return self::$instance = new self($preferences, $pdo);
}

public function delete($id)
{
if($this->findById($id)) {
Expand Down
10 changes: 9 additions & 1 deletion Task.php → src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
use \Exception;
use RapidAuthorization\Database\MySQL;

class Task extends Entity
class Task extends AbstractEntity
{
/**
* @return $this
*/
public static function instance(ClientPreferences $preferences, PDO $pdo)
{
return self::$instance = new self($preferences, $pdo);
}

public function delete($id)
{
if($this->findById($id)) {
Expand Down
Loading

0 comments on commit d2d612c

Please sign in to comment.