php - How to Properly Enforce Correct Usage of a Class Method? -


itemprop = "text">

Our existing ORM solution uses data-meters to represent tables / views in the database, which is then a collection object Returns that can be used to be used as a model object, through a retrieved record. There is a repository layer between the data mapper and the model layers, which manages domain requests for data mappers and gives a related archive or domain object.

We are currently looking for reconstruction of the responsibilities of the repositories and data mapper layers so that all application requests for the data mapper layer are made through the repository and the data mapper retrieve data lines in the repository Which then returns the required item to the requested item.

What I am thinking is that whether it is a valid / good practice to pass the entire repository object in the same data mapper so that we can access only through the Data Speakers repository layer.

For example, how it works by default:

  class datamap {public function meets all (criteria $ criteria) {$ select = $ benchmark - & gt; GetSelect); // specific selection statement $ rows = $ this- & gt; _fetchAll (select $); Return the new collection (array ('data' = & gt; $ rows, 'mapper' = & gt; get_class ($ this))); }}  

I'm thinking of doing something like this:

  class repository {public function find AllByName (model $ model) {$ this- & Gt; _criteria- & gt; Ad condition ('like name', $ model-> name); $ Rows = $ this- & gt; _mapper-> Search (all $$); Return the new collection (array ('data' = & gt; $ rows, 'repository' = & gt; get_class ($ this))); }} Find the public function {class for all repository ($ repository) {$ select = $ repository-> GetCriteria () - & gt; GetSelect (); // specific selection statement $ rows = $ this- & gt; _fetchAll (select $); Return $ rows; }}  

and then in this version, the collection will release the call to the object repository, which was previously able to search through its cached objects and then only to call the record to load Calls if it is needed.

Chris has a reasonable suggestion.

This is partly dependent on the code reference, but the dependencies of the repository injector on the datamap that you have created, i.e.:

  $ repo = new Repository (); $ Mapper = New DataMapper ($ Repo);  

When you want to use findAll (), you will be left with around $ $ repo passing that time. IE:

  $ mapper - & gt; Search (all); $ Mapper- & gt; FindAllByName ();  

I think that when the parameter becomes a omnipresent part of every function call I am making, it is understandable to consider changing it in these example variables (especially when they Every time it is the same).

If your repository differs between references / examples then injection becomes more understandable. If you find that you are always making a repo example and want to recycle it, then a singleton may be appropriate.

The good thing about dependency injection is that this dependency clarifies the idea (irony!). If you want to apply it, you can throw exceptions if the $ repo object is empty, or not a repository example, in your __construct () method.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -