public function get($id = null) { if ($id) { $entity = $this->entityFactory->create('Preferences'); $entity->id = $id; if (empty($this->data[$id])) { $fileName = $this->getFilePath($id); if (file_exists($fileName)) { $d = Json::decode($this->getFileManager()->getContents($fileName)); $this->data[$id] = get_object_vars($d); } else { $fields = $this->getMetadata()->get('entityDefs.Preferences.fields'); $defaults = array(); $defaults['dashboardLayout'] = $this->getMetadata()->get('app.defaultDashboardLayouts.Standard'); $defaults['dashletOptions'] = $this->getMetadata()->get('app.defaultDashboardOptions.Standard'); foreach ($fields as $field => $d) { if (array_key_exists('default', $d)) { $defaults[$field] = $d['default']; } } foreach ($this->defaultAttributesFromSettings as $attr) { $defaults[$attr] = $this->getConfig()->get($attr); } $this->data[$id] = $defaults; } } $entity->set($this->data[$id]); $this->fetchAutoFollowEntityTypeList($entity); $entity->setAsFetched($this->data[$id]); $d = $entity->toArray(); return $entity; } }
protected function restoreFiles() { $packagePath = $this->getPath('packagePath'); $filesPath = Util::concatPath($packagePath, self::FILES); if (!file_exists($filesPath)) { $this->unzipArchive($packagePath); } $res = $this->copy($filesPath, '', true); $manifestJson = $this->getFileManager()->getContents(array($packagePath, $this->manifestName)); $manifest = Json::decode($manifestJson, true); if (!empty($manifest['delete'])) { $res &= $this->getFileManager()->remove($manifest['delete'], null, true); } $res &= $this->getFileManager()->removeInDir($packagePath, true); return $res; }
public function getManifest() { if (!isset($this->data['manifest'])) { $packagePath = $this->getPackagePath(); $manifestPath = Util::concatPath($packagePath, $this->manifestName); if (!file_exists($manifestPath)) { $this->throwErrorAndRemovePackage('It\'s not an Installation package.'); } $manifestJson = $this->getFileManager()->getContents($manifestPath); $this->data['manifest'] = Json::decode($manifestJson, true); if (!$this->data['manifest']) { $this->throwErrorAndRemovePackage('Syntax error in manifest.json.'); } if (!$this->checkManifest($this->data['manifest'])) { $this->throwErrorAndRemovePackage('Unsupported package.'); } } return $this->data['manifest']; }
public function create($name, $type, $params = array()) { if ($this->getMetadata()->get('scopes.' . $name)) { throw new Conflict('Entity [' . $name . '] already exists.'); } if (empty($name) || empty($type)) { throw new Error(); } $normalizedName = Util::normilizeClassName($name); $contents = "<" . "?" . "php\n\n" . "namespace Fox\\Custom\\Entities;\n\n" . "class {$normalizedName} extends \\Fox\\Core\\Templates\\Entities\\{$type}\n" . "{\n" . " protected \$entityType = \"{$name}\";\n" . "}\n"; $filePath = "custom/Fox/Custom/Entities/{$normalizedName}.php"; $this->getFileManager()->putContents($filePath, $contents); $contents = "<" . "?" . "php\n\n" . "namespace Fox\\Custom\\Controllers;\n\n" . "class {$normalizedName} extends \\Fox\\Core\\Templates\\Controllers\\{$type}\n" . "{\n" . "}\n"; $filePath = "custom/Fox/Custom/Controllers/{$normalizedName}.php"; $this->getFileManager()->putContents($filePath, $contents); $contents = "<" . "?" . "php\n\n" . "namespace Fox\\Custom\\Services;\n\n" . "class {$normalizedName} extends \\Fox\\Core\\Templates\\Services\\{$type}\n" . "{\n" . "}\n"; $filePath = "custom/Fox/Custom/Services/{$normalizedName}.php"; $this->getFileManager()->putContents($filePath, $contents); $contents = "<" . "?" . "php\n\n" . "namespace Fox\\Custom\\Repositories;\n\n" . "class {$normalizedName} extends \\Fox\\Core\\Templates\\Repositories\\{$type}\n" . "{\n" . "}\n"; $filePath = "custom/Fox/Custom/Repositories/{$normalizedName}.php"; $this->getFileManager()->putContents($filePath, $contents); $stream = false; if (!empty($params['stream'])) { $stream = $params['stream']; } $labelSingular = $name; if (!empty($params['labelSingular'])) { $labelSingular = $params['labelSingular']; } $labelPlural = $name; if (!empty($params['labelPlural'])) { $labelPlural = $params['labelPlural']; } $labelCreate = $this->getLanguage()->translate('Create') . ' ' . $labelSingular; $filePath = "application/Fox/Core/Templates/Metadata/{$type}/scopes.json"; $scopesDataContents = $this->getFileManager()->getContents($filePath); $scopesDataContents = str_replace('{entityType}', $name, $scopesDataContents); $scopesData = Json::decode($scopesDataContents, true); $scopesData['stream'] = $stream; $scopesData['type'] = $type; $scopesData['module'] = 'Custom'; $scopesData['object'] = true; $scopesData['isCustom'] = true; $this->getMetadata()->set('scopes', $name, $scopesData); $filePath = "application/Fox/Core/Templates/Metadata/{$type}/entityDefs.json"; $entityDefsDataContents = $this->getFileManager()->getContents($filePath); $entityDefsDataContents = str_replace('{entityType}', $name, $entityDefsDataContents); $entityDefsData = Json::decode($entityDefsDataContents, true); $this->getMetadata()->set('entityDefs', $name, $entityDefsData); $filePath = "application/Fox/Core/Templates/Metadata/{$type}/clientDefs.json"; $clientDefsContents = $this->getFileManager()->getContents($filePath); $clientDefsContents = str_replace('{entityType}', $name, $clientDefsContents); $clientDefsData = Json::decode($clientDefsContents, true); $this->getMetadata()->set('clientDefs', $name, $clientDefsData); $this->getLanguage()->set('Global', 'scopeNames', $name, $labelSingular); $this->getLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural); $this->getLanguage()->set($name, 'labels', 'Create ' . $name, $labelCreate); $this->getMetadata()->save(); $this->getLanguage()->save(); $layoutsPath = "application/Fox/Core/Templates/Layouts/{$type}"; if ($this->getFileManager()->isDir($layoutsPath)) { $this->getFileManager()->copy($layoutsPath, 'custom/Fox/Custom/Resources/layouts/' . $name); } return true; }
/** * Run Service * * @param array $job * * @return void */ protected function runService(array $job) { $serviceName = $job['service_name']; if (!$this->getServiceFactory()->checkExists($serviceName)) { throw new NotFound(); } $service = $this->getServiceFactory()->create($serviceName); $serviceMethod = $job['method']; if (!method_exists($service, $serviceMethod)) { throw new NotFound(); } $data = $job['data']; if (Json::isJSON($data)) { $data = Json::decode($data, true); } $service->{$serviceMethod}($data); }
/** * Load default values for selected type [metadata, layouts] * * @param string $name * @param string $type - [metadata, layouts] * * @return array */ protected function loadDefaultValues($name, $type = 'metadata') { $defaultPath = $this->params['defaultsPath']; $defaultValue = $this->getFileManager()->getContents(array($defaultPath, $type, $name . '.json')); if ($defaultValue !== false) { //return default array return Utils\Json::decode($defaultValue, true); } return array(); }