Improved singleton implementation

This commit is contained in:
Sam Mousa 2018-11-19 14:27:42 +01:00
parent 5c88c8ac2a
commit 1a5f38f6de
No known key found for this signature in database
GPG Key ID: A18520F9B4301C9D
4 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,8 @@
<?php
class FileDownloader extends FileManager {
use SingletonTrait;
public function download() {
$fullFilePath = $this->getFullFilePath();

View File

@ -1,7 +1,6 @@
<?php
abstract class FileManager {
use SingletonTrait;
private $fileName;
private $localPath = 'files/';

View File

@ -1,13 +1,14 @@
<?php
class FileUploader extends FileManager {
use SingletonTrait;
private $maxSize = 1;
private $fileName;
private $permission;
private $storage;
protected function __construct() {
parent::__construct();
private function __construct() {
$this->storage = new \Upload\Storage\FileSystem($this->getLocalPath());
}

View File

@ -1,10 +1,15 @@
<?php
/**
* Trait SingletonTrait
* This trait helps implementing singleton classes
* It must be used on each class in a hierarchy that needs to be a singleton
*/
trait SingletonTrait
{
private static $instance;
protected static $instance;
protected function __construct()
private function __construct()
{
}