Overview

Namespaces

  • Cron
  • None

Classes

  • _HtmlGrid_TableOut
  • _TransactionModel_RawSaveOperation
  • AccessControlComponent
  • AccessControlHelper
  • ActionListHelper
  • ActiveDirectoryUtils
  • AddCurrentPidToSchedulingShellCallLogs
  • AnonymousFunctionOperation
  • ArrayUtil
  • AssociationIntegrityBehavior
  • AtomicOperation
  • AuthenticationComponent
  • AuthenticationController
  • AuthenticationUser
  • AutocompleteDatasourceComponent
  • BaseModelComponent
  • Basics
  • CakeLayersHelper
  • CheckAndRunShell
  • ClassSearcher
  • CommandLineUtil
  • CommonValidationBehavior
  • ConfigurableShellCallsSchedulingTask
  • ConfigurationKey
  • ConfigurationKeys
  • ConfigurationKeysController
  • Context
  • ContextComponent
  • ContextHelper
  • Contexts
  • ControllerInspector
  • ControllerMenuHelper
  • CreateJournalingTables
  • CreateTableConfigurationKeys
  • CreateTableSchedulingConfigurableShellCalls
  • CreateTableSchedulingShellCallLogs
  • CreateTableSettedConfigurationKeys
  • CreateTableUserResetPasswordRequests
  • CreateTableUsers
  • CronSchedulingInstaller
  • CronValidationBehavior
  • CssBox
  • CssController
  • CssProperties
  • CssShell
  • CsvUtil
  • CustomDataModel
  • DatasourceDumperManager
  • DateTimeInput
  • DependencyShell
  • DetailHelper
  • DumperShell
  • ExtendedFieldsAccessControl
  • ExtendedFieldSet
  • ExtendedFieldSetHelper
  • ExtendedFieldsParser
  • ExtendedFormHelper
  • ExtendedHasManyAppModel
  • ExtendedOperationsBehavior
  • FieldDefinition
  • FieldRowDefinition
  • FieldSetDefinition
  • FieldSetLayoutHelper
  • FileOperations
  • FileOperations_Rename
  • FileOperations_SymLink
  • FileOperations_Touch
  • FileOperations_Unlink
  • FileSystem
  • FixConfigurationKeysPrimaryKey
  • FixSettedConfigurationKeysPrimaryKey
  • HasManyUtilsBehavior
  • HtmlDocument
  • HtmlGrid
  • HtmlGrid_Cell
  • HttpClient
  • HttpResponse
  • ImapClient
  • ImapMailBox
  • ImapParserShell
  • IncludePath
  • InputMasked
  • InputSearchable
  • InputsOnSubmit
  • InstallShell
  • JenkinsBuildShell
  • Journal
  • JournalDetail
  • JournalizedBehavior
  • JsonResponseComponent
  • LayoutsHelper
  • Ldap
  • LdapUtils
  • ListFieldSet
  • ListFieldSetHelper
  • ListsHelper
  • MailParser
  • Make
  • MenuHelper
  • MigrationAllPluginsShell
  • ModelOperations
  • ModelOperations_Delete
  • ModelOperations_Save
  • ModelTraverser
  • MysqlDumper
  • OpenLdapUtils
  • PaginatorUtilComponent
  • PaginatorUtilComponentFilter
  • PaginatorUtilHelper
  • Plugin
  • PluginManager
  • Reflections
  • RenameEnabledToActiveFromUsersTable
  • RunShellCallShell
  • ScaffoldUtilComponent
  • ScaffoldUtilHelper
  • Scheduling
  • SchedulingConfigurableShellCall
  • SchedulingConfigurableShellCallsController
  • SchedulingShellCallLog
  • SchedulingShellCallLogsController
  • SettedConfigurationKey
  • StuffreposPluginsRename
  • TimeZoneBehavior
  • TransactionModel
  • TransactionOperation
  • Translator
  • TranslatorShell
  • User
  • UserAuthenticationComponent
  • UserChangePassword
  • UserResetPassword
  • UserResetPasswordRequest
  • UserResetPasswordRequestSubmission
  • UsersController
  • ViewUtilHelper

Interfaces

  • AccessControlFilter
  • CommitableOperation
  • DatasourceDumper
  • MakeListener
  • SchedulingInstaller
  • TasksObject
  • UndoableOperation

Exceptions

  • LdapObjectNotWritableException
  • ModelTraverserException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: App::uses('ClassRegistry', 'Utility');
  4: App::uses('Sanitize', 'Utility');
  5: 
  6: class ConfigurationKeys {
  7:     
  8:     const LIST_SEPARATOR = '|';
  9: 
 10:     /**
 11:      * @var array(key:string => options:array())
 12:      */
 13:     private static $keys = null;
 14: 
 15:     public static function reset() {
 16:         self::$keys = null;
 17:     }
 18: 
 19:     private static function _getKeys() {
 20:         if (self::$keys === null) {
 21:             if ((self::$keys = Configure::read('configurationKeys'))) {
 22:                 foreach (self::$keys as $key => $options) {
 23:                     if (is_int($key)) {
 24:                         $key = $options;
 25:                         $options = array();
 26:                     }
 27:                     self::$keys[$key] = $options + array(
 28:                         'description' => null,
 29:                         'defaultValue' => null,
 30:                         'listOptions' => null,
 31:                     );
 32:                 }
 33:             }
 34:         }
 35:         return self::$keys;
 36:     }
 37: 
 38:     public static function getKeys() {
 39:         return array_keys(self::_getKeys());
 40:     }
 41: 
 42:     public static function getRequiredKeyValue($key) {
 43:         if (($value = self::getKeyValue($key))) {
 44:             return $value;
 45:         } else {
 46:             throw new Exception(sprintf(__d('configuration_keys','Configuration value not found to key=%s'), $key));
 47:         }
 48:     }
 49: 
 50:     public static function getKeyValue($key) {
 51:         self::_throwExceptionIfKeyNotExists($key);
 52: 
 53:         $SettedConfigurationKey = ClassRegistry::init('ConfigurationKeys.SettedConfigurationKey');
 54:         $settedConfigurationKey = $SettedConfigurationKey->findByName($key);
 55:         if ($settedConfigurationKey) {
 56:             return $settedConfigurationKey[$SettedConfigurationKey->alias]['value'];
 57:         } else {
 58:             return self::$keys[$key]['defaultValue'];
 59:         }
 60:     }
 61:     
 62:     public static function getKeyValueAsList($key) {
 63:         return array_map(function($value) {
 64:             return trim($value);
 65:         }, explode(self::LIST_SEPARATOR, self::getKeyValue($key)));
 66:     }
 67: 
 68:     public static function getKeyDefaultValue($key) {
 69:         self::_throwExceptionIfKeyNotExists($key);
 70:         return self::$keys[$key]['defaultValue'];
 71:     }
 72:     
 73:     public static function getKeyValueSql($key) {
 74:         self::_throwExceptionIfKeyNotExists($key);
 75:         $SettedConfigurationKey = ClassRegistry::init('ConfigurationKeys.SettedConfigurationKey');
 76:         $defaultValue = Sanitize::escape(self::$keys[$key]['defaultValue'], $SettedConfigurationKey->useDbConfig);
 77:         $key = Sanitize::escape($key, $SettedConfigurationKey->useDbConfig);
 78:         return <<<EOT
 79: ifnull(
 80:         (
 81:     select scc.value
 82:     from {$SettedConfigurationKey->tablePrefix}{$SettedConfigurationKey->table} scc
 83:     where scc.name = '$key'
 84:     limit 1)
 85:     , '$defaultValue'
 86: )
 87: EOT;
 88:     }
 89: 
 90:     public static function setKeyValue($key, $value) {
 91:         self::_throwExceptionIfKeyNotExists($key);
 92: 
 93:         $SettedConfigurationKey = ClassRegistry::init('ConfigurationKeys.SettedConfigurationKey');
 94:         $settedConfigurationKey = $SettedConfigurationKey->findByName($key);
 95: 
 96:         if (empty($settedConfigurationKey)) {
 97:             $SettedConfigurationKey->create();
 98:             $settedConfigurationKey[$SettedConfigurationKey->alias]['name'] = $key;
 99:         }
100: 
101:         $settedConfigurationKey[$SettedConfigurationKey->alias]['value'] = $value;
102:         return $SettedConfigurationKey->save($settedConfigurationKey);
103:     }
104: 
105:     public static function clearKeyValue($key) {
106:         self::_throwExceptionIfKeyNotExists($key);
107: 
108:         $SettedConfigurationKey = ClassRegistry::init('ConfigurationKeys.SettedConfigurationKey');
109:         $settedConfigurationKey = $SettedConfigurationKey->findByName($key);
110: 
111:         if (!empty($settedConfigurationKey)) {
112:             $SettedConfigurationKey->delete($settedConfigurationKey[$SettedConfigurationKey->alias][$SettedConfigurationKey->primaryKey]);
113:         }
114:     }
115: 
116:     public static function hasKey($key) {
117:         return array_key_exists($key, self::_getKeys());
118:     }
119: 
120:     public static function getKeyOptions($key, $option = null) {
121:         self::_throwExceptionIfKeyNotExists($key);
122:         $options = self::$keys[$key];
123:         return $option ? $options[$option] : $option;
124:     }
125: 
126:     private static function _throwExceptionIfKeyNotExists($key) {
127:         if (!self::hasKey($key)) {
128:             throw new Exception(sprintf(__d('configuration_keys','Key not setted: %s (Keys setted: %s)'), $key, implode(',', self::getKeys())));
129:         }
130:     }
131: 
132: }
133: 
134: ?>
135: 
API documentation generated by ApiGen 2.8.0