/** * @param array $params */ public function setParams($params, $path = null) { if (null !== $path) { $this->params = ArrayUtils::set($this->params, $path, $params); } else { $this->params = $params; } }
public function DatesAction() { $this->autoRenderOff(); $manager = $this->getArticlesManager(); $dates = $manager->getDates(); $dates = ArrayUtils::filterNulls($dates); $dates = array_values($dates); $dates = json_encode($dates, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); echo $dates; }
/** * @return Config */ public function getConfig() { if (is_null($this->configObj)) { $defaultConfig = $this->getDefaultConfig(); $globalConfig = $this->readConfig(self::GLOBAL_CONFIG); $localConfig = $this->readConfig(self::LOCAL_CONFIG); $config = ArrayUtils::mergeRecursive($defaultConfig, $globalConfig, $localConfig); $this->configObj = new Config($config); } return $this->configObj; }
public function getParams($path = null, $default = null) { if (null === $this->params) { $this->params = $this->getParentCommand()->getParams(); } if (null === $path) { return $this->params; } else { return ArrayUtils::get($this->params, $path, $default); } }
public function isAllow($group, $resource, $user = null, $owner = null) { $resource = $this->prepareResource($resource); $params = ["-c" => $this->getAclFile(), "-g" => $group, "-r" => $resource, "-u" => $user, "-o" => $owner]; $params = ArrayUtils::filterNulls($params); $params = ArrayUtils::implodePairs(" ", $params, " "); $output = []; exec("x-acl " . $params, $output, $code); if ($code !== 0) { throw new \RuntimeException("Error in acl check. Code: {$code}. Msg: " . implode(" ", $output)); } $output = reset($output); return $output === "Access allow"; }
public static function replaceNamedParams($regexp, $params) { $regexp = ltrim($regexp, "^"); $regexp = rtrim($regexp, "\$"); if (!empty($params)) { $link = preg_replace_callback('~\\(\\?P<(\\w+)>.+\\)~U', function ($match) use(&$params) { return ArrayUtils::extract($params, $match[1], $match[0]); }, $regexp); } else { $link = preg_replace('~\\(\\?P<(\\w+)>.+\\)~U', "", $regexp); } $link = preg_replace(['~(\\/)(\\?+)~', '~\\?+$~'], ["\$1"], $link); return $link; }
/** * @param null $path * @param null $default * @return $this|null */ public function get($path = null, $default = null) { if (is_null($path)) { return $this; } $pathKey = implode('|', (array) $path); if (!isset($this->childConfig[$pathKey])) { if (!ArrayUtils::issetByPath($this->configRaw, $path)) { return is_array($default) ? new Config([]) : $default; } $needConfig = ArrayUtils::getByPath($this->configRaw, $path, $default); if (is_array($needConfig)) { $this->childConfig[$pathKey] = new Config($needConfig); } else { $this->childConfig[$pathKey] = $needConfig; } } return $this->childConfig[$pathKey]; }
public function getOrderBy($orderBy) { $orderStr = ""; if (!is_null($orderBy)) { if (is_array($orderBy)) { if (ArrayUtils::getArrayType($orderBy) === -1) { $orderField = $orderBy[0]; $orderDirect = $orderBy[1]; $orderStr = " order by {$orderField} {$orderDirect}"; } else { foreach ($orderBy as $key => $value) { $orderStr = " order by {$key} {$value}"; } } } else { $orderStr = " order by {$orderBy}"; } } return $orderStr; }
/** * @param CommandInterface $command * @return WorkerInterface[] */ public function getCommandWorkers(CommandInterface $command) { $class = (string) $command->getClass(); $action = $command->getName(); do { if (false === $class) { $class = ""; } $path = [$action, $class]; if (ArrayUtils::issetByPath($this->actionMap, $path)) { $workers = ArrayUtils::get($this->actionMap, $path); $workers = ArrayUtils::sortByKey($workers); //may be cache like: $this->actionMap = ArrayUtils::set($this->actionMap, $path, $workers); foreach ($workers as $worker) { (yield $this->getWorker($worker["name"])); } } if ("" !== $class) { $class = get_parent_class($class); } } while ("" !== $class); }
public function getMonths() { $table = $this->getTable(); $sql = "select distinct to_char(created, 'YYYY-MM') from {$table}"; $months = $this->getAdapter()->selectCol($sql); $months = array_map(function ($value) { return new \DateTime($value); }, ArrayUtils::filterNulls($months)); return $months; }
public function loadUntrusted(EntityInterface &$entity, array $data, $id = null) { $data = ArrayUtils::renameKeys($data, function ($var) { return StringUtils::camelCaseToLowDash($var); }); $id = $id ?: isset($data["id"]) ? $data["id"] : null; if ($id) { if ($this->getIdMap()->has($id)) { $entityHas = $this->getIdMap()->get($id); if ($entityHas->isTrusted()) { $entity = $entityHas; return $entity; } } } $entity->setUntrusted(); $this->load($entity, $data); $this->getIdMap()->set($id, $entity); return $entity; }
public function readMenu() { $configDir = $this->getConfigDir(); $globalMenu = $this->readMenuRaw($configDir . "global.menu.php", []); $localMenu = $this->readMenuRaw($configDir . "local.menu.php", []); $moduleManager = $this->getModuleManager(); $modules = $moduleManager->getModulesList(); $menuConfig = []; foreach ($modules as $moduleName) { $modulePath = $moduleManager->getModulePath($moduleName); $moduleConfig = $this->readMenuRaw($modulePath . "/config/menu.php", null); if ($moduleConfig) { $menuConfig = array_merge_recursive($menuConfig, $moduleConfig); } } $menuConfig = ArrayUtils::mergeRecursive($menuConfig, $globalMenu, $localMenu); return $menuConfig; }
public static function toString($var, $oneField = false, $implode = false) { if ($oneField === true) { $oneField = "id"; } if ($implode === true) { $implode = ", "; } switch (gettype($var)) { case "boolean": case "integer": case "double": case "string": case "NULL": return (string) $var; case "array": if (!$oneField) { return $implode ? ArrayUtils::implodeRecursive($implode, $var) : ""; } else { return self::toString(array_key_exists($oneField, $var) ? $var[$oneField] : "", $oneField, $implode); } case "object": if ($var instanceof \DateTime) { return $var->format("Y-m-d h:i:s"); } if ($oneField) { if (property_exists($var, $oneField)) { return self::toString($var->{$oneField}, $oneField, $implode); } if (method_exists($var, $oneField)) { return self::toString($var->{$oneField}(), $oneField, $implode); } $method = "get" . ucfirst($oneField); if (method_exists($var, $method)) { return self::toString($var->{$method}(), $oneField, $implode); } return ""; } else { if (method_exists($var, "__toString")) { return (string) $var; } if (method_exists($var, "toArray")) { return self::toString($var->toArray()); } return self::toString(get_object_vars($var), $oneField, $implode); } default: throw new \InvalidArgumentException("work with type " . gettype($var) . " not implemented"); } }
public function render($params = [], $templateName = null) { if (!is_null($templateName)) { $this->setTemplate($templateName); } $vars = $this->getAssignedVars(); $vars = ArrayUtils::mergeRecursive($vars, $params); $globalVars = $this->getGlobalVars(); $render = $this->getRender(); foreach ($globalVars as $name => $value) { $render->addGlobal($name, $value); } /** @var \Twig_Environment $template */ $template = $this->getTemplate(); $output = $render->render($template, $vars); return $output; }
public function getListArrayConfigs($fileConfigName, $recursiveMerge = false) { $modules = $this->getModulesList(); $configs = []; foreach ($modules as $module) { $path = $this->getModulePath($module); if (!$path) { throw new \Exception("Path for module {$module} not found"); } $configFile = $path . "/config/{$fileConfigName}.php"; if (!file_exists($configFile)) { continue; } $moduleResources = (include $configFile); if ($recursiveMerge) { $configs = ArrayUtils::mergeRecursive($configs, $moduleResources); } else { $configs = array_merge($configs, $moduleResources); } } return $configs; }