<?php
/**
* @version 1.0.0
* @category Anahita Social Engineâ¢
* @copyright Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.anahitapolis.com
*/
class AnahitaFactoryAdapter extends KFactoryAdapterAbstract
{
public function instantiate($identifier, array $options)
{
$instance = false;
if($identifier->type == 'lib' && $identifier->package == 'anahita')
{
$classname = 'An'.KInflector::implode($identifier->path).ucfirst($identifier->name);
$filepath = KLoader::path($identifier);
if (!class_exists($classname))
{
// use default class i nstead
$classname = $classname.'Default';
if (!class_exists($classname)) {
throw new KFactoryAdapterException("Class [$classname] not found in file [".basename($filepath)."]" );
}
}
//If the object is indentifiable push the identifier in through the constructor
if(array_key_exists('KFactoryIdentifiable', class_implements($classname)))
{
$identifier->filepath = $filepath;
$options['identifier'] = $identifier;
}
// If the class has a factory method call it
if(is_callable(array($classname, 'factory'), false)) {
$instance = call_user_func(array($classname, 'factory'), $options);
} else {
$instance = new $classname($options);
}
}
return $instance;
}
//end class
}