-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c637f0
commit 245d02a
Showing
5 changed files
with
67 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PBaszak\DedicatedMapper; | ||
|
||
use PBaszak\DedicatedMapper\Reflection\ClassReflection; | ||
use PBaszak\DedicatedMapper\Reflection\ReflectionFactory; | ||
|
||
class Config | ||
{ | ||
/** @var array<string> */ | ||
protected array $usedFiles = []; | ||
protected ClassReflection $classReflection; | ||
|
||
/** | ||
* @param class-string $className | ||
*/ | ||
public function __construct(private string $className) | ||
{ | ||
if (!class_exists($this->className, false)) { | ||
throw new \InvalidArgumentException( | ||
sprintf('Class %s does not exist', $this->className) | ||
); | ||
} | ||
} | ||
|
||
public function reflect(): self | ||
{ | ||
$this->classReflection = (new ReflectionFactory())->createClassReflection($this->className, null); | ||
|
||
return $this; | ||
} | ||
|
||
public function getClassReflection(): ClassReflection | ||
{ | ||
return $this->classReflection; | ||
} | ||
|
||
public function export(): array | ||
{ | ||
return [ | ||
'className' => $this->className, | ||
'classReflection' => $this->classReflection, | ||
'usedFiles' => $this->usedFiles, | ||
]; | ||
} | ||
|
||
public static function import(array $data): self | ||
{ | ||
$config = new self($data['className']); | ||
$config->classReflection = $data['classReflection']; | ||
$config->usedFiles = $data['usedFiles']; | ||
|
||
return $config; | ||
} | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
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