<?php  // vim:set et ts=4 sw=4 sts=4:
# Copyright (C) 2003-2014 hipplay Inc.
#
# This is UNPUBLISHED PROPRIETARY SOURCE CODE OF hipplay Inc.
# The copyright notice above does not evidence any actual or intended
# publication of such source code. The contents of this file may not
# be disclosed to third parties, copied or duplicated in any form, in
# whole or in part, without the prior written permission of
# hipplay Inc.
#
namespace HipPlayConnect\REST;


//
// parent of all REST Services
//
use HipPlayConnect\Identity\AxSession;

abstract class AxAbstractRESTService
{
	protected $serviceName; // to override
    protected $resourcesClassNamePrefix = '';
    protected $requiresAuthenticatedHipServUser = true;
	
	public function __construct()
	{
		if ( $this->requiresAuthenticatedHipServUser && !AxSession::isLoggedIn() )
			throw new AxUnauthorizedRESTException();
	}
	
	//
	// include the required PHP file and return the class name for a given resource
	//
	protected function getResourceClassName( $resourceName )
	{
        $resourceNameSpace = '\\HipPlayConnect\\REST\\services\\' . $this->serviceName;
		$resourceClassName = 'Ax' . $this->resourcesClassNamePrefix . ucfirst( $resourceName ) . 'RESTResource';
		return $resourceNameSpace . '\\' . $resourceClassName;
	}
}