Skip to content
Snippets Groups Projects
serviceModule.php 1.55 KiB
Newer Older
alangrafu's avatar
alangrafu committed
<?
require_once('abstractModule.php');
class ServiceModule extends abstractModule{
  //Service module
  
  public function match($uri){
alangrafu's avatar
alangrafu committed
  	global $conf; 
alangrafu's avatar
alangrafu committed
  	global $acceptContentType; 
    global $localUri;
alangrafu's avatar
alangrafu committed
  	$q = preg_replace('|^'.$conf['basedir'].'|', '', $localUri);
alangrafu's avatar
alangrafu committed
 	$qArr = explode('/', $q);
alangrafu's avatar
alangrafu committed
  	if(sizeof($qArr)==0){
  	  return FALSE;
  	}
  	$extension = Utils::getExtension($acceptContentType); 
  	$auxViewFile  = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0]."/".$extension.".template";
  	$auxModelFile = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0]."/".$extension.".queries";
  	if(is_dir($auxModelFile) && is_file($auxViewFile)){
  	  return $uri;// $qArr[0];
  	}
  	$auxViewFile  = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0];
  	$auxModelFile = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0];
  	if(is_dir($auxModelFile) && is_dir($auxViewFile)){
  	  Utils::send406($uri);// $qArr[0];
  	}
  	if(is_dir($auxModelFile) && is_file($auxViewFile)){
alangrafu's avatar
alangrafu committed
  	  return $localUri;// $qArr[0];
alangrafu's avatar
alangrafu committed
  	}

  	return FALSE;
alangrafu's avatar
alangrafu committed
  }
  
alangrafu's avatar
alangrafu committed
  public function execute($service){
alangrafu's avatar
alangrafu committed
  	global $conf;
  	global $localUri;
  	global $uri;
  	global $acceptContentType;
  	global $endpoints;
alangrafu's avatar
alangrafu committed
  	require_once($conf['home'].$conf['service']['class']);
alangrafu's avatar
alangrafu committed
  	$context = array();
  	$context['contentType'] = $acceptContentType;
  	$context['endpoints'] = $endpoints;
  	$sp = new SpecialFunction();
alangrafu's avatar
alangrafu committed
  	$sp->execute($localUri, $context);
alangrafu's avatar
alangrafu committed
  	exit(0);	
  }
  
}
?>