public function __construct() { $this->tool =& get_clips_tool(); $this->clips = $this->tool->clips; // Using a new environment to do the validation $this->clips->createEnv('VALIDATION'); }
public function __construct($argv) { $argv = explode(' ', $argv); $tool = get_clips_tool(); $command = 'shell'; if (count($argv) >= 2 && trim($argv[1])) { // We have the command $command = $argv[1]; } $tool->execute($command, $argv); }
public function __construct($name = '') { $this->tool =& get_clips_tool(); context('app', $this); context('app_name', $name); context('smarty', $this->tool->create('Smarty')); set_error_handler("Clips\\web_error_handler"); $this->name = $name; $this->router = $this->tool->load_class('Router', true); $this->router->route(); }
public function getCascadeOptions($value = null) { if (isset($this->cascade_model)) { $tool = get_clips_tool(); $model = $tool->model($this->cascade_model); if ($model) { // We do have a cascade model $cascade_field = get_default($this, 'cascade_field', null); if ($cascade_field) { if ($value) { $cascade_data = $value; } else { $cascade_data = get_default(context('current_form_data'), $cascade_field); } $cascade_method = get_default($this, 'cascasde_method', 'list' . ucfirst($this->field)); return $model->{$cascade_method}($cascade_data); } } } return null; }
public function __construct($uri) { if (strpos($uri, '://') === false) { throw new Exception('The resource of uri ' . $uri . ' is not valid!'); } $this->uri = $uri; if (strpos($uri, "string://") === false) { $info = parse_url($uri); $proto = $info['scheme']; $clips_class = "Clips\\ResourceHandlers\\" . ucfirst($proto) . "ResourceHandler"; if (class_exists($clips_class)) { $handler = new $clips_class(); } else { // Using the configuration to load the handlers foreach (clips_config("resource_handlers") as $c) { if (isset($c->{$proto})) { $class = $c->{$proto}; if (class_exists($class)) { $handler = new $class(); } } } // We really can't find the handler, let's doing a load. if (!isset($handler)) { $tool =& get_clips_tool(); $handler = $tool->load_class(ucfirst($info['scheme']), true, new LoadConfig($tool->config->resource_handler_dir, "ResourceHandler", "ResourceHandlers\\")); } } } else { $handler = new ResourceHandlers\StringResourceHandler(); } if (!$handler) { throw new Exception('No handler found for resource of uri ' . $uri . ' !'); } $this->handler = $handler; }
function current_env() { $tool =& get_clips_tool(); return $tool->clips->current_env; }
public function __construct() { $this->tool =& get_clips_tool(); }
public function update($params) { $tool =& get_clips_tool(); $tool->library('sql'); $this->offset = $params['start']; $this->length = $params['length']; if (isset($params['search']) && isset($params['search']['value'])) { if (isset($params['search']['value']) && trim($params['search']['value'])) { $or = array(); $or_value = $params['search']['value']; } } foreach ($this->columns() as $col) { $field_type = get_default($col, 'field_type'); if ($field_type != 'datetime' && get_default($col, 'searchable', true)) { if (isset($or)) { $or[$col->data] = $or_value; } } } // Update the where configuration using request columns $i = 0; foreach ($params['columns'] as $col) { if (isset($col['search'])) { $search = $col['search']; if (isset($search['value']) && $search['value']) { $field = $this->columns[$i]; if (isset($field->refer)) { $f = $field->refer; } else { $f = $field->data; } if ($search['regex'] && $search['regex'] != 'false') { $this->where[] = Libraries\_like($f, $search['value']); } else { $this->where[$f] = $search['value']; } } } $i++; } if (isset($or)) { $this->where[] = Libraries\_or($or); } $order = $params['order']; $arr = array(); if ($order) { foreach ($order as $o) { $col = $params['columns'][$o['column']]['data']; $arr[] = $col . ' ' . $o['dir']; } } if (isset($this->orderBy)) { $arr = array_merge($arr, $this->orderBy); } $this->orderBy = $arr; }
public function setUp() { $mute = getenv('MUTE_PHPUNIT'); $ref = new \ReflectionClass($this); $func = $this->getName(); if (!$mute && $func != 'testStub') { echo "\n----------" . $ref->name . " | " . $func . "----------\n"; } $this->tool =& get_clips_tool(); $this->tool->helper('fake'); $this->clips = new Engine(); $re = new \Addendum\ReflectionAnnotatedClass($this); foreach (array($re, $re->getMethod($func)) as $m) { foreach ($m->getAnnotations() as $a) { switch (get_class($a)) { case "Clips\\Rules": // We need to load the rules before test execution $this->clips->clear(); // We should clear the clips every time $rules = get_default($a, 'rules', array()); $templates = get_default($a, 'templates', array()); // Load the templates foreach ($templates as $t) { $this->clips->template($t); } // Load the rules foreach ($rules as $r) { $this->clips->load($r); } break; case "Clips\\FakeModel": $ds = $this->tool->library('dataSource'); $fake = $this->tool->library('fakeDataSource'); $ds->fake = $fake; if (valid_obj($this, 'Clips\\Interfaces\\FakeDataSourceHandler')) { $fake->handler = $this; } else { if (!$a->value) { $a->value = 'expectFakeDataSourceHandler'; } $fake->handler = $this->tool->library($a->value); $this->fake_handler = $fake->handler; } $ds->_datasources = array('fake'); break; case "Clips\\TestData": case "Clips\\DataGenerator": $this->data = $this->tool->enhance($a); break; case "Clips\\TestValue": if (isset($a->json)) { $a->file = $a->json; } if (isset($a->file)) { $test_config_dir = clips_config('test_data_dir'); if (!$test_config_dir) { $test_config_dir = clips_config('test_dir'); $test_config_dir = path_join($test_config_dir[0], 'data'); } else { $test_config_dir = $test_config_dir[0]; } $p = path_join($test_config_dir, $a->file); if (\file_exists($p)) { $this->value = \file_get_contents($p); if (isset($a->json)) { $this->value = parse_json($this->value); } } } else { if (isset($a->context)) { $this->value = clips_context($a->context); } else { if (isset($a->value)) { $this->value = $a->value; } } } break; default: $this->tool->annotationEnhance($a, $this); } } } $this->doSetUp(); }
function image_size($p) { if (file_exists($p)) { $tool =& get_clips_tool(); $util = $tool->library('ImageUtils'); return $util->size($p); } return false; }
public static function get($name, $args = null) { $tool =& get_clips_tool(); return $tool->library($name, true, 'Formatter', $args); }
/** * The interactive wizzard function, will take the options to run. * * The options is something like this(the generate widget option): * * <code> * { * "header": "Clips Widget Generator v1.0", * "steps": [ * { * "prompt": "The name of the widget:", * "field": "widget", * "rules": { * "minlength": 4, * "maxlength": 10 * } * }, * { * "prompt": "Widget Author:", * "field": "author", * "default": "!Clips\\current_user" * }, * { * "prompt": "Widget Version:", * "default": "1.0", * "field": "version" * }, * { * "prompt": "Widget Doc:", * "field": "doc" * }, * { * "prompt": "The widget configuration is:", * "call": "dump" * }, * { * "prompt": "Are you sure:", * "confirm": true, * "condition": { * "cancel": [{"jump": 0}] * } * } * ] * } * </code> * * Concept in details: * * 1. Step: The interactive step, can be 2 types [step, confirm] * 2. Operation: Only support 2 kind of operations by this version call and jump, for call * operation, will call the method from callback, for jump operation, will jump to the step * it set, like this {"jump":0} * 3. Confirm Step: This step will prompt a question to user, and let the user to choose, * use the condition part to add operation to the interactive console * 4. Field: If step has this settings, will prompt to get the user input using readline, and set * the input as field of the return object. * 5. Default: If no input is there, use this as default value, support method call, like this !time, * do not support arguments for this version */ function interactive($config, $callback = null) { if (is_string($config)) { // This is the config location $conf_dir = clips_config('config_dir'); foreach ($conf_dir as $dir) { $p = try_path(path_join($dir, $config . '.json')); if ($p) { break; } } $config = parse_json(file_get_contents($p)); } $prompt = get_default($config, 'prompt', '$'); if (isset($config->header)) { echo $config->header . "\n"; } $tool =& get_clips_tool(); $ret = array(); $validator = new Validator(); for ($i = 0; $i < count($config->steps); $i++) { $step = $config->steps[$i]; $operations = array(); $default = null; if (isset($step->field)) { if (isset($step->default)) { $default = $step->default; if (strpos($default, '!') === 0) { $default = call_user_func('\\' . str_replace('!', '', $default)); } } if (isset($step->prompt)) { $field = readline($step->prompt . (isset($default) ? ' (' . $default . ') ' : ' ')); } else { $field = readline($prompt . isset($default) ? ' (' . $default . ') ' : ' '); } if (!$field) { if (isset($default)) { $field = $default; } } if (isset($step->rules)) { // TODO Add the validation } $ret[$step->field] = $field; } else { if (isset($step->confirm)) { // This is the confirm step if (isset($step->confirm->options)) { $options = $step->confirm->options; } else { $options = array('yes', 'no'); } if (isset($step->prompt)) { $confirm = readline($step->prompt . ' [' . implode(', ', $options) . ']' . ' '); } else { $confirm = readline($prompt . ' '); } if (!is_array($step->confirm)) { $result_array = array('', 'y', 'Y', 'yes', 'Yes'); } else { $result_array = $step->confirm; } if (array_search($confirm, $result_array) !== false) { $condition = 'confirm'; } else { $condition = 'cancel'; } if (isset($step->condition)) { if (isset($step->condition->{$condition})) { $operations = array_merge($operations, $step->condition->{$condition}); } } } else { echo $step->prompt . "\n"; // Just print the prompt } } if (isset($step->jump)) { $operations[] = (object) array('jump' => $step->jump); } if (isset($step->call)) { $operations[] = (object) array('call' => $step->call); } if ($operations) { foreach ($operations as $operation) { if (isset($operation->jump)) { $i = $operation->jump - 1; } if ($callback && isset($operation->call)) { \call_user_func_array(array($callback, $operation->call), array($ret)); } } } } return (object) $ret; }