arangodb / arangodb-php

PHP ODM for ArangoDB
https://www.arangodb.com
Apache License 2.0
182 stars 46 forks source link

Allow to use custom document classes #192

Closed diabl0 closed 7 years ago

diabl0 commented 8 years ago

Related with https://github.com/arangodb/arangodb-php/issues/6 Allows to use custom document classes. This will enable to have some business logic associated with particular document types and helps with using ArangoDB documents in different frameworks like Symfony.

Documentation:

If you want to use custom document class you can pass it's name to DocumentHandler or CollectionHandler using method setDocumentClass. Remember that Your class must extend \triagens\ArangoDb\Document.

$ch = new CollectionHandler($connection);
$ch->setDocumentClass('\AppBundle\Entity\Product');
$cursor = $ch->all('product'); 
// All returned documents will be \AppBundle\Entity\Product instances

$dh = new DocumentHandler($connection);
$dh->setDocumentClass('\AppBundle\Entity\Product');
$product = $dh->get('products', 11231234);
// Product will be \AppBundle\Entity\Product instance
frankmayer commented 8 years ago

@diabl0 Hi, this looks solid. Could you please fix the conflicts and write accompanying tests? Thanks.

frankmayer commented 7 years ago

@diabl0, I just realized that you made this PR against master. Could you please make this against the devel branch? Let me know if you have the time to do this within the next one or two days, so I can include this in the next release.

Also, there is a chance that in order to accept third-party code into this repo, a CLA (https://www.arangodb.com/documents/cla.pdf) might have to be signed and mailed or faxed to ArangoDB's offices. @jsteemann can you confirm this? I remember I signed it, but I am not sure if it only applies to the main arangodb/arangodb repo or indeed all arangodb/* repos.

frankmayer commented 7 years ago

@diabl0 pls check my last comment on the issue of the CLA and the correct branch to make a PR against. Please also make sure there are no conflicts. Thanks

diabl0 commented 7 years ago

@frankmayer CLA was submitted and accepted. Next week I will try to update my pull request to current devel branch.

frankmayer commented 7 years ago

@diabl0 great! please also write one or more tests to cover the new functionality. Essentially the best thing is to check the https://github.com/arangodb/arangodb-php/blob/devel/CONTRIBUTING.md file.

hwde commented 7 years ago

Hey @diabl0, I would love to see your pull request merged, I thought about to help to resolve the merge conflicts or write some tests ... if it doesn't require to send CLA, which would slow down the merge, of course.

diabl0 commented 7 years ago

@hwde i have it mostly rewritten to current debate branch but due to other urgent project I haven't tested it properly. I will push current work in progress later if you want to contribute.

hwde commented 7 years ago

@diabl0 That would be cool, thanks.

diabl0 commented 7 years ago

@hwde it's pushed here: https://github.com/diabl0/arangodb-php/tree/DocumentClass

hwde commented 7 years ago

@diabl0 Ok, I've written some tests and added the documentClass to Batch and Export too, please have a look here: https://github.com/hwde/arangodb-php/tree/DocumentClass - five arangodb-php tests are failing, but I assume it's because I'm using macOS, on devel branch the same tests failed.

diabl0 commented 7 years ago

@hwde Great. Can you create pull request?

I switched my main project to use this arrangedb-php branch and it works properly, so probably tomorrow I will try to wrap this up, update documentation, write some use cases and create new pull request from DocumentClass branch to devel branch.

frankmayer commented 7 years ago

Closing this PR in favor of PR #208