Created
April 20, 2021 14:03
-
-
Save leroy/69261b74554971c8bc320345a34eee91 to your computer and use it in GitHub Desktop.
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
<?php | |
interface Component { | |
} | |
class ProjectType extends Enum { | |
const BEDROCK = 'bedrock'; | |
const THEMOSIS = 'themosis'; | |
} | |
class ProjectTypeComponent { | |
public ProjectType $projectType; | |
public function __construct(ProjectType $projectType) | |
{ | |
$this->projectType = $projectType; | |
} | |
} | |
class Project { | |
private $components; | |
public function getComponent($class) | |
{ | |
return $this->components[$class]; | |
} | |
public function addComponent(Component $component) | |
{ | |
$this->components[$component::class] = $component; | |
} | |
} | |
interface ProjectResolverStrategy { | |
public function resolve(Project $project): Project; | |
} | |
class ProjectTypeStrategy implements projectResolverStrategy { | |
public function __construct(Repository $repository) | |
{ | |
$this->repository = $repository; | |
} | |
public function resolve(Project $project): Project | |
{ | |
$projectType = null; | |
if (is_dir($this->repository->getPath('/web'))) { | |
$projectType = ProjectType::BEDROCK; | |
} | |
if (is_dir($this->repository->getPath('/htdocs'))) { | |
$projectType = ProjectType::THEMOSIS; | |
} | |
if ($projectType !== null) { | |
$project->addComponent(new ProjectTypeComponent($projectType)); | |
} | |
return $project; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment