Example #1
0
 protected function getNotificator($entityType)
 {
     if (empty($this->notifatorsHash[$entityType])) {
         $normalizedName = Util::normilizeClassName($entityType);
         $className = '\\Fox\\Custom\\Notificators\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->getMetadata()->getScopeModuleName($entityType);
             if ($moduleName) {
                 $className = '\\Fox\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
             } else {
                 $className = '\\Fox\\Notificators\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Fox\\Core\\Notificators\\Base';
             }
         }
         $notificator = new $className();
         $dependencies = $notificator->getDependencyList();
         foreach ($dependencies as $name) {
             $notificator->inject($name, $this->getContainer()->get($name));
         }
         $this->notifatorsHash[$entityType] = $notificator;
     }
     return $this->notifatorsHash[$entityType];
 }
Example #2
0
 public function getImplementation($scope)
 {
     if (empty($this->implementationHashMap[$scope])) {
         $normalizedName = Util::normilizeClassName($scope);
         $className = '\\Fox\\Custom\\Acl\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->metadata->getScopeModuleName($scope);
             if ($moduleName) {
                 $className = '\\Fox\\Modules\\' . $moduleName . '\\Acl\\' . $normalizedName;
             } else {
                 $className = '\\Fox\\Acl\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Fox\\Core\\Acl\\Base';
             }
         }
         if (class_exists($className)) {
             $acl = new $className();
             $dependencies = $acl->getDependencyList();
             foreach ($dependencies as $name) {
                 $acl->inject($name, $this->container->get($name));
             }
             $this->implementationHashMap[$scope] = $acl;
         } else {
             throw new Error();
         }
     }
     return $this->implementationHashMap[$scope];
 }
Example #3
0
 /**
  * Get class name of a job
  *
  * @param  string $name
  * @return string
  */
 protected function getClassName($name)
 {
     $name = Util::normilizeClassName($name);
     $data = $this->getAll();
     $name = ucfirst($name);
     if (isset($data[$name])) {
         return $data[$name];
     }
     return false;
 }
Example #4
0
 public function normalizeEntityName($name)
 {
     if (empty($this->entityClassNameHash[$name])) {
         $className = '\\Fox\\Custom\\Entities\\' . Util::normilizeClassName($name);
         if (!class_exists($className)) {
             $className = $this->espoMetadata->getEntityPath($name);
         }
         $this->entityClassNameHash[$name] = $className;
     }
     return $this->entityClassNameHash[$name];
 }
Example #5
0
 protected function getClassName($name)
 {
     $name = Util::normilizeClassName($name);
     if (!isset($this->data)) {
         $this->init();
     }
     $name = ucfirst($name);
     if (isset($this->data[$name])) {
         return $this->data[$name];
     }
     return false;
 }
Example #6
0
 public function process($controllerName, $actionName, $params, $data, $request)
 {
     $customeClassName = '\\Fox\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
     if (class_exists($customeClassName)) {
         $controllerClassName = $customeClassName;
     } else {
         $moduleName = $this->metadata->getScopeModuleName($controllerName);
         if ($moduleName) {
             $controllerClassName = '\\Fox\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
         } else {
             $controllerClassName = '\\Fox\\Controllers\\' . Util::normilizeClassName($controllerName);
         }
     }
     if ($data && stristr($request->getContentType(), 'application/json')) {
         $data = json_decode($data);
     }
     if ($data instanceof \stdClass) {
         $data = get_object_vars($data);
     }
     if (!class_exists($controllerClassName)) {
         throw new NotFound("Controller '{$controllerName}' is not found");
     }
     $controller = new $controllerClassName($this->container, $request->getMethod());
     if ($actionName == 'index') {
         $actionName = $controllerClassName::$defaultAction;
     }
     $actionNameUcfirst = ucfirst($actionName);
     $beforeMethodName = 'before' . $actionNameUcfirst;
     $actionMethodName = 'action' . $actionNameUcfirst;
     $afterMethodName = 'after' . $actionNameUcfirst;
     $fullActionMethodName = strtolower($request->getMethod()) . ucfirst($actionMethodName);
     if (method_exists($controller, $fullActionMethodName)) {
         $primaryActionMethodName = $fullActionMethodName;
     } else {
         $primaryActionMethodName = $actionMethodName;
     }
     if (!method_exists($controller, $primaryActionMethodName)) {
         throw new NotFound("Action '{$actionName}' (" . $request->getMethod() . ") does not exist in controller '{$controllerName}'");
     }
     if (method_exists($controller, $beforeMethodName)) {
         $controller->{$beforeMethodName}($params, $data, $request);
     }
     $result = $controller->{$primaryActionMethodName}($params, $data, $request);
     if (method_exists($controller, $afterMethodName)) {
         $controller->{$afterMethodName}($params, $data, $request);
     }
     if (is_array($result) || is_bool($result)) {
         return \Fox\Core\Utils\Json::encode($result);
     }
     return $result;
 }
Example #7
0
 public function create($entityType)
 {
     $normalizedName = Util::normilizeClassName($entityType);
     $className = '\\Fox\\Custom\\SelectManagers\\' . $normalizedName;
     if (!class_exists($className)) {
         $moduleName = $this->metadata->getScopeModuleName($entityType);
         if ($moduleName) {
             $className = '\\Fox\\Modules\\' . $moduleName . '\\SelectManagers\\' . $normalizedName;
         } else {
             $className = '\\Fox\\SelectManagers\\' . $normalizedName;
         }
         if (!class_exists($className)) {
             $className = '\\Fox\\Core\\SelectManagers\\Base';
         }
     }
     $selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
     $selectManager->setEntityType($entityType);
     return $selectManager;
 }
Example #8
0
 public function delete($name)
 {
     if (!$this->isCustom($name)) {
         throw new Forbidden();
     }
     $normalizedName = Util::normilizeClassName($name);
     $unsets = array('entityDefs', 'clientDefs', 'scopes');
     $res = $this->getMetadata()->delete('entityDefs', $name);
     $res = $this->getMetadata()->delete('clientDefs', $name);
     $res = $this->getMetadata()->delete('scopes', $name);
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/entityDefs/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/clientDefs/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/scopes/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Entities/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Services/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Controllers/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Repositories/{$normalizedName}.php");
     try {
         $this->getLanguage()->delete('Global', 'scopeNames', $name);
         $this->getLanguage()->delete('Global', 'scopeNamesPlural', $name);
     } catch (\Exception $e) {
     }
     $this->getMetadata()->save();
     $this->getLanguage()->save();
     return true;
 }
Example #9
0
 public function getRepositoryPath($entityName, $delim = '\\')
 {
     $path = $this->getScopePath($entityName, $delim);
     return implode($delim, array($path, 'Repositories', Util::normilizeClassName(ucfirst($entityName))));
 }