atomatis / ofm
此包最新版本(1.0.2)无可用许可证信息。
对象文件映射器
1.0.2
2022-05-12 09:53 UTC
Requires
- php: 8.*
- php-school/cli-menu: ^4.2
- symfony/property-access: ^6.0
- symfony/serializer: ^6.0
- symfony/yaml: ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^6.0
This package is not auto-updated.
Last update: 2024-09-26 21:36:32 UTC
README
由 doctrine/ORM 包启发的对象文件操作工具
警告。我写这个是为了个人使用。文档非常糟糕。如果您对此包感兴趣,请通过alexandre.tomatis@gmail.com与我联系,以获取更好的文档。
安装
composer req atomatis/OFM
使用
创建实体
yaml文件示例
<?php declare(strict_types=1); namespace App\Entity; use Atomatis\OFM as OFM; #[OFM\Entity(OFM\Entity::TYPE_YAML)] final class Configuration { #[OFM\Parameter] private ?string $foo; #[OFM\Parameter] private ?array $bar; ... // getter/setter ...
配置
// init registry with Entity file path. $registry = new Registry(); $registry->addFile(Configuration::class, (new RegistryConfiguration())->setPath('my/file/path/configuration.yaml')); $entityManager = new EntityManager($registry);
加载文件
# my/file/path/configuration.yaml foo: 'hello here'
$configuration = $entityManager->load(Configuration::class); $configuration->getFoo(); // return 'hello here' $configuration->getBar(); // return null
刷新文件
# my/file/path/configuration.yaml foo: 'hello here'
$configuration = $entityManager->load(Configuration::class); $configuration->setFoo('see you later'); $entityManager->flush($configuration);
# my/file/path/configuration.yaml foo: 'see you later'