Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
drobotik committed May 29, 2023
1 parent 4456368 commit f6a6696
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 101 deletions.
125 changes: 24 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
Expand All @@ -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.<br />
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).

Expand Down
42 changes: 42 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
@@ -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.<br />
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
11 changes: 11 additions & 0 deletions docs/eav.md
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -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();
```

0 comments on commit f6a6696

Please sign in to comment.