Skip to content

Instantly share code, notes, and snippets.

@leroy
Created April 20, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leroy/69261b74554971c8bc320345a34eee91 to your computer and use it in GitHub Desktop.
Save leroy/69261b74554971c8bc320345a34eee91 to your computer and use it in GitHub Desktop.
<?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