public static function processRule(App_Acl $acl, $role, $rule) { $resources = App_Util_String::cleanCsvParam($rule, 'resource', array()); $actions = App_Util_String::cleanCsvParam($rule, 'action', array()); if (isset($rule->fields) || isset($rule->default)) { if (isset($rule->default)) { if (filter_var($rule->default, FILTER_VALIDATE_BOOLEAN)) { $asserts = array(); } else { if (isset($rule->default)) { $asserts = 'NotAllowed'; } } $defaultActions = $actions; array_walk($defaultActions, function (&$item) { $item .= '_default'; }); self::createPermission($acl, $role, $resources, $defaultActions, $asserts); } $fields = App_Util_String::cleanCsvParam($rule, 'fields', array()); $newActions = array(); foreach ($fields as $field) { $fieldActions = $actions; array_walk($fieldActions, function (&$item) use($field) { $item .= '_' . $field; }); $newActions = array_merge($newActions, $fieldActions); } $actions = $newActions; } $asserts = App_Util_String::cleanCsvParam($rule, 'assert', array()); self::createPermission($acl, $role, $resources, $actions, $asserts); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if the string length of $value is at least the min option and * no greater than the max option (when the max option is not null). * * @param string $value * @return boolean */ public function isValid($value) { if (!is_string($value)) { $this->_error(self::INVALID); return false; } $this->_setValue($value); if ($this->_encoding !== null) { $length = iconv_strlen($value, $this->_encoding); } else { $length = iconv_strlen($value, 'UTF-8'); } $counter = array_count_values(App_Util_String::strToArray($value)); foreach (static::$doubleCountChars as $char) { if (isset($counter[$char])) { $length += $counter[$char]; } } if ($length < $this->_min) { $this->_error(self::TOO_SHORT); } if (null !== $this->_max && $this->_max < $length) { $this->_error(self::TOO_LONG); } if (count($this->_messages)) { return false; } else { return true; } }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid postalcode * * @param string $value * @param Default_Model_Organization_Address * @return boolean */ public function isValid($value, $context = null) { if (!is_string($value)) { $this->_error(self::INVALID); return false; } $result = array_diff(App_Util_String::strToArray($value), static::$alphabet); if (!empty($result)) { $this->_error(self::INVALID_CHAR, current($result)); return false; } return true; }
public function processResponse(Zend_Http_Response $response) { parent::processResponse($response); $data[] = $this->_path; $data[] = 'RESPONSE'; $data[] = round($this->getRestService()->getLastResultTimeSpent() * 1000) . 'ms'; $data[] = App_Util_String::formatBytes($this->_lastMessageSize); $data[] = $response->getStatus(); if ($this->getLogResponseBody()) { $body = $response->getBody(); if ($body) { $data[] = "\n" . $this->_processLogMessage($body); } else { $data[] = "No body data"; } } $this->getLogger()->log(implode(' | ', $data), Zend_Log::INFO); return $this; }
public function processResponseData(&$response) { if ($response instanceof \DrSlump\Protobuf\Message) { $data = $this->_prepareData($response); $data[] = 'RESPONSE'; $data[] = round($this->getRestService()->getLastResultTimeSpent() * 1000) . 'ms'; $data[] = App_Util_String::formatBytes($this->_lastMessageSize); if ($this->getLogResponseBody()) { if ($this->_lastMessageSize < $this->getMessageSizeLimit()) { $codec = new \DrSlump\Protobuf\Codec\TextFormat(); $out = $codec->encode($response); $data[] = get_class($response) . "\n" . $out; } else { $data[] = "\nData message is too big to log. Sorry..."; } } $this->getLogger()->log(implode(' | ', $data), Zend_Log::INFO); } return $this; }
public function removePermissions($ns, $removes) { $mapper = PermissionMapper::getInstance(); $defualtRoles = $mapper->findAllRoles($ns); $defaultResources = $mapper->findAllResources($ns); foreach ($removes as $rule) { $roles = \App_Util_String::cleanCsvParam($rule, 'role', $defualtRoles); $resources = \App_Util_String::cleanCsvParam($rule, 'resource', null); if ($resources === null) { foreach ($roles as $role) { try { $mapper->removeRoleId($role, $ns); \App::log()->notice("Removed role '{$role}' on namespace '{$ns}'"); } catch (NotFoundException $ex) { } } continue; } $actions = \App_Util_String::cleanCsvParam($rule, 'action', array()); foreach ($roles as $role) { foreach ($resources as $resource) { if (empty($actions)) { $mapper->unsetResource($ns, $role, $resource); \App::log()->notice("Removed resource '{$resource}' for role '{$role}' on namespace '{$ns}'"); } else { foreach ($actions as $action) { $mapper->unsetPermission($ns, $role, $resource, $action); \App::log()->notice("Removed permission '{$action}' of resource '{$resource}' for role '{$role}' on namespace '{$ns}'"); } } } } } }
/** * Get result from Ericsson * * @param string $name Service name at ericsson.ini * @param string $sp Optional service provider */ protected function _getEricssonList($name, $sp = null, $filter = false) { // Cache hit? $cacheId = \App_Util_String::toCacheId($sp ? $name . '_' . $sp : $name); if ($data = $this->getCache()->load($cacheId)) { return $data; } // Cache miss $data = $this->_processResponse($name, $sp); if ($filter) { $this->_filterServiceProviderData($data, $sp); } // Cache store $tags = $sp ? array($sp) : array(); $this->getCache()->save($data, $cacheId, $tags); return $data; }
protected function _createCacheTags($tags = array()) { $tags = array_merge($tags, $this->_tags); $tags = array_values(array_unique($tags)); array_walk($tags, function (&$tag, $key) { $tag = \App_Util_String::toCacheId($tag); }); return $tags; }
/** * Generate cache id with prefix to avoid collisions * * @param string $transactionId * @return string */ protected function _getCacheId($transactionId) { return 'tx' . \App_Util_String::toCacheId($transactionId); }
/** * * @param string $resource * @param string $key * @return array */ protected function _getConfig($resource, $key) { if (!in_array($resource, array(self::RESOURCE_REPORT, self::RESOURCE_SIM))) { throw new InvalidArgumentException("Invalid config resource ({$resource})"); } if (!in_array($key, array(self::KEY_HEADERS, self::KEY_FILTERS, self::KEY_FILE_HEADERS, self::KEY_FILE_FOOTERS))) { throw new InvalidArgumentException("Invalid config key ({$key})"); } // Get CSV configuration $cacheId = \App_Util_String::toCacheId('csv_config_' . $resource); $config = \App::cache()->load($cacheId); if (empty($config)) { $config = new \Tid_Zend_Config_Yaml(APPLICATION_PATH . "/modules/default/views/csv/{$resource}.yml"); \App::cache()->save($config, $cacheId); } return $config; }