Skip to content

Instantly share code, notes, and snippets.

@devosc
Created March 23, 2015 14:56
Show Gist options
  • Save devosc/532ccb328ecb304d8328 to your computer and use it in GitHub Desktop.
Save devosc/532ccb328ecb304d8328 to your computer and use it in GitHub Desktop.
ArrayAccess Container Support
<?php
/**
*
*/
namespace Framework\Service\Container;
use Framework\Config\ArrayAccess;
use Framework\Config\Configuration;
trait Service
{
/**
*
*/
use ArrayAccess;
/**
* @var array|Configuration
*/
protected $config;
/**
* @var ServiceContainer
*/
protected $services;
/**
* @return array|Configuration
*/
public function config()
{
return $this->config;
}
/**
* @param array|Configuration $config
*/
public function configuration($config)
{
$this->config = $config;
}
/**
* @param string $name
* @param mixed $config
* @return void
*/
public function configure($name, $config)
{
$this->services->configure($name, $config);
}
/**
* @param string $name
* @return array|callable|null|object|string
*/
public function configured($name)
{
return $this->services->configured($name);
}
/**
* @param string $name
* @return object|null
*/
public function get($name)
{
return $this->services[$name];
}
/**
* @param string $name
* @return bool
*/
public function has($name)
{
return isset($this->services[$name]);
}
/**
* @param string $name
* @return void
*/
public function remove($name)
{
unset($this->services[$name]);
}
/**
* @param string $name
* @return object|null
*/
public function service($name)
{
return $this->services[$name];
}
/**
* @param ServiceContainer $services
*/
public function services(ServiceContainer $services)
{
$this->services = $services;
}
/**
* @param string $name
* @param mixed $service
* @return void
*/
public function set($name, $service)
{
$this->services[$name] = $service;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment