This repository has been archived by the owner on Apr 10, 2020. It is now read-only.
-
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
0 parents
commit 0b8bb42
Showing
22 changed files
with
1,162 additions
and
0 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,8 @@ | ||
/tests export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/phpcs.xml export-ignore | ||
/PULL_REQUEST_TEMPLATE.md export-ignore | ||
/CODE_OF_CONDUCT.md export-ignore | ||
/CONTRIBUTING.md export-ignore |
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,2 @@ | ||
/vendor | ||
/composer.lock |
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,17 @@ | ||
language: php | ||
php: | ||
- '7.2' | ||
- '7.3' | ||
|
||
before_script: | ||
- yes '' | pecl install yaml | ||
- composer install | ||
|
||
script: | ||
- composer validate --strict | ||
- vendor/bin/phpunit --coverage-text | ||
- vendor/bin/phpcs src/ tests/ | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache |
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,26 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 1.0.0 - 2019-11-17 | ||
### Added | ||
- Created the initial implementation of the ObjectFactory. | ||
|
||
### Changed | ||
- Nothing | ||
|
||
### Deprecated | ||
- Nothing | ||
|
||
### Removed | ||
- Nothing | ||
|
||
### Fixed | ||
- Nothing | ||
|
||
### Security | ||
- Nothing | ||
|
||
[Unreleased]: https://github.com/ulrack/object-factory/compare/1.0.0...HEAD |
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,76 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
level of experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at info@jyxon.com. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see | ||
https://www.contributor-covenant.org/faq |
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,28 @@ | ||
# Contributing | ||
|
||
To contribute to this package, please keep to these guidelines. | ||
|
||
- Fork the package. | ||
- Create a branch per feature. | ||
- Commit your changes to these branches. | ||
- Create a pull request per feature to the master branch of the original repository. | ||
|
||
## Pull requests | ||
|
||
Pull request should follow these rules, before they can get accepted. | ||
|
||
- Follow the [pull request template](PULL_REQUEST_TEMPLATE.md). | ||
- Contains a short but complete description. | ||
- Has passed all test command listed bellow. | ||
|
||
## Running Tests | ||
|
||
``` bash | ||
$ vendor/bin/phpunit --coverage-text | ||
$ vendor/bin/phpcs src/ tests/ | ||
``` | ||
|
||
## Notes | ||
|
||
Multiple commits per feature are allowed, but please provide a good description in your pull request. | ||
This description will be used to squash your feature into the master branch. |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Jyxon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,18 @@ | ||
# (bugfix / feature / refactor / etc.): Short descriptive title | ||
|
||
## Description | ||
|
||
Fixes # | ||
|
||
Changes proposed in this pull request: | ||
- | ||
- | ||
- | ||
|
||
Make sure you can check the following boxes before submitting the pull request: | ||
- [] The proposed changes work with the dependencies from composer. | ||
- [] The proposed changes have been thoroughly tested. | ||
- [] The proposed changes don't alter the code in such a manner that it conflicts with the initial purpose of the package. | ||
|
||
Optional checkbox | ||
- [] Backwards incompatible |
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,164 @@ | ||
[![Build Status](https://travis-ci.com/ulrack/object-factory.svg?branch=master)](https://travis-ci.com/ulrack/object-factory) | ||
|
||
# Ulrack Object Factory | ||
|
||
The Object Factory package contains an implementation for creating objects, | ||
based on configuration. | ||
|
||
## Installation | ||
|
||
To install the package run the following command: | ||
|
||
``` | ||
composer require ulrack/object-factory | ||
``` | ||
|
||
## Usage | ||
|
||
The package provides a [Analyser](src/Component/Analyser/ClassAnalyser.php) | ||
class, which retrieves an instantiation signature of a class. | ||
This analyser is used by the [ObjectFactory](src/Factory/ObjectFactory.php) to | ||
determine the order of the provided parameter from the configuration. | ||
The analyser expects an implementation of the StorageInterface from the | ||
`ulrack/storage` package. | ||
This implementation can be used to store previous analyses and retrieve them at | ||
a later point (caching mechanisms e.g.). | ||
|
||
Creating an ObjectFactory can simply be done with the following snippet: | ||
```php | ||
<?php | ||
|
||
use Ulrack\Storage\Component\ObjectStorage; | ||
use Ulrack\ObjectFactory\Factory\ObjectFactory; | ||
use Ulrack\ObjectFactory\Component\Analyser\ClassAnalyser; | ||
|
||
$factory = new ObjectFactory(new ClassAnalyser(new ObjectStorage())) | ||
``` | ||
|
||
To create an object with the factory, simply pass the class and parameters to | ||
the create method. | ||
|
||
```php | ||
<?php | ||
|
||
use Ulrack\Storage\Component\ObjectStorage; | ||
|
||
/** @var ObjectStorage $result */ | ||
$result = $factory->create( | ||
ObjectStorage::class, | ||
[ | ||
'data' => ['foo'] | ||
] | ||
); | ||
``` | ||
|
||
A key-value structure is used for the parameters provided to the ObjectFactory. | ||
If (in this case the ObjectStorage class) expects a `$data` parameter of the | ||
type array in the `__construct` method, then the structure of the `$parameter` | ||
parameter will be as follows: | ||
```php | ||
$parameters = [ | ||
'data' => [/** Value of $data here. */] | ||
]; | ||
``` | ||
|
||
For variadic parameters, this structure is the same. | ||
|
||
### Object nesting | ||
|
||
Some objects require other objects in their `__construct` method. With the | ||
ObjectFactory it is also possible to create these object, with the correct | ||
configuration. | ||
|
||
There are two ways to create the objects. | ||
|
||
#### Configuration declaration | ||
|
||
It is possible to completely configure the nested objects, expected by the method. | ||
Instead of passing along the variable as is, a array is used with one expected | ||
and one optional node. The expected node is `class`, this array node should contain | ||
the string representation of the expected class. The optional node is `parameters`, | ||
this array node will contain the objects' instantiation parameters. If none are | ||
required, then this can be left empty or undeclared. | ||
|
||
To create the ObjectFactory with a (full) configuration declaration, would look | ||
like this: | ||
```php | ||
<?php | ||
|
||
use Ulrack\Storage\Component\ObjectStorage; | ||
use Ulrack\ObjectFactory\Factory\ObjectFactory; | ||
use Ulrack\ObjectFactory\Component\Analyser\ClassAnalyser; | ||
|
||
/** @var ObjectFactory $result */ | ||
$result = $factory->create( | ||
ObjectFactory::class, | ||
[ | ||
'classAnalyser' => [ | ||
'class' => ClassAnalyser::class, | ||
'parameters' => [ | ||
'analysisStorage' => [ | ||
'class' => ObjectStorage::class, | ||
], | ||
], | ||
], | ||
] | ||
); | ||
``` | ||
|
||
The configuration declaration could technically be infinitely deep. | ||
|
||
#### Object declaration | ||
|
||
It is also possible to re-use a previously generated or instantiation instance | ||
of a class. This can be done, by simply passing along the object in the parameters. | ||
|
||
```php | ||
<?php | ||
|
||
use Ulrack\Storage\Component\ObjectStorage; | ||
use Ulrack\ObjectFactory\Factory\ObjectFactory; | ||
use Ulrack\ObjectFactory\Component\Analyser\ClassAnalyser; | ||
|
||
$classAnalyser = new ClassAnalyser(new ObjectStorage()); | ||
|
||
/** @var ObjectFactory $result */ | ||
$result = $factory->create( | ||
ObjectFactory::class, | ||
[ | ||
'classAnalyser' => $classAnalyser | ||
] | ||
); | ||
``` | ||
|
||
Both of these declaration methods can be used and mixed throughout the declaration. | ||
|
||
## Change log | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details. | ||
|
||
## MIT License | ||
|
||
Copyright (c) Jyxon | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.