forked from anahitasocial/anahita
/
default.php
74 lines (64 loc) · 2.64 KB
/
default.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* LICENSE: ##LICENSE##
*
* @category Anahita
* @package Com_Base
* @subpackage Controller
* @author Arash Sanieyan <ash@anahitapolis.com>
* @author Rastin Mehr <rastin@anahitapolis.com>
* @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
* @version SVN: $Id: resource.php 13650 2012-04-11 08:56:41Z asanieyan $
* @link http://www.anahitapolis.com
*/
/**
* Service Controller
*
* @category Anahita
* @package Com_Base
* @subpackage Controller
* @author Arash Sanieyan <ash@anahitapolis.com>
* @author Rastin Mehr <rastin@anahitapolis.com>
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
* @link http://www.anahitapolis.com
*/
final class ComBaseControllerDefault extends ComBaseControllerService implements KServiceInstantiatable
{
/**
* Force creation of a singleton
*
* @param KConfigInterface $config An optional KConfig object with configuration options
* @param KServiceInterface $container A KServiceInterface object
*
* @return KServiceInstantiatable
*/
public static function getInstance(KConfigInterface $config, KServiceInterface $container)
{
$strIdentifier = (string)$config->service_identifier;
$registery = $container->get('application.registry', array('key'=>$strIdentifier.'_default_class'));
if(!$registery->offsetExists($strIdentifier))
{
try
{
$identifier = clone $config->service_identifier;
$identifier->type = 'repos';
$identifier->path = array('domain','entity');
$default = array('prefix'=>$container->get($identifier)->getClone(),'fallback'=>'ComBaseControllerDefault');
}
catch(Exception $e)
{
$default = 'Com'.ucfirst($config->service_identifier->package).'ControllerDefault';
$default = array('default'=>array($default, 'ComBaseControllerResource'));
}
$default['identifier'] = $config->service_identifier;
register_default($default);
$classname = AnServiceClass::findDefaultClass($config->service_identifier);
$config->service_identifier->classname = $classname;
$registery->offsetSet($strIdentifier, $classname);
}
$classname = $registery->offsetGet($strIdentifier);
$instance = new $classname($config);
return $instance;
}
}