Exemplo n.º 1
0
 /**
  * Returns options in an array
  * @return array
  */
 public static function getOptions()
 {
     if (static::$_options) {
         return static::$_options;
     }
     $defaults = array('base_url' => get_bloginfo('url'), 'image_name' => '%filename%', 'alt_name' => '%image_alt%');
     return static::$_options = wp_parse_args(get_option(self::WP_OPTIONS_KEY), $defaults);
 }
Exemplo n.º 2
0
 /**
  * Adds to or replaces built-in validation rules specified in `Validator::$_rules`.  Any new
  * validation rules created are automatically callable as validation methods.
  *
  * For example:
  * {{{
  * Validator::add('zeroToNine', '/^[0-9]$/');
  * $isValid = Validator::isZeroToNine("5"); // true
  * $isValid = Validator::isZeroToNine("20"); // false
  * }}}
  *
  * Alternatively, the first parameter may be an array of rules expressed as key/value pairs,
  * as in the following:
  * {{{
  * Validator::add(array(
  * 	'zeroToNine' => '/^[0-9]$/',
  * 	'tenToNineteen' => '/^1[0-9]$/',
  * ));
  * }}}
  *
  * In addition to regular expressions, validation rules can also be defined as full anonymous
  * functions:
  * {{{
  * use app\models\Account;
  *
  * Validator::add('accountActive', function($value) {
  * 	$value = is_int($value) ? Account::find($value) : $value;
  * 	return (boolean) $value->is_active;
  * });
  *
  * $testAccount = Account::create(array('is_active' => false));
  * Validator::isAccountActive($testAccount); // returns false
  * }}}
  *
  * These functions can take up to 3 parameters:
  * 	- `$value` _mixed_: This is the actual value to be validated (as in the above example).
  * 	- `$format` _string_: Often, validation rules come in multiple "formats", for example:
  * 	  postal codes, which vary by country or region. Defining multiple formats allows you to
  * 	  retian flexibility in how you validate data. In cases where a user's country of origin
  * 	  is known, the appropriate validation rule may be selected. In cases where it is not
  * 	  known, the value of `$format` may be `'any'`, which should pass if any format matches.
  * 	  In cases where validation rule formats are not mutually exclusive, the value may be
  * 	  `'all'`, in which case all must match.
  * 	- `$options` _array_: This parameter allows a validation rule to implement custom
  * 	  options.
  *
  * @see lithium\util\Validator::$_rules
  * @param mixed $name The name of the validation rule (string), or an array of key/value pairs
  *              of names and rules.
  * @param string $rule If $name is a string, this should be a string regular expression, or a
  *               closure that returns a boolean indicating success. Should be left blank if
  *               `$name` is an array.
  * @param array $options The default options for validating this rule. An option which applies
  *              to all regular expression rules is `'contains'` which, if set to true, allows
  *              validated values to simply _contain_ a match to a rule, rather than exactly
  *              matching it in whole.
  * @return void
  */
 public static function add($name, $rule = null, array $options = array())
 {
     if (!is_array($name)) {
         $name = array($name => $rule);
     }
     static::$_rules = Set::merge(static::$_rules, $name);
     if (!empty($options)) {
         $options = array_combine(array_keys($name), array_fill(0, count($name), $options));
         static::$_options = Set::merge(static::$_options, $options);
     }
 }
 /**
  * Loads the debug interface and/or the console class if requested. See @ref dbg_getting_started
  * @param 	array 		$options		array of options, see PtcDebug::$ _defaultOptions
  */
 public static function load($options = null)
 {
     $now = microtime(true);
     if (defined('_PTCDEBUG_NAMESPACE_')) {
         $err = array('errno' => static::_msgType(E_USER_NOTICE), 'errstr' => 'Debug already loaded!', 'errfile' => 'trace');
         static::_buildBuffer('log', '{errorHandler}', $err);
         return;
     }
     $called_class = get_called_class();
     /* if error handler was called previously */
     if (@isset(static::$_options['die_on_error'])) {
         static::$_defaultOptions['die_on_error'] = static::$_options['die_on_error'];
     }
     if (@isset(static::$_options['error_reporting'])) {
         static::$_defaultOptions['error_reporting'] = static::$_options['error_reporting'];
     }
     static::$_options = is_array($options) ? array_merge(static::$_defaultOptions, $options) : static::$_defaultOptions;
     if (!($has_access = static::_checkAccess())) {
         return;
     }
     // check access with ips
     $buffer = 'Debug Info:';
     if (static::$_options['check_referer']) {
         static::checkReferer();
     }
     // check if referer has debug vars
     if (static::$_options['session_start']) {
         if (session_id() === '') {
             session_start();
             $buffer .= '<br>Initialized browser session with session_start( )';
         } else {
             $buffer .= '<br>Session id is ' . session_id();
         }
     }
     if (!@$_SESSION) {
         $_SESSION = array();
     }
     if (!@$_SESSION['ptcdebug']) {
         $_SESSION['ptcdebug'] = array();
     }
     if (@$_GET[static::$_options['url_key']] == static::$_options['url_pass']) {
         $_SESSION['ptcdebug'][static::$_options['url_key']] = true;
         $_SESSION['ptcdebug']['code_highlighter'] = true;
         $_SESSION['ptcdebug']['search_files'] = true;
         //$buffer .= '<br>PtcDebug turned on!';
     } else {
         if (@$_GET[static::$_options['url_key'] . '_off'] == static::$_options['url_pass']) {
             $_SESSION['ptcdebug'][static::$_options['url_key']] = false;
             $_SESSION['ptcdebug']['code_highlighter'] = false;
             $_SESSION['ptcdebug']['search_files'] = false;
         }
     }
     if (static::_getSessionVars(static::$_options['url_key'])) {
         static::$_startTime = microtime(true);
         if (static::$_options['set_time_limit']) {
             set_time_limit(static::$_options['set_time_limit']);
         }
         if (static::$_options['memory_limit']) {
             ini_set('memory_limit', static::$_options['memory_limit']);
         }
         if (static::$_options['show_interface'] || static::$_options['debug_console']) {
             register_shutdown_function(array($called_class, 'processBuffer'));
         }
         if (static::$_options['replace_error_handler']) {
             static::setErrorHandler(static::$_options['die_on_error']);
             $buffer .= '<br>Error handler has been overridden!';
         }
         if (static::$_options['catch_exceptions']) {
             set_exception_handler(array($called_class, 'exceptionHandler'));
             $buffer .= "<br>Exception Handler turned on!";
         }
         if (static::$_options['debug_console']) {
             static::$_consoleStarted = false;
             $buffer .= '<br>Console debug turned on';
             if (file_exists(dirname(__FILE__) . '/PhpConsole/__autoload.php')) {
                 require_once dirname(__FILE__) . '/PhpConsole/__autoload.php';
                 static::$_consoleStarted = true;
                 \PhpConsole\Helper::register();
                 $buffer .= ", phpConsole class started!";
             } else {
                 $buffer .= ', but could not find phpConsole class!';
             }
         }
         if (static::$_options['enable_inspector'] || static::$_options['code_coverage'] || static::$_options['trace_functions']) {
             register_tick_function(array($called_class, 'tickHandler'));
             //if ( static::$_options[ 'declare_ticks' ] ) { declare( ticks = 1 ); }
             $buffer .= "<br>Variables inspector enabled!";
         }
         if (static::$_options['code_coverage'] === 'full') {
             static::startCoverage();
             $buffer .= "<br>Code coverage analysis for all scripts enabled!";
         }
         if (static::$_options['trace_functions'] === 'full') {
             static::startTrace();
             $buffer .= "<br>Function calls tracing for all scripts enabled!";
         }
         if (!static::_getSessionVars('show_messages')) {
             static::_setSessionVars();
         }
         if (@$_GET['hidepanels']) {
             static::_disablePanels();
         } else {
             static::$_options['show_messages'] = static::_getSessionVars('show_messages');
             static::$_options['show_globals'] = static::_getSessionVars('show_globals');
             static::$_options['show_sql'] = static::_getSessionVars('show_sql');
             static::$_options['show_w3c'] = static::_getSessionVars('show_w3c');
         }
         @define('_PTCDEBUG_NAMESPACE_', $called_class);
         static::$_tickTime = microtime(true) - $now + static::$_tickTime;
         static::bufferLog('', '<span>' . $buffer . '<span>', 'Debug Loader');
     }
 }
Exemplo n.º 4
0
 protected static function setOptions($options)
 {
     static::$_options = isset(self::$_options) ? array_merge(static::$_options, $options) : $options;
 }
Exemplo n.º 5
0
 /**
  * Deserialize
  */
 public static function __wakeup()
 {
     //	Load options from session...
     if (PHP_SESSION_DISABLED != session_status() && null !== ($_frozen = Option::get($_SESSION, CoreSettings::SESSION_KEY))) {
         //	Merge them into the fold
         $_data = Storage::defrost($_frozen);
         //	If this object wasn't stored by me, don't use it.
         if ($_data == $_frozen) {
             Log::debug('  - Retrieved data is not compressed or bogus. Removing. ');
             unset($_SESSION[CoreSettings::SESSION_KEY]);
             return;
         }
         static::$_options = Options::merge($_data, static::$_options);
     }
     static::$_awake = true;
 }