コード例 #1
0
 public function itShouldGroupArraysIntoSubArrays()
 {
     $data = range(1, 10);
     $grouped = Ra_ArrayHelper::in_groups_of($data, 5);
     $this->spec(count($grouped))->should->be(2);
     $this->spec(count($grouped[0]))->should->be(5);
     $this->spec(count($grouped[1]))->should->be(5);
     $grouped = Ra_ArrayHelper::in_groups_of($data, 3);
     $this->spec(count($grouped))->should->be(4);
     $this->spec(count($grouped[0]))->should->be(3);
     $this->spec(count($grouped[1]))->should->be(3);
     $this->spec(count($grouped[2]))->should->be(3);
     $this->spec(count($grouped[3]))->should->be(1);
 }
コード例 #2
0
ファイル: autoloader.php プロジェクト: EscoreBu/metrics-bot
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;
}