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