diff --git a/application/src/Domain/AbstractDomainService.php b/application/src/Domain/AbstractDomainService.php new file mode 100644 index 0000000..8992f3a --- /dev/null +++ b/application/src/Domain/AbstractDomainService.php @@ -0,0 +1,7 @@ +source = $source; + $this->branches = new ArrayCollection(); + $this->leaves = new ArrayCollection(); + } + + private function sortMember(SourceInterface $member):bool{ + if($member instanceof TreeCollectionSource){ + return $this->branches->add($member); + } + return $this->leaves->add($member); + } + + private function basicSort():void{ + foreach($this->source->getCollection() as $member){ + $this->sortMember($member); + } + } + + public function getBranches(): Collection + { + return $this->branches; + } + + /** + * @todo Remove the optional parameter and put the logic in a private funtion. + * @todo Remove the getAllBranches use inside the function. + * {@inheritDoc} + * @see \App\Domain\SourceManagement\TreeSourceServiceInterface::getAllBranches() + */ + public function getAllBranches(?ArrayCollection $excludedBranches=null): Collection + { + if(!$excludedBranches){ + $excludedBranches = new ArrayCollection(); + } + $branches = new ArrayCollection($this->branches->toArray()); + foreach($this->branches->toArray() as $branch){ + if(!$excludedBranches->contains($branch)){ + foreach((new TreeSourceService($branch))->getAllBranches($excludedBranches) as $branchBranch){ + $branches->add($branchBranch); + } + } + } + return $branches; + } + + public function getLeaves(): Collection + { + return $this->leaves; + } + + public function getAllLeaves(): Collection + { + $leaves = new ArrayCollection(); + foreach ($this->getAllBranches()->toArray() as $branch){ + foreach ((new TreeSourceService($branch))->getLeaves() as $leave){ + if(!$leaves->contains($leave)){ + $leaves->add($leave); + } + } + } + } + +} \ No newline at end of file diff --git a/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php b/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php new file mode 100644 index 0000000..8aa7da9 --- /dev/null +++ b/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php @@ -0,0 +1,32 @@ +