Improved singleton implementation
This commit is contained in:
parent
5c88c8ac2a
commit
1a5f38f6de
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
class FileDownloader extends FileManager {
|
||||
use SingletonTrait;
|
||||
|
||||
public function download() {
|
||||
$fullFilePath = $this->getFullFilePath();
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
abstract class FileManager {
|
||||
use SingletonTrait;
|
||||
private $fileName;
|
||||
private $localPath = 'files/';
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue