Skip to content

Commit

Permalink
Sensio corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Oct 18, 2017
1 parent cc20b85 commit 6299682
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/controller/router.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ubiquity Router
=================
=================
2 changes: 1 addition & 1 deletion docs/controller/uri.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ On Unix systems, the name of the controllers is case-sensitive.

Routing customization
---------------------
The :doc:`router` and annotations of the controller classes allow you to customize URLs.
The :doc:`router` and annotations of the controller classes allow you to customize URLs.
18 changes: 6 additions & 12 deletions micro/cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ public static function getControllerCache() {
public static function getRouteCache($routePath, $duration) {
$key=self::getRouteKey($routePath);

if (self::$cache->exists("controllers/" . $key) && self::$cache->expired("controllers/" . $key, $duration) === false){
if (self::$cache->exists("controllers/" . $key) && self::$cache->expired("controllers/" . $key, $duration) === false) {
$response=self::$cache->file_get_contents("controllers/" . $key);
return $response;
}
else {
} else {
$response=Startup::runAsString($routePath);
return self::storeRouteResponse($key, $response);
}
Expand Down Expand Up @@ -160,11 +159,6 @@ private static function initModelsCache(&$config) {
}
}

private static function getClassNameFromFile($file, $namespace="") {
$fileName=pathinfo($file, PATHINFO_FILENAME);
return $namespace . ucfirst($fileName);
}

private static function initControllersCache(&$config) {
$controllersNS=$config["mvcNS"]["controllers"];
$controllersDir=ROOT . DS . str_replace("\\", DS, $controllersNS);
Expand All @@ -181,10 +175,10 @@ private static function initControllersCache(&$config) {
self::$cache->store("controllers/routes", "return " . JArray::asPhpArray(self::$routes, "array") . ";");
}

private static function glob_recursive($pattern, $flags = 0){
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, self::glob_recursive($dir.'/'.basename($pattern), $flags));
private static function glob_recursive($pattern, $flags=0) {
$files=glob($pattern, $flags);
foreach ( glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir ) {
$files=array_merge($files, self::glob_recursive($dir . '/' . basename($pattern), $flags));
}
return $files;
}
Expand Down
76 changes: 34 additions & 42 deletions micro/cache/ClassUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,62 @@
namespace micro\cache;

class ClassUtils {

/**
* get the full name (name \ namespace) of a class from its file path
* result example: (string) "I\Am\The\Namespace\Of\This\Class"
*
* @param $filePathName
*
* @return string
* @return string
*/
public static function getClassFullNameFromFile($filePathName){
public static function getClassFullNameFromFile($filePathName) {
return self::getClassNamespaceFromFile($filePathName) . '\\' . self::getClassNameFromFile($filePathName);
}

public static function cleanClassname($classname){
public static function cleanClassname($classname) {
return \str_replace("\\", "\\\\", $classname);
}


/**
* build and return an object of a class from its file path
*
* @param $filePathName
*
* @return mixed
* @return mixed
*/
public static function getClassObjectFromFile($filePathName){
$classString = self::getClassFullNameFromFile($filePathName);
$object = new $classString;
public static function getClassObjectFromFile($filePathName) {
$classString=self::getClassFullNameFromFile($filePathName);
$object=new $classString();
return $object;
}





/**
* get the class namespace form file path using token
*
* @param $filePathName
*
* @return null|string
* @return null|string
*/
protected static function getClassNamespaceFromFile($filePathName){
$src = file_get_contents($filePathName);
protected static function getClassNamespaceFromFile($filePathName) {
$src=file_get_contents($filePathName);

$tokens = token_get_all($src);
$count = count($tokens);
$i = 0;
$namespace = '';
$namespace_ok = false;
while ($i < $count) {
$token = $tokens[$i];
$tokens=token_get_all($src);
$count=count($tokens);
$i=0;
$namespace='';
$namespace_ok=false;
while ( $i < $count ) {
$token=$tokens[$i];
if (is_array($token) && $token[0] === T_NAMESPACE) {
// Found namespace declaration
while (++$i < $count) {
while ( ++$i < $count ) {
if ($tokens[$i] === ';') {
$namespace_ok = true;
$namespace = trim($namespace);
$namespace_ok=true;
$namespace=trim($namespace);
break;
}
$namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
$namespace.=is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
}
break;
}
Expand All @@ -80,26 +76,22 @@ protected static function getClassNamespaceFromFile($filePathName){
*
* @param $filePathName
*
* @return mixed
* @return mixed
*/
protected static function getClassNameFromFile($filePathName)
{
$php_code = file_get_contents($filePathName);
protected static function getClassNameFromFile($filePathName) {
$php_code=file_get_contents($filePathName);

$classes = array();
$tokens = token_get_all($php_code);
$count = count($tokens);
for ($i = 2; $i < $count; $i++) {
if ($tokens[$i - 2][0] == T_CLASS
&& $tokens[$i - 1][0] == T_WHITESPACE
&& $tokens[$i][0] == T_STRING
) {
$classes=array ();
$tokens=token_get_all($php_code);
$count=count($tokens);
for($i=2; $i < $count; $i++) {
if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {

$class_name = $tokens[$i][1];
$classes[] = $class_name;
}
$class_name=$tokens[$i][1];
$classes[]=$class_name;
}
}

return $classes[0];
}
}
}

0 comments on commit 6299682

Please sign in to comment.