-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Maykonn/psr4
Fixed autoload psr-4 and bug fix
- Loading branch information
Showing
17 changed files
with
201 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
test/ | ||
vendor/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.