Improved singleton implementation
This commit is contained in:
parent
5c88c8ac2a
commit
1a5f38f6de
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class FileDownloader extends FileManager {
|
class FileDownloader extends FileManager {
|
||||||
|
use SingletonTrait;
|
||||||
|
|
||||||
public function download() {
|
public function download() {
|
||||||
$fullFilePath = $this->getFullFilePath();
|
$fullFilePath = $this->getFullFilePath();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
abstract class FileManager {
|
abstract class FileManager {
|
||||||
use SingletonTrait;
|
|
||||||
private $fileName;
|
private $fileName;
|
||||||
private $localPath = 'files/';
|
private $localPath = 'files/';
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class FileUploader extends FileManager {
|
class FileUploader extends FileManager {
|
||||||
|
use SingletonTrait;
|
||||||
|
|
||||||
private $maxSize = 1;
|
private $maxSize = 1;
|
||||||
private $fileName;
|
private $fileName;
|
||||||
private $permission;
|
private $permission;
|
||||||
private $storage;
|
private $storage;
|
||||||
|
|
||||||
protected function __construct() {
|
private function __construct() {
|
||||||
parent::__construct();
|
|
||||||
$this->storage = new \Upload\Storage\FileSystem($this->getLocalPath());
|
$this->storage = new \Upload\Storage\FileSystem($this->getLocalPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
<?php
|
<?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
|
trait SingletonTrait
|
||||||
{
|
{
|
||||||
private static $instance;
|
protected static $instance;
|
||||||
|
|
||||||
protected function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue