Comments (4)
Can you write some pseudo-code to see exactly how you see it ?
I think this is a really good idea because the default client is kind of heavy.
from rest-client-sdk.
Let me see. Something like this (comments are in the code)
use Mapado\RestClientSdk\Mapping\Annotations as Rest;
/**
* This way no client (or repository) means the default Client/Repository will be used for lookups
* The repository will return an object (or array of objects) of Cart when looking up information
* @Rest\Entity(key="carts")
*/
class Cart
{
/**
* @Rest\Id()
*/
protected $id;
}
$cartClient = $sdkClient->getClient(); // this contains the default client (a parameter can give back another client)
// Multiple clients could be configured in 1 single $sdkClient like https://example.com/api and https://anotherpage.com/api/v2
$repository = $cartClient->getRepository('carts'); // the client can give back the default Client/Repository
$cart = $repository->find(1); // with a repository you can lookup information
// A custom repository
class CartRepository extends Repository
{
public function findByUser(User $user)
{
return $this->find($user->getId()); // find is defined in the repository (currently in your AbstractClient)
}
}
// the Entity would look like
/**
* @Rest\Entity(repository="namespace\to\CartRepository")
* or with a new annotation like
* @Rest\EntityRepository("namespace\to\CartRepository")
*/
class Cart
{
/**
* @Rest\Id()
*/
protected $id;
}
// now the code would look exactly the same
$cartClient = $sdkClient->getClient(); // this contains the default client (a parameter can give back another client)
$repository = $cartClient->getRepository('carts'); // the client will now give the CartRepository back instead of the default Repository
// but now you can use the findByUser on the CartRepository
$cart = $repository->findByUser($app->getUser()); // with a repository you can lookup information
Basically the same approach Doctrine uses with EntityRepositories
and EntityManager(s)
With Doctrine another EntityManager can be loaded (for example when you use a different database)
$em = $doctrine->getEntityManager('products'); // this will lookup in database X
$repo = $em->getRepository("namespace\to\Product\Entity");
$product = $repo->findBy(array("id" => 1));
$em1 = $doctrine->getEntityManager('category'); // this will lookup in database Y
$repo1 = $em1->getRepository("namespace\to\Category\Entity");
$categories = $repo1->findByProduct($product);
$defaultrepo = $doctrine->getEntityManager()->getRepository("namespace\to\User\Entity"); // this will lookup in your default database
$user = $defaultrepo->find(1);
from rest-client-sdk.
In fact, you can manage multiple endpoints too when using the bundle:
You can configure something like this:
# app/config/config.yml
mapado_rest_client_sdk:
entity_managers:
foo:
server_url: 'http://foo.com:8080'
mappings:
prefix: /v1
dir: '%kernel.root_dir%/../src/Foo/Entity/'
bar:
server_url: 'http://bar.com'
mappings:
dir: '%kernel.root_dir%/../src/Bar/Entity/'
You will have too clients: mapado.rest_client_sdk.foo
and mapado.rest_client_sdk.bar
, which is pretty similar to the doctrine differents entity managers. (in fact the doctrine bundle allows you to call doctrine.orm.foo_entity_manager
and doctrine.orm.bar_entity_manager
).
You have a point though about the component, which does not have a main container.
from rest-client-sdk.
Fixed in #21
from rest-client-sdk.
Related Issues (20)
- Persisting an entity with a ManyToOne relation does not convert related entity as IRI HOT 10
- Allow an ID instead of an IRI HOT 1
- Handle exceptions from API HOT 3
- paginated hydra collections support HOT 8
- retrieving a list of "abstracted" entities HOT 5
- More recent version of ocramius/proxy-manager HOT 5
- improve performance of related entities retrieval HOT 1
- Do not `PUT` if Unit of work returns an empty diff
- support of partial entities HOT 8
- Creating relation entities even when they aren't resources HOT 6
- page collection
- list available types
- Error if the setter does not exists
- Do not allow two `@Rest\Id` fields
- Proxy initializer function bug HOT 6
- Issue with `UnitOfWork` and query parameters
- Use property accessor
- Allow int as id in model
- DateTime : allow customer format
- DateTime : changing timezone
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rest-client-sdk.