News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Repository Design Pattern Demystified
June 02, 2014 @ 09:12:40

The SitePoint PHP blog has a new post today that hopes to "demystify" the Repository design pattern with an overview of its structure and ow your code can put it to use.

What is the Repository Design Pattern? To put it simply, it is an implementation of a brokering layer between the application and a data source. Neither party needs to be be aware of the other to perform their respective jobs which allows us to have a decoupled architecture which in turn helps in the scaling of the application in the big leagues without having hard dependencies.

He includes an example case where the Repository pattern might be used, to "proxy" requests to multiple types of data sources from many different inventory systems. He includes some pros and cons of using the functionality too, like a positive separation of concerns but a negative additional abstraction layer. The remainder of the post includes a code example basing it on a Laravel framework installation. He creates a simple Repository class and shows how to extend it with a layer specific to one city type.

0 comments voice your opinion now!
repository designpattern introduction tutorial laravel class

Link: http://www.sitepoint.com/repository-design-pattern-demystified/

Matthias Noback:
Inject a repository instead of an entity manager
May 19, 2014 @ 11:04:30

Matthias Noback has made a recommendation in his latest post about using a repository rather than an entity manager in your classes to inject dependencies.

It appears that I didn't make myself clear while writing about entity managers and manager registries yesterday. People were quick to reply that instead you should inject entity repositories. However, I wasn't talking about entity repositories here. I was talking about classes that get an EntityManager injected because they want to call persist() or flush(). The point of my previous post was that in those cases you should inject the manager registry, because you don't know beforehand which entity manager manages the entities you are trying to persist. By injecting a manager registry you also make your code useful in contexts where another Doctrine persistence library is used.

He suggests that more classes actually need a repository and not an entity manager to work with necessary objects. He also points out how the use of an entity manager can sometimes violate the Law of Demeter. He includes some code showing a refactoring away from an entity manager and towards a repository. He also has an example of a custom repository class based on the domain logic object types. In addition he talks about repository interfaces, resetting closed entity managers and "criteria" objects.

0 comments voice your opinion now!
repository entity manager doctrine refactor example

Link: http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/

Stephan Hochdörfer:
Speeding up your Satis run
May 02, 2014 @ 09:11:40

Stephan Hochdörfer has a new post with a handy tip on speeding up the indexing Satis does on your local repositories to generate its information. His tip involves being more selective in the rebuild process, only indexing the projects that might need it.

In the last couple of months this [indexing] process takes quite a while because Satis rebuilds the index for every repo it knows about. Since we deal with quite a few repos containing a large amount of versions it slowed down the "build time". Obviously it does not make any sense to run Satis on a repo that has not changed. Since Satis was lacking this feature I started hacking on it and I am happy that the feature got merged into master this morning.

With his patch, you can specify only the repository you want reindexed via the "build" command. You can even specify multiple repositories to rebuild, allowing for a bit more automation around the process.

0 comments voice your opinion now!
satis repository index speed performance patch single

Link: http://blog.bitexpert.de/blog/speeding-up-your-satis-run/

Nils Adermann:
Composer Replace, Conflict & Forks Explained
February 19, 2014 @ 12:56:41

Nils Adermann has a new post looking at a problem with Composer where it will install a fork of a project rather than the actual project repository. He points out that it is not a security vulnerability in Composer itself, and is usually cause by using the configuration incorrectly.

Recently there has been an increase of cases in which Composer installs a fork of a package instead of the package the user expects. Most frequently these are forks of packages using a "replace" statement in their composer.json. These forks are usually meant for private use only but are still published on Packagist.

The issue stems from the use of "replace" and the publishing of those forked repositories in the Packagist service. "Replace" is meant to define a fork that is still compatible with the original project. The way that Composer handles finding the correct package to install can cause a conflict and the wrong package could end up "winning".

0 comments voice your opinion now!
composer replace fork repository dependency install

Link: http://blog.naderman.de/2014/02/17/replace-conflict-forks-explained

Lorna Mitchell:
Use a GitHub Branch as a Composer Dependency
February 19, 2014 @ 11:48:53

Lorna Mitchell has a quick post to her site today showing you how to use a GitHub branch as a Composer dependency when the need arrises for something other than master (or whatever branch is "stable" for the project).

My current project sees Celery (a python distributed task queue) added to my PHP application. There's a handy PHP interface to the RabbitMQ that Celery uses as a backend, which makes it easy for me to create jobs, called celery-php. This requires either the PECL AMQP extension< or alternatively it has experimental support for the PHP library for AMQP - I would normally prefer the PECL version but ran into version compatibility problems, missing manual pages, and decided that a pure PHP solution might be more portable and perhaps I would just add the experimental branch to my composer.json file for this project.

She includes an example of what the "composer.json" file would look like to pull this other branch. Two pieces of data have to be defined - the URL for the repository (to prevent Composer from trying to find it) and the branch name in the "require" section where the version would normally be.

0 comments voice your opinion now!
github repository branch composer dependency

Link: http://www.lornajane.net/posts/2014/use-a-github-branch-as-a-composer-dependency

PHPClasses.org:
Speedup Your Web Deployments Using Composer to Install PHP Classes Packages
December 12, 2013 @ 11:43:01

On the PHPClasses.org site today Manuel Lemos has a new post showing how you can use Composer in your deployments to help install packages from the PHPClasses site.

You can install one or more packages from PHP Classes, JS Classes or other Composer repository sites. [...] To make it simpler for you, PHP Classes and JS Classes generate a sample composer.json file for each package available in the Composer repository. Just go in the page of the package you want to install and click on the Install with Composer link.

He includes a brief guide on installing Composer and an example of the resulting "composer.json" file when you click on a link in a package. He points out the use of logins (depends on the package maintainer) and the use of an "auth.json" to automatically provide this information.

This is a great example of how a site that puts the Composer ecosystem to work to provide packages outside of Packagist. Composer, by default, relies on Packagist for its package information, but you can provide alternate repositories too - including using something like Satis for local packages.

0 comments voice your opinion now!
phpclasses composer install repository custom

Link: http://www.phpclasses.org/blog/post/221-Speedup-Your-Web-Deployments-Using-Composer-to-Install-PHP-Classes-Packages.html

NetTuts.com:
The Repository Design Pattern
November 26, 2013 @ 11:53:16

While design patterns are a wider topic than just PHP, the NetTuts.com site has posted a new tutorial looking at the Repository Pattern and uses PHP and PHPUnit to illustrate how the pattern works. They looks at the structure of the pattern at a high level and provide a more "real world" example too.

The Repository Design Pattern, defined by Eric Evens in his Domain Driven Design book, is one of the most useful and most widely applicable design patterns ever invented. Any application has to work with persistence and with some kind of list of items. These can be users, products, networks, disks, or whatever your application is about. If you have a blog for example, you have to deal with lists of blog posts and lists of comments. The problem that all of these list management logics have in common is how to connect business logic, factories and persistence.

They start with an overview of the pattern and some of the problems that it can help to solve. They also briefly mention the Gateway pattern that will be used in the examples to pull information into the Repository. After covering some of the basic concepts, they get into the code (going the TDD route) showing how to manage comments, like from a blog, inside a repository. It implements a "Comment" class, a persistence mechanism (the Gateway) and a Factory class that takes in the comment data and returns a correctly formatted object. Finally, they make the repository class and show how to add and retrieve comments from its internal data set.

0 comments voice your opinion now!
designpattern repository gateway factory persistence tutorial

Link: http://net.tutsplus.com/tutorials/php/the-repository-design-pattern/

Hasin Hayder:
Install and Run Symfony 2.3.6 projects in OpenShift instances in just one minute
October 28, 2013 @ 10:32:36

Hasin Hayder has a new post today sharing a boilerplate configuration and setup he's created to get Symfony2 running on OpenShift in "just one minute". OpenShift is RedHat's platform as a service that makes it easier to set up and deploy web apps.

Okay, I have written an article 2 days ago where I went through every details. But today. I have created a blank symfony container with all the necessary deploy hook and mods so that you can get your symfony 2 project up and running in an openshift container within a minute, fully automated, seriously!

This repository helps you set up the Symfony instance that's ready to go. He walks you through the steps you'll need to create the OpenShift "gear" and configure it to work with Symfony and MySQL.

0 comments voice your opinion now!
symfony boilerplate repository openshift instance configure install

Link: http://hasin.me/2013/10/27/install-and-run-symfony-2-3-0-in-openshift-instances-in-just-one-minute-with-this-boilerplate-repository/

David Adams:
Is ORM abstraction a pipe dream?
October 23, 2013 @ 09:59:21

David Adams has published a recent post that wonders if ORM abstraction is a "pipe dream" when it comes to abstraction. ORM stands for "object relational mapper" and is commonly used as a layer between the application and a dta source to work with the data as objects, not directly with it. He instead investigates replacing the ORM layer with multiple instances of repository pattern-structured code to abstract thing even more.

I was recently introduced to the repository pattern, a type of abstraction and organizational technique. The idea being, create a repository for each of your models to retrieve and persist to and from. A supposed benefit of the repository pattern is the ability to abstract your ORM and create different implementations for Eloquent, Doctrine, Propel, etc. This abstraction intrigued me. I set off to put this idea into practice and see what it took. Here are my findings.

He looks into how Doctrine handles its entities and tries to mimic some of the logic, including the calls to "save" and "flush". He also looks at how to handle a few other common ORM-ish topics like relationships, validation and observers. Unfortunately, he hit a wall with his solution and wasn't able to figure out a good Repository-based solution.

0 comments voice your opinion now!
repository designpattern proofofconcept orm object mapper doctrine entity

Link: http://programmingarehard.com/2013/10/21/is-orm-abstraction-a-pipe-dream.html

Wojciech Sznapka:
Injecting repositories to service in Symfony2
October 17, 2013 @ 11:45:54

Wojciech Sznapka has an interesting new post to his site today talking about injecting repositories into services in Symfony2-based applications. By injecting just a single repository instead of the entire EntityManager, you get a cleaner, more clear interface defined in the code.

It is generally a good idea to wrap business logic into services. Often, such services methods uses doctrine's repositories to operate on data storage. Injecting whole EntityManager service is very popular approach, but it isn't the most elegant way I could think of. EntityManager works only as a factory in that case and could lead to usage of other repositories, which might end up with too many responsibilities of given service.

He includes some code to illustrate his point - both a "services.xml" configuration of the related dependency injection container and a custom entity repository (defined in the config). He then shows how this repository (FooRepository) would be injected into the service (FooService) via constructor injection.

0 comments voice your opinion now!
symfony2 repository injection configuration tutorial entity manager

Link: http://blog.sznapka.pl/injecting-repositories-to-service-in-symfony2/


Community Events





Don't see your event here?
Let us know!


api bugfix interview laravel framework opinion voicesoftheelephpant podcast introduction list deployment install language release community symfony tips library series package

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework