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; }
public function notifyAboutNote(array $userIds, \Fox\Entities\Note $note) { $data = array('noteId' => $note->id); $encodedData = Json::encode($data); $now = date('Y-m-d H:i:s'); $pdo = $this->getEntityManager()->getPDO(); $sql = "INSERT INTO `notification` (`id`, `data`, `type`, `user_id`, `created_at`) VALUES "; $arr = []; foreach ($userIds as $userId) { $id = uniqid(); $arr[] = "(" . $pdo->quote($id) . ", " . $pdo->quote($encodedData) . ", " . $pdo->quote('Note') . ", " . $pdo->quote($userId) . ", " . $pdo->quote($now) . ")"; } if (empty($arr)) { return; } $sql .= implode(", ", $arr); $pdo->query($sql); }
public function save(Entity $entity) { if ($entity->id) { $this->data[$entity->id] = $entity->toArray(); $fields = $fields = $this->getMetadata()->get('entityDefs.Preferences.fields'); $data = array(); foreach ($this->data[$entity->id] as $field => $value) { if (empty($fields[$field]['notStorable'])) { $data[$field] = $value; } } $fileName = $this->getFilePath($entity->id); $this->getFileManager()->putContents($fileName, Json::encode($data, \JSON_PRETTY_PRINT)); $this->storeAutoFollowEntityTypeList($entity); return $entity; } }
/** * Get All Metadata context * * @param $isJSON * @param bool $reload * * @return json | array */ public function getAll($isJSON = false, $reload = false) { if ($reload) { $this->init(true); } if ($isJSON) { return Json::encode($this->meta); } return $this->meta; }
/** * Merge file content and save it to a file * * @param string | array $path * @param string $content JSON string * @param bool $isReturnJson * @param string | array $removeOptions - List of unset keys from content * @param bool $isPhp - Is merge php files * * @return bool | array */ public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false) { if ($isPhp) { $fileContent = $this->getPhpContents($path); } else { $fileContent = $this->getContents($path); } $fullPath = $this->concatPaths($path); if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) { throw new Error('FileManager: Failed to read file [' . $fullPath . '].'); } $savedDataArray = Utils\Json::getArrayData($fileContent); $newDataArray = Utils\Json::getArrayData($content); if (isset($removeOptions)) { $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions); $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions); } $data = Utils\Util::merge($savedDataArray, $newDataArray); if ($isReturnJson) { $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } if ($isPhp) { return $this->putPhpContents($path, $data); } return $this->putContents($path, $data); }