public static function objectFactory()
 {
     if (RESTObject::$object === false) {
         $object_name = Router::getObjectName();
         if (file_exists(__DIR__ . "/REST/{$object_name}.php")) {
             require_once __DIR__ . "/REST/{$object_name}.php";
             RESTObject::$object = new $object_name();
         } else {
             //Exception
         }
     }
     return RESTObject::$object;
 }
 public static function objectFactory()
 {
     if (RESTObject::$object === false) {
         $object_name = Router::getObjectName();
         if (file_exists(RESTDIR . "{$object_name}.php")) {
             require_once RESTDIR . "{$object_name}.php";
             //Verificar parâmetros
             RESTObject::$object = new $object_name();
         } else {
             //Exception
         }
     }
     return RESTObject::$object;
 }
 public function init()
 {
     $uri = explode('?', $_SERVER['REQUEST_URI']);
     $uri = explode('/', $uri[0]);
     if (count($uri) < 3 or $uri[2] == '') {
         Router::$objectName = 'Index';
     } else {
         Router::$objectName = $uri[2];
     }
     Router::$object = RESTObject::objectFactory();
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'POST':
             Router::$method = Router::POST;
             break;
         case 'PUT':
             Router::$method = Router::PUT;
             break;
         case 'DELETE':
             Router::$method = Router::DELETE;
             break;
         default:
             Router::$method = Router::GET;
     }
 }
function loadObjectsFromXML($xmlParser)
{
    $objects = array();
    $xmlObjects = XmlParserUtils::getChildren($xmlParser->document, XML_OBJECT);
    foreach ($xmlObjects as $xmlObject) {
        $className = XmlParserUtils::existAttribute($xmlObject, XML_OBJECT_CLASS) ? $xmlObject->tagAttrs[XML_OBJECT_CLASS] : null;
        if (empty($className)) {
            throw new MashapeException(EXCEPTION_OBJECT_EMPTY_CLASS, EXCEPTION_XML_CODE);
        } else {
            if (existClassName($objects, $className)) {
                throw new MashapeException(sprintf(EXCEPTION_OBJECT_DUPLICATE_CLASS, $className), EXCEPTION_XML_CODE);
            }
        }
        //Get fields
        $fields = array();
        $xmlFields = XmlParserUtils::getChildren($xmlObject, XML_FIELD);
        if (empty($xmlFields)) {
            throw new MashapeException(sprintf(EXCEPTION_EMPTY_FIELDS, $className), EXCEPTION_XML_CODE);
        }
        foreach ($xmlFields as $xmlField) {
            $field_name = $xmlField->tagData;
            if (empty($field_name)) {
                throw new MashapeException(EXCEPTION_FIELD_EMPTY_NAME, EXCEPTION_XML_CODE);
            } else {
                if (existFieldName($fields, $field_name)) {
                    throw new MashapeException(sprintf(EXCEPTION_FIELD_NAME_DUPLICATE, $field_name, $className), EXCEPTION_XML_CODE);
                }
            }
            $field_object = XmlParserUtils::existAttribute($xmlField, XML_FIELD_OBJECT) ? $xmlField->tagAttrs[XML_FIELD_OBJECT] : null;
            $field_method = XmlParserUtils::existAttribute($xmlField, XML_FIELD_METHOD) ? $xmlField->tagAttrs[XML_FIELD_METHOD] : null;
            $field_array = XmlParserUtils::existAttribute($xmlField, XML_FIELD_ARRAY) ? $xmlField->tagAttrs[XML_FIELD_ARRAY] : null;
            if ($field_array != null && strtolower($field_array) == "true") {
                $field_array = true;
            } else {
                $field_array = false;
            }
            $field_optional = XmlParserUtils::existAttribute($xmlField, XML_FIELD_OPTIONAL) ? $xmlField->tagAttrs[XML_FIELD_OPTIONAL] : null;
            if ($field_optional != null && strtolower($field_optional) == "true") {
                $field_optional = true;
            } else {
                $field_optional = false;
            }
            $field = new RESTField();
            $field->setName($field_name);
            $field->setObject($field_object);
            $field->setMethod($field_method);
            $field->setArray($field_array);
            $field->setOptional($field_optional);
            array_push($fields, $field);
        }
        $object = new RESTObject();
        $object->setClassName($className);
        $object->setFields($fields);
        array_push($objects, $object);
    }
    return $objects;
}