Skip to content

Instantly share code, notes, and snippets.

@ronan-gloo
Created March 4, 2014 09:17
Show Gist options
  • Save ronan-gloo/9342993 to your computer and use it in GitHub Desktop.
Save ronan-gloo/9342993 to your computer and use it in GitHub Desktop.
Cuisine et dépendances
<?php
// constructor
class Void
{
protected $mapper;
public function __construct(Mapper $mapper)
{
$this->mapper = $mapper;
}
}
// Getter | Setter
class Void {
protected $mapper;
public function getMapper()
{
return $this->mapper;
}
public function setMapper(Foreign $object)
{
$this->mapper = $object;
return $this;
}
}
// Lazy loading
class Void implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
public function getMapper()
{
return $this->getServiceLocator()->get('service.mapper');
}
}
// Getter | Setter + Lazy loading
class Void implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
protected $mapper;
public function getMapper()
{
if (! isset($this->mapper)) {
$this->setMapper($this->getServiceLocator()->get('service.mapper'));
}
return $this->mapper;
}
public function setMapper(Mapper $object)
{
$this->mapper = $object;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment