diff --git a/.settings/org.eclipse.php.core.prefs b/.settings/org.eclipse.php.core.prefs new file mode 100644 index 0000000..b7c1348 --- /dev/null +++ b/.settings/org.eclipse.php.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +include_path=0;/Zirror-API/docroot/include diff --git a/.settings/org.eclipse.php.formatter.core.prefs b/.settings/org.eclipse.php.formatter.core.prefs index 4dab866..a0829ac 100755 --- a/.settings/org.eclipse.php.formatter.core.prefs +++ b/.settings/org.eclipse.php.formatter.core.prefs @@ -71,6 +71,7 @@ org.eclipse.php.formatter.core.formatter.indent_body_declarations_compare_to_type_header=true org.eclipse.php.formatter.core.formatter.indent_breaks_compare_to_cases=true org.eclipse.php.formatter.core.formatter.indent_empty_lines=false +org.eclipse.php.formatter.core.formatter.indent_heredocs=true org.eclipse.php.formatter.core.formatter.indent_statements_compare_to_block=true org.eclipse.php.formatter.core.formatter.indent_statements_compare_to_body=true org.eclipse.php.formatter.core.formatter.indent_switchstatements_compare_to_cases=true diff --git a/docroot/include/core/ZirrorAPI.php b/docroot/include/core/ZirrorAPI.php index 673a178..70cc389 100644 --- a/docroot/include/core/ZirrorAPI.php +++ b/docroot/include/core/ZirrorAPI.php @@ -12,7 +12,14 @@ $qualifiedModuleName = $request->getModule ( false ); - return (true); + $handlerClass = ZirrorAPI_Loader::getComponentClassName ( $componentType, $componentName, $qualifiedModuleName ); + $handler = new $handlerClass (); + + if ($handler) { + + return (true); + } else + return (false); } diff --git a/docroot/include/runtime/Loader.php b/docroot/include/runtime/Loader.php new file mode 100644 index 0000000..835ac13 --- /dev/null +++ b/docroot/include/runtime/Loader.php @@ -0,0 +1,115 @@ + $LOADER_FILE_DIR + * @param $qualifiedName + * @return Absolute File Name + */ + static function resolveNameToPath($qualifiedName, $fileExtension = 'php') { + + global $LOADER_FILE_DIR; + $allowedExtensions = array ( + 'php', + 'js', + 'css', + 'less' + ); + + $file = ''; + if (! in_array ( $fileExtension, $allowedExtensions )) { + return ''; + } + // TO handle loading vtiger files + if (strpos ( $qualifiedName, '~~' ) === 0) { + $file = str_replace ( '~~', '', $qualifiedName ); + $file = $LOADER_FILE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $file; + } else if (strpos ( $qualifiedName, '~' ) === 0) { + $file = str_replace ( '~', '', $qualifiedName ); + $file = $LOADER_FILE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $file; + } else { + $file = str_replace ( '.', DIRECTORY_SEPARATOR, $qualifiedName ) . '.' . $fileExtension; + $file = $LOADER_FILE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $file; + } + return $file; + + } + + /** + * Function to get the class name of a given Component, of given Type, for a given Module + * + * @param $componentType + * @param $componentName + * @param $moduleName + * @return Required Class Name + * @throws AppException + */ + public static function getComponentClassName($componentType, $componentName, $moduleName = 'Vtiger') { + + // Change component type from view to views, action to actions to navigate to the right path. + $componentTypeDirectory = strtolower ( $componentType ) . 's'; + // Fall Back Directory & Fall Back Class + $fallBackModuleDir = $fallBackModuleClassPath = 'Vtiger'; + // Intermediate Fall Back Directories & Classes, before relying on final fall back + $firstFallBackModuleDir = $firstFallBackModuleClassPath = ''; + $secondFallBackDir = $secondFallBackClassPath = ''; + // Default module directory & class name + $moduleDir = $moduleClassPath = $moduleName; + // Change the Module directory & class, along with intermediate fall back directory and class, if module names has submodule as well + if (strpos ( $moduleName, ':' ) > 0) { + $moduleHierarchyParts = explode ( ':', $moduleName ); + $moduleDir = str_replace ( ':', '.', $moduleName ); + $moduleClassPath = str_replace ( ':', '_', $moduleName ); + $actualModule = $moduleHierarchyParts [count ( $moduleHierarchyParts ) - 1]; + $secondFallBackModuleDir = $secondFallBackModuleClassPath = $actualModule; + if ($actualModule != 'Users') { + $baseModule = $moduleHierarchyParts [0]; + if ($baseModule == 'Settings') + $baseModule = 'Settings:Vtiger'; + $firstFallBackDir = str_replace ( ':', '.', $baseModule ); + $firstFallBackClassPath = str_replace ( ':', '_', $baseModule ); + } + } + // Build module specific file path and class name + $moduleSpecificComponentFilePath = ZirrorAPI_Loader::resolveNameToPath ( 'modules.' . $moduleDir . '.' . $componentTypeDirectory . '.' . $componentName ); + $moduleSpecificComponentClassName = $moduleClassPath . '_' . $componentName . '_' . $componentType; + if (file_exists ( $moduleSpecificComponentFilePath )) { + return $moduleSpecificComponentClassName; + } + + // Build first intermediate fall back file path and class name + if (! empty ( $firstFallBackDir ) && ! empty ( $firstFallBackClassPath )) { + $fallBackComponentFilePath = ZirrorAPI_Loader::resolveNameToPath ( 'modules.' . $firstFallBackDir . '.' . $componentTypeDirectory . '.' . $componentName ); + $fallBackComponentClassName = $firstFallBackClassPath . '_' . $componentName . '_' . $componentType; + + if (file_exists ( $fallBackComponentFilePath )) { + return $fallBackComponentClassName; + } + } + + // Build intermediate fall back file path and class name + if (! empty ( $secondFallBackModuleDir ) && ! empty ( $secondFallBackModuleClassPath )) { + $fallBackComponentFilePath = ZirrorAPI_Loader::resolveNameToPath ( 'modules.' . $secondFallBackModuleDir . '.' . $componentTypeDirectory . '.' . $componentName ); + $fallBackComponentClassName = $secondFallBackModuleClassPath . '_' . $componentName . '_' . $componentType; + + if (file_exists ( $fallBackComponentFilePath )) { + return $fallBackComponentClassName; + } + } + + // Build fall back file path and class name + $fallBackComponentFilePath = ZirrorAPI_Loader::resolveNameToPath ( 'modules.' . $fallBackModuleDir . '.' . $componentTypeDirectory . '.' . $componentName ); + $fallBackComponentClassName = $fallBackModuleClassPath . '_' . $componentName . '_' . $componentType; + if (file_exists ( $fallBackComponentFilePath )) { + return $fallBackComponentClassName; + } + throw new AppException ( 'Handler not found.' ); + + } + +} \ No newline at end of file