Ejemplo n.º 1
0
 public function refresh()
 {
     if (isset($this->options['polymorphic']) && $this->options['polymorphic'] == true) {
         $as = Ra_StringHelper::underscore($this->foreign_model);
         $id_field = $as . "_id";
         $type_field = $as . "_type";
         $value = $this->local_model->{$id_field};
         return ActiveRecord::model($this->local_model->{$type_field})->find($value);
     } else {
         $foreign_field = $this->get_foreign_field($this->foreign_model);
         $foreign_key_field = $this->foreign_model->primary_key();
         $data = $this->foreign_model->find($this->local_model->{$foreign_field});
         return $data;
     }
 }
Ejemplo n.º 2
0
function ra_autoloader($classname)
{
    //check if class already exists
    if (class_exists($classname)) {
        return true;
    }
    //if($classname != 'Ra_Uri')
    //check if is a core library
    if (Ra_StringHelper::starts_with($classname, RA_SYSTEM_CLASS_PREFIX)) {
        $filename = substr($classname, strlen(RA_SYSTEM_CLASS_PREFIX));
        $path = RA_SYSTEM_LIBRARIES_PATH . '/' . $filename . '.php';
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        }
        $path = RA_SYSTEM_HELPERS_PATH . '/' . $filename . '.php';
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        }
    }
    //check if the class is a controller
    if (Ra_StringHelper::ends_with($classname, 'Controller')) {
        $base_paths = array(RA_CONTROLLERS_PATH);
        Ra_ArrayHelper::array_push($base_paths, glob(RA_SLICES_PATH . "/*/app/controllers"));
        foreach ($base_paths as $path) {
            $bits = explode('_', $classname);
            while (count($bits) > 1) {
                $path .= '/' . strtolower(array_shift($bits));
            }
            $path .= '/' . substr(array_shift($bits), 0, -strlen('Controller')) . '.php';
            if (file_exists($path)) {
                require_once $path;
                if (class_exists($classname)) {
                    return true;
                }
            }
        }
    }
    //try to load user helper
    if (Ra_StringHelper::ends_with($classname, 'Helper')) {
        $path = RA_HELPERS_PATH;
        $bits = explode('_', $classname);
        while (count($bits) > 1) {
            $path .= '/' . strtolower(array_shift($bits));
        }
        $path .= '/' . array_shift($bits) . '.php';
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        }
    }
    //try to load model
    $base_paths = array(RA_MODELS_PATH);
    Ra_ArrayHelper::array_push($base_paths, glob(RA_SLICES_PATH . "/*/app/models"));
    foreach ($base_paths as $path) {
        $path = $path . '/' . $classname . '.php';
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        }
    }
    //try user library
    $path = RA_LIBRARIES_PATH . '/' . $classname . '.php';
    // CORRECAO PARA USAR CLASSES NO DIRETORIO library DENTRO DE app
    // PASTA EM MINUSCULO CLASSE COM O NOME DA PASTA
    if (file_exists($path)) {
        require_once $path;
        if (class_exists($classname)) {
            return true;
        }
    } else {
        // if(strpos($classname, "ReCaptcha") !== false) {
        // 	$temp = explode('\\', $classname);
        // 	$classname = $temp[count($temp) - 1];
        // 	$path = RA_LIBRARIES_PATH . "/recaptcha/" . $classname . ".php";
        // 	// de($path);
        // 	if(file_exists($path)) {
        // 		require_once $path;
        // 		return true;
        // 	} else {
        // 		$path = RA_LIBRARIES_PATH . "/recaptcha/requestmethod/" . $classname . ".php";
        // 		if(file_exists($path)) {
        // 			require_once $path;
        // 			return true;
        // 		}
        // 	}
        // 	// de($classname);
        // }
        $path = RA_LIBRARIES_PATH . "/" . strtolower($classname) . "/" . $classname . ".php";
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        } else {
            $path = RA_LIBRARIES_PATH . "/" . strtolower($classname) . "/" . strtolower($classname) . ".php";
            if (file_exists($path)) {
                require_once $path;
                if (class_exists($classname)) {
                    return true;
                }
            } else {
                $path = RA_LIBRARIES_PATH . "/" . strtolower($classname) . "/" . ucfirst(strtolower($classname)) . ".php";
                if (file_exists($path)) {
                    require_once $path;
                    if (class_exists($classname)) {
                        return true;
                    }
                }
            }
        }
    }
    //CORRECAO PARA NOVA API DO FB ESSA PORRA
    if (strpos($classname, "Facebook") !== false) {
        $arr = explode("\\", $classname);
        // de($arr);
        $path = RA_LIBRARIES_PATH . "/facebook/" . $arr[1] . ".php";
        // de($path);
        if (file_exists($path)) {
            require_once $path;
            if (class_exists($classname)) {
                return true;
            }
        }
    }
    //sorry, i can't found the class :(
    return false;
}
Ejemplo n.º 3
0
 public function __call($method, $args)
 {
     global $ROUTER;
     if (Ra_StringHelper::ends_with($method, '_url')) {
         $route_name = substr($method, 0, -4);
         return RA_BASE_URL . RA_INDEX_PAGE . $ROUTER->named_route($route_name, @$args[0]);
     }
     if (Ra_StringHelper::starts_with($method, 'redirect_to_')) {
         $route_name = substr($method, strlen('redirect_to_'));
         return $this->redirect_to($ROUTER->named_route($route_name, @$args[0]));
     }
     throw new Exception("Method {$method} doesn't exists");
 }
Ejemplo n.º 4
0
 public function itShouldRemoveAccentsFromStrings()
 {
     $string = "É uma string. Não pode ter acentos.";
     $without_accents = Ra_StringHelper::remove_accents($string);
     $this->spec($without_accents)->should->be("E uma string. Nao pode ter acentos.");
 }
Ejemplo n.º 5
0
 /**
  * Discovery a route for certain parameters
  *
  * @param string $controller Controller name
  * @param string $action Action name
  * @param array $params The params
  * @return string The discovered route
  */
 public function discovery_route($controller, $action, $req_params = array())
 {
     foreach ($this->routes as $route) {
         $params = $req_params;
         $con = $controller;
         if ($route['options']['namespace']) {
             if (Ra_StringHelper::starts_with($con, $route['options']['namespace'])) {
                 $con = substr($con, strlen($route['options']['namespace']) + 1);
             } else {
                 continue;
             }
         }
         //check if can solve controller
         if (in_array('controller', $route['names'])) {
             $params['controller'] = $con;
         } elseif ($route['options']['controller'] != $con) {
             continue;
         }
         //check if can solve action
         if (in_array('action', $route['names'])) {
             $params['action'] = $action;
         } else {
             if (!$route['options']['action']) {
                 $route['options']['action'] = $this->default_action();
             }
             if ($route['options']['action'] != $action) {
                 continue;
             }
         }
         if (count($params) != count($route['names'])) {
             continue;
         }
         $solve = true;
         //check if can solve params
         foreach ($params as $key => $param) {
             if ($key == 'controller' || $key == 'action') {
                 continue;
             }
             if (!in_array($key, $route['names'])) {
                 $solve = false;
                 break;
             }
         }
         if ($solve) {
             return $this->apply_route($route['pattern'], $params);
         }
     }
     throw new Ra_RouterException("The requested route can't be discovery");
 }
Ejemplo n.º 6
0
 private static function get_field($fieldname)
 {
     $object = self::get_object();
     if (is_a($object, 'BlankObject')) {
         return $fieldname;
     } else {
         $filtred_name = self::get_normalized_field($fieldname);
         $result = "{$object->__form_var_name}[{$filtred_name}]";
         if (Ra_StringHelper::ends_with($fieldname, '[]')) {
             $result .= '[]';
         }
         return $result;
     }
 }