diff --git a/README.md b/README.md index f9bce18..3c5e173 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,27 @@ # EAV package -A tool to manage and maintain EAV master data across multiple domains. +Manage, manipulate EAV data across multiple domains. CRUD/import/export entities, manage attribute sets and groups. +Configurable attributes, attribute strategies with hooks. +It's ideas from "Magento way". App oriented for custom CMS. -## Requirements +Currently, it dependent from Illuminate\database Laravel models, they are used for this structure tables: +domain, entity, attribute_set, attribute_group, attribute, pivot, +string_value, integer_value, decimal_value, datetime_value, text_value. + +### Features +- single entity CRUD +- import attribute set, bulk create new, update/delete existing, csv driver +- export attribute set, query builder + +### Requirements - PHP >=8.1 -- Illuminate\database ^9.0|^10.0 +- Illuminate\database - Illuminate\validator ^9.0|^10.0 - Illuminate\translation ^9.0|^10.0 -## Getting started -Composer +[Documentation](./docs/eav.md) + +### Installation ```bash composer require drobotik/eav ``` @@ -22,111 +34,22 @@ $ composer install $ php eav ``` -### Database connection -EAV uses Laravel Capsule for connections. -For Laravel apps, it's trying to use default connection and can be used as is. -For other cases, initialize a Capsule instance: -```php -$capsule = new Capsule; -$capsule->addConnection([ - // connection settings -]); -$this->capsule = $capsule; -$capsule->setAsGlobal(); -$capsule->bootEloquent(); -``` - -### Work with migrations, cli-application -CLI app relies on a database connection. It uses [Doctrine DBAL](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#configuration) to perform connections.
-There isn't any pre-configured connection information. For non-docker environments is required to set up a connection. -As an option, make a new file connection.php in root folder. This file will be automatically included. -```php -#connection.php -use Drobotik\Eav\Database\Connection; -$config = [ - // connection settings -] -$connection = Connection::get($config) -``` -Note use a [driver](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver) that suits your needs. - -Migrate: -```bash -$ php eav migrations:migrate latest -``` - - -### Laravel migrations support -It also contains laravel migrations for publishing on Laravel app. Add EavServiceProvider to -providers config array. -```php -\Drobotik\Eav\Database\Support\Laravel\EavServiceProvider::class -``` -Publish migrations by vendor:publish. -### Raw schema dump -Use dump.sql placed on root folder. - -## Docs - -Documentation in progress.. - -## Example - - -```php -// make data -$domain = $this->eavFactory->createDomain(); -$attrSet = $this->eavFactory->createAttributeSet($domain); -$group = $this->eavFactory->createGroup($attrSet); -$stringAttribute = $this->eavFactory->createAttribute($domain, [ - _ATTR::NAME->column() => "name", - _ATTR::TYPE->column() => ATTR_TYPE::STRING->value() -]); -$integerAttribute = $this->eavFactory->createAttribute($domain, [ - _ATTR::NAME->column() => "age", - _ATTR::TYPE->column() => ATTR_TYPE::INTEGER->value() -]); -$this->eavFactory->createPivot($domain, $attrSet, $group, $stringAttribute); -$this->eavFactory->createPivot($domain, $attrSet, $group, $integerAttribute); -$data = [ - "name" => $this->faker->name, - "age" => $this->faker->randomNumber(), -]; -// create new -$entity = new Entity(); -$entity->setDomainKey($domain->getKey()); -$entity->getAttributeSet()->setKey($attrSet->getKey()); -$entity->getBag()->setFields($data); -$result = $entity->save(); -$id = $entity->getKey() -// find -$entity = new Entity(); -$entity->find($id); -$data = $entity->toArray(); -// update -$entity->getBag()->setField("name", "new name") -$result = $entity->save(); -// delete -$entity->delete(); -``` - -## Planned features +### Planned features -* Domain import/export (csv/excel) -* Option to use separated tables for ValueModels -* Attribute props +* ~~Domain import/export csv~~ +* Attribute props +* removing Illuminate\database dependency, Impl folder -## Contributing +### Contributing -Contributions are welcome. -Please note the following guidelines before submitting your pull request. +Please note the following guidelines before submitting pull request. - Follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standards - Create feature branches, one pull request per feature - Implement your change and add tests for it - Ensure the test suite passes -## License +### License Eav package is licensed under the [MIT License](http://opensource.org/licenses/MIT). diff --git a/docs/database.md b/docs/database.md new file mode 100644 index 0000000..e170ee0 --- /dev/null +++ b/docs/database.md @@ -0,0 +1,42 @@ +### Connection +Library uses Laravel Capsule for connections. +For Laravel apps, it's trying to use default connection and can be used as is. +For other cases, initialize a Capsule instance: +```php +$capsule = new Capsule; +$capsule->addConnection([ + // connection settings +]); +$this->capsule = $capsule; +$capsule->setAsGlobal(); +$capsule->bootEloquent(); +``` + +### Work with migrations, cli-application +CLI app relies on a database connection. It uses [Doctrine DBAL](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#configuration) to perform connections.
+There isn't any pre-configured connection information. For non-docker environments is required to set up a connection. +As an option, make a new file connection.php in root folder. This file will be automatically included. +```php +#connection.php +use Drobotik\Eav\Database\Connection; +$config = [ + // connection settings +] +$connection = Connection::get($config) +``` +Note use a [driver](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver) that suits your needs. + +Migrate: +```bash +$ php eav migrations:migrate latest +``` + +### Laravel migrations support +It also contains laravel migrations for publishing on Laravel app. Add EavServiceProvider to +providers config array. +```php +\Drobotik\Eav\Database\Support\Laravel\EavServiceProvider::class +``` +Publish migrations by vendor:publish. + +## Example \ No newline at end of file diff --git a/docs/eav.md b/docs/eav.md new file mode 100644 index 0000000..7477344 --- /dev/null +++ b/docs/eav.md @@ -0,0 +1,11 @@ +## Documentation + +- [database](./database.md) +- [entity](./examples.md) +- [attribute](./examples.md) +- [attribute set](./examples.md) +- [attribute group](./examples.md) +- [value](./examples.md) +- [import](./examples.md) +- [export](./examples.md) +- [examples](./examples.md) \ No newline at end of file diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..4029f56 --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,36 @@ +```php +// make data +$domain = $this->eavFactory->createDomain(); +$attrSet = $this->eavFactory->createAttributeSet($domain); +$group = $this->eavFactory->createGroup($attrSet); +$stringAttribute = $this->eavFactory->createAttribute($domain, [ + _ATTR::NAME->column() => "name", + _ATTR::TYPE->column() => ATTR_TYPE::STRING->value() +]); +$integerAttribute = $this->eavFactory->createAttribute($domain, [ + _ATTR::NAME->column() => "age", + _ATTR::TYPE->column() => ATTR_TYPE::INTEGER->value() +]); +$this->eavFactory->createPivot($domain, $attrSet, $group, $stringAttribute); +$this->eavFactory->createPivot($domain, $attrSet, $group, $integerAttribute); +$data = [ + "name" => $this->faker->name, + "age" => $this->faker->randomNumber(), +]; +// create new +$entity = new Entity(); +$entity->setDomainKey($domain->getKey()); +$entity->getAttributeSet()->setKey($attrSet->getKey()); +$entity->getBag()->setFields($data); +$result = $entity->save(); +$id = $entity->getKey() +// find +$entity = new Entity(); +$entity->find($id); +$data = $entity->toArray(); +// update +$entity->getBag()->setField("name", "new name") +$result = $entity->save(); +// delete +$entity->delete(); +``` \ No newline at end of file