public function itShouldAbleToTestIfAStringStartsWithAnotherString() { $haystack = "This is a complete string"; $this->spec(Ra_StringHelper::starts_with($haystack, "This"))->should->beTrue(); $this->spec(Ra_StringHelper::starts_with($haystack, "not"))->should->beFalse(); $this->spec(Ra_StringHelper::starts_with($haystack, "this"))->should->beFalse(); }
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; }
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"); }
/** * 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"); }