Last active
August 29, 2015 14:20
-
-
Save etki/1d68ef7e8041ebc1186a to your computer and use it in GitHub Desktop.
Interfaces
This file contains hidden or 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
<?php | |
class Application | |
{ | |
private $cache; | |
private $filesystem; | |
public function __construct(CacheInterface $cache, FilesystemInterface $filesystem) | |
{ | |
$this->cache = $cache; | |
$this->filesystem = $filesystem; | |
} | |
public function clearCache() | |
{ | |
foreach ($this->cache->getTemporaryFiles() as $file) { | |
$this->filesystem->removeFile($file); | |
} | |
} | |
} |
This file contains hidden or 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
<?php | |
// конечно, в PHP нет никакого system, описывающего ОС, но давайте представим, что есть | |
$filesystem = $system->getFilesystemApi(); | |
if ($system->getType() === 'THETA') { | |
$filesystemAdapter = new ThetaFilesystemAdapter($filesystem); | |
} else { | |
$filesystemAdapter = new LambdaFilesystemAdapter($filesystem); | |
} | |
$application = new Application(new FilesystemCache, $filesystemAdapter); | |
$application->clearCache(); |
This file contains hidden or 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
<?php | |
interface FielsystemInteface | |
{ | |
public removeFile($path); | |
} |
This file contains hidden or 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
<?php | |
class LambdaFilesystemAdapter implements FielsystemInteface | |
{ | |
private $filesystem; | |
// какая-нибудь тупая система, которой ну прям ОБЯЗАТЕЛЬНо нужны транзакции | |
public function __construct(LambdaFilesystem $filesystem) | |
{ | |
$this->filesystem = $filesystem; | |
} | |
public function removeFile($path) | |
{ | |
$this->filesystem->startAwkwardTransaction(); | |
$this->filesystem->delete($path); | |
$this->filesystem->commitAwkwardTransaction(); | |
} | |
} |
This file contains hidden or 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
<?php | |
class ThetaFilesystemAdapter implements FielsystemInteface | |
{ | |
private $filesystem; | |
// система, которая принимает на вход только объекты класса URL | |
public function __construct(ThetaFilesystem $filesystem) | |
{ | |
$this->filesystem = $filesystem; | |
} | |
public function removeFile($path) | |
{ | |
$url = new URL($path); | |
$this->filesystem->erase($url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment