Example #1
0
 /**
  * replaceLinks
  * EditPage::attemptSave hook function
  * replaces links to Census pages with template
  */
 public static function replaceLinks($editpage)
 {
     wfProfileIn(__METHOD__);
     $cas = new self();
     $cas->execute($editpage->textbox1);
     wfProfileOut(__METHOD__);
     return true;
 }
Example #2
0
 /**
  * @param string $schema A schema file to load from the configured schema path
  * @param array $input
  *
  * @return array|bool|Result
  * @throws InvalidConstraintException
  * @throws InvalidInputException
  * @throws ValidationException
  *
  */
 public static function validate($schema, array $input)
 {
     $instance = new self($input, self::getSchema($schema));
     if ($instance->execute()) {
         return new Result($instance->getCleanedData(), $instance->getViolations());
     } else {
         throw new InvalidInputException($instance->getViolations());
     }
 }
Example #3
0
 /**
  * Creates a transaction and optionally execute a transaction
  * @return Transaction
  */
 public static function create($closure, $execute = true)
 {
     $transaction = new self();
     $transaction->callback($closure);
     if ($execute) {
         $transaction->execute();
     }
     return $transaction;
 }
Example #4
0
 public static function do_get($url, $parameters = null, $headers = null)
 {
     $client = new self($url);
     $client->parameters = $parameters ? $parameters : array();
     $client->headers = $headers ? $headers : array();
     try {
         $response = $client->execute();
     } catch (Exception $e) {
         throw new Exception('Could not fetch: ' . $url . ':' . $e);
     }
     return $response;
 }
Example #5
0
 public static function read($file, array $options = [])
 {
     $reader = new self($file, $options);
     $reader->execute();
     $requirements = [];
     foreach ($reader->requirements as $type => $reqsOfType) {
         foreach ($reqsOfType as $name => $unused) {
             $requirements[] = ['type' => $type, 'name' => $name];
         }
     }
     return ['requirements' => $requirements, 'tests' => $reader->tests, 'articles' => $reader->articles];
 }
Example #6
0
 public static function createAndExec($_type, $_cmd, $_options)
 {
     $scenarioExpression = new self();
     $scenarioExpression->setType($_type);
     $scenarioExpression->setExpression($_cmd);
     if (is_array($_options)) {
         foreach ($_options as $key => $value) {
             $scenarioExpression->setOptions($key, $value);
         }
     }
     return $scenarioExpression->execute();
 }
Example #7
0
File: db.php Project: dapepe/tymio
 public static function exec($table, $where = '', $conn = null)
 {
     $db = new self($conn);
     $db->table = $table;
     $db->where = $where;
     $db->execute();
 }
Example #8
0
 /**
  * [render description]
  * @param  [type]  $__content [description]
  * @param  array   $__params  [description]
  * @param  boolean $__sandbox [description]
  * @return [type]             [description]
  */
 public static function render($content, $params = array(), $sandbox = false, $srcinfo = null)
 {
     $obj = new self();
     return $obj->execute($content, $params, $sandbox, $srcinfo);
 }
 /**
  * Read a ZIP file and call a function for each file discovered in it.
  *
  * Because this class is aimed at verification, an error is raised on
  * suspicious or ambiguous input, instead of emulating some standard
  * behaviour.
  *
  * @param $fileName string The archive file name
  * @param $callback Array The callback function. It will be called for each file
  *   with a single associative array each time, with members:
  *
  *      - name: The file name. Directories conventionally have a trailing
  *        slash.
  *
  *      - mtime: The file modification time, in MediaWiki 14-char format
  *
  *      - size: The uncompressed file size
  *
  * @param $options Array An associative array of read options, with the option
  *    name in the key. This may currently contain:
  *
  *      - zip64: If this is set to true, then we will emulate a
  *        library with ZIP64 support, like OpenJDK 7. If it is set to
  *        false, then we will emulate a library with no knowledge of
  *        ZIP64.
  *
  *        NOTE: The ZIP64 code is untested and probably doesn't work. It
  *        turned out to be easier to just reject ZIP64 archive uploads,
  *        since they are likely to be very rare. Confirming safety of a
  *        ZIP64 file is fairly complex. What do you do with a file that is
  *        ambiguous and broken when read with a non-ZIP64 reader, but valid
  *        when read with a ZIP64 reader? This situation is normal for a
  *        valid ZIP64 file, and working out what non-ZIP64 readers will make
  *        of such a file is not trivial.
  *
  * @return Status object. The following fatal errors are defined:
  *
  *      - zip-file-open-error: The file could not be opened.
  *
  *      - zip-wrong-format: The file does not appear to be a ZIP file.
  *
  *      - zip-bad: There was something wrong or ambiguous about the file
  *        data.
  *
  *      - zip-unsupported: The ZIP file uses features which
  *        ZipDirectoryReader does not support.
  *
  * The default messages for those fatal errors are written in a way that
  * makes sense for upload verification.
  *
  * If a fatal error is returned, more information about the error will be
  * available in the debug log.
  *
  * Note that the callback function may be called any number of times before
  * a fatal error is returned. If this occurs, the data sent to the callback
  * function should be discarded.
  */
 public static function read($fileName, $callback, $options = array())
 {
     $zdr = new self($fileName, $callback, $options);
     return $zdr->execute();
 }
Example #10
0
 /**
  * Execute the chain
  */
 public function execute()
 {
     for ($i = 0; $i < count($this->rules); $i++) {
         $this->rules[$i]->execute();
         echo "LinkType: " . $this->rules[$i]->linkType . "\n";
         switch ($this->rules[$i]->linkType) {
             case "NONE":
                 break;
             case "LOOP":
                 // Find the matching endloop, extract the subarray as a new chain and loop
                 // execution for each row
                 echo "DETECTED LOOP\n";
                 if (count($this->rules) - ($i + 1) > 0) {
                     //                    if(((count($this->rules)-1)-$i) > 0) {
                     $endindex = $this->getEndLoopIndex($i + 1);
                     echo "LOOP START\n";
                     echo $i . ": LOOP RULE Index\n";
                     $loopcount = 0;
                     $loopchain = NULL;
                     while ($row = $this->rules[$i]->getNextResultRow()) {
                         echo $i + 1 . ": INNER RULE Index\n";
                         echo $endindex . ": Endindex\n";
                         $loopcount++;
                         echo "INNER RULE ITERATION COUNTER: " . $loopcount . "\n";
                         echo "Offset: " . ($i + 1) . "\n";
                         echo "Length: " . ($endindex - $i) . "\n";
                         $loopchain = new self(null, \array_slice($this->rules, $i + 1, $endindex - $i), $row, FALSE);
                         $loopchain->execute();
                         echo "CURRENT LOOP RULE\n";
                         if (in_array($this->rules[$endindex]->resultType, ['ROW', 'RECORDSET'])) {
                             $this->rules[$endindex]->setOutput($loopchain->getChainResult());
                         }
                     }
                     echo "LOOP END\n";
                     $i = $endindex + 1;
                     echo $i . ": Current Index\n";
                 }
                 break;
             case "ENDLOOP":
                 break;
             case "NEXT":
                 if (count($this->rules) - $i > 1) {
                     $this->rules[$i + 1]->input = clone $this->rules[$i]->input;
                 }
                 break;
             default:
                 // do nothing
                 break;
         }
     }
 }
 /**
  * @see     sfCombineMinifierInterface::minify
  * @param   string  $content
  * @param   array   $options
  * @return  string
  */
 public static function minify($content, array $options = array())
 {
     $obj = new self($content, $options);
     return $obj->execute();
 }
Example #12
0
 /**
  * 启动控制器
  *
  * @param string $uri 路径
  *
  * @return Controller
  */
 public static function run($uri)
 {
     $c = new self($uri);
     $c->cutURI();
     $c->dispatch();
     try {
         $c->execute();
     } catch (\Exception $e) {
         Error::exceptionHandler($e);
     } finally {
         if ($c->outputAllow) {
             Responder::write();
         }
     }
     return $c;
 }
 /**
  * Hook account creation
  *
  * @param User $user User that was created
  * @return bool
  */
 public static function hook($user)
 {
     $notifier = new self();
     $notifier->execute($user);
     return true;
 }
Example #14
0
 function execute()
 {
     global $osC_Cache;
     if (isset($this->cache_key)) {
         if ($osC_Cache->read($this->cache_key, $this->cache_expire)) {
             $this->cache_data = $osC_Cache->getCache();
             $this->cache_read = true;
         }
     }
     if ($this->cache_read === false) {
         if ($this->db_class->use_foreign_keys == false) {
             $query_action = substr($this->sql_query, 0, strpos($this->sql_query, ' '));
             if ($query_action == 'delete' || $query_action == 'update') {
                 if (empty($this->db_class->fkeys)) {
                     $Qfk = new self($this->db_class);
                     $Qfk->setQuery('select * from :table_fk_relationships');
                     $Qfk->bindTable(':table_fk_relationships', TABLE_FK_RELATIONSHIPS);
                     //              $Qfk->setCache('fk_relationships');
                     $Qfk->execute();
                     while ($Qfk->next()) {
                         $this->db_class->fkeys[$Qfk->value('to_table')][] = array('from_table' => $Qfk->value('from_table'), 'from_field' => $Qfk->value('from_field'), 'to_field' => $Qfk->value('to_field'), 'on_update' => $Qfk->value('on_update'), 'on_delete' => $Qfk->value('on_delete'));
                     }
                     $Qfk->freeResult();
                 }
             }
             if ($query_action == 'delete') {
                 $query_data = split(' ', $this->sql_query, 4);
                 $query_table = substr($query_data[2], strlen(DB_TABLE_PREFIX));
                 if (isset($this->db_class->fkeys[$query_table])) {
                     // check for RESTRICT constraints first
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         if ($fk['on_delete'] == 'restrict') {
                             $child_query = $this->db_class->simpleQuery('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                             while ($child_result = $this->db_class->next($child_query)) {
                                 $Qcheck = new self($this->db_class);
                                 $Qcheck->setQuery('select ' . $fk['from_field'] . ' from ' . DB_TABLE_PREFIX . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $child_result[$fk['to_field']] . '" limit 1');
                                 $Qcheck->execute();
                                 if ($Qcheck->numberOfRows() === 1) {
                                     $this->db_class->setError('RESTRICT constraint condition from table ' . DB_TABLE_PREFIX . $fk['from_table'], null, $this->sql_query);
                                     return false;
                                 }
                             }
                         }
                     }
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         $parent_query = $this->db_class->simpleQuery('select * from ' . $query_data[2] . ' ' . $query_data[3]);
                         while ($parent_result = $this->db_class->next($parent_query)) {
                             if ($fk['on_delete'] == 'cascade') {
                                 $Qdel = new self($this->db_class);
                                 $Qdel->setQuery('delete from :from_table where :from_field = :' . $fk['from_field']);
                                 $Qdel->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                 $Qdel->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qdel->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']]);
                                 if ($this->logging === true) {
                                     if ($this->db_class->logging_transaction === false) {
                                         $this->db_class->logging_transaction = true;
                                     }
                                     $Qdel->setLogging($this->logging_module, $this->logging_module_id);
                                 }
                                 $Qdel->execute();
                             } elseif ($fk['on_delete'] == 'set_null') {
                                 $Qupdate = new self($this->db_class);
                                 $Qupdate->setQuery('update :from_table set :from_field = :' . $fk['from_field'] . ' where :from_field = :' . $fk['from_field']);
                                 $Qupdate->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                 $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qupdate->bindRaw(':' . $fk['from_field'], 'null');
                                 $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qupdate->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']], false);
                                 if ($this->logging === true) {
                                     if ($this->db_class->logging_transaction === false) {
                                         $this->db_class->logging_transaction = true;
                                     }
                                     $Qupdate->setLogging($this->logging_module, $this->logging_module_id);
                                 }
                                 $Qupdate->execute();
                             }
                         }
                     }
                 }
             } elseif ($query_action == 'update') {
                 $query_data = split(' ', $this->sql_query, 3);
                 $query_table = substr($query_data[1], strlen(DB_TABLE_PREFIX));
                 if (isset($this->db_class->fkeys[$query_table])) {
                     // check for RESTRICT constraints first
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         if ($fk['on_update'] == 'restrict') {
                             $child_query = $this->db_class->simpleQuery('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                             while ($child_result = $this->db_class->next($child_query)) {
                                 $Qcheck = new self($this->db_class);
                                 $Qcheck->setQuery('select ' . $fk['from_field'] . ' from ' . DB_TABLE_PREFIX . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $child_result[$fk['to_field']] . '" limit 1');
                                 $Qcheck->execute();
                                 if ($Qcheck->numberOfRows() === 1) {
                                     $this->db_class->setError('RESTRICT constraint condition from table ' . DB_TABLE_PREFIX . $fk['from_table'], null, $this->sql_query);
                                     return false;
                                 }
                             }
                         }
                     }
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         // check to see if foreign key column value is being changed
                         if (strpos(substr($this->sql_query, strpos($this->sql_query, ' set ') + 4, strpos($this->sql_query, ' where ') - strpos($this->sql_query, ' set ') - 4), ' ' . $fk['to_field'] . ' ') !== false) {
                             $parent_query = $this->db_class->simpleQuery('select * from ' . $query_data[1] . substr($this->sql_query, strrpos($this->sql_query, ' where ')));
                             while ($parent_result = $this->db_class->next($parent_query)) {
                                 if ($fk['on_update'] == 'cascade' || $fk['on_update'] == 'set_null') {
                                     $on_update_value = '';
                                     if ($fk['on_update'] == 'cascade') {
                                         $on_update_value = $this->logging_fields[$fk['to_field']];
                                     }
                                     $Qupdate = new self($this->db_class);
                                     $Qupdate->setQuery('update :from_table set :from_field = :' . $fk['from_field'] . ' where :from_field = :' . $fk['from_field']);
                                     $Qupdate->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                     $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                     if (empty($on_update_value)) {
                                         $Qupdate->bindRaw(':' . $fk['from_field'], 'null');
                                     } else {
                                         $Qupdate->bindValue(':' . $fk['from_field'], $on_update_value);
                                     }
                                     $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                     $Qupdate->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']], false);
                                     if ($this->logging === true) {
                                         if ($this->db_class->logging_transaction === false) {
                                             $this->db_class->logging_transaction = true;
                                         }
                                         $Qupdate->setLogging($this->logging_module, $this->logging_module_id);
                                     }
                                     $Qupdate->execute();
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($this->logging === true) {
             $this->logging_action = substr($this->sql_query, 0, strpos($this->sql_query, ' '));
             if ($this->logging_action == 'update') {
                 $db = split(' ', $this->sql_query, 3);
                 $this->logging_database = $db[1];
                 $test = $this->db_class->simpleQuery('select ' . implode(', ', array_keys($this->logging_fields)) . ' from ' . $this->logging_database . substr($this->sql_query, strrpos($this->sql_query, ' where ')));
                 while ($result = $this->db_class->next($test)) {
                     foreach ($this->logging_fields as $key => $value) {
                         if ($result[$key] != $value) {
                             $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $result[$key], 'new' => $value);
                         }
                     }
                 }
             } elseif ($this->logging_action == 'insert') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 foreach ($this->logging_fields as $key => $value) {
                     $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => '', 'new' => $value);
                 }
             } elseif ($this->logging_action == 'delete') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 $del = $this->db_class->simpleQuery('select * from ' . $this->logging_database . ' ' . $db[3]);
                 while ($result = $this->db_class->next($del)) {
                     foreach ($result as $key => $value) {
                         $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $value, 'new' => '');
                     }
                 }
             }
         }
         $this->query_handler = $this->db_class->simpleQuery($this->sql_query, $this->debug);
         if ($this->logging === true) {
             if ($this->db_class->logging_transaction_action === false) {
                 $this->db_class->logging_transaction_action = $this->logging_action;
             }
             if ($this->affectedRows($this->query_handler) > 0) {
                 if (!empty($this->logging_changed)) {
                     if ($this->logging_action == 'insert' && !is_numeric($this->logging_module_id)) {
                         $this->logging_module_id = $this->db_class->nextID();
                         $this->setNextID($this->logging_module_id);
                     }
                     if (class_exists('osC_AdministratorsLog_Admin')) {
                         osC_AdministratorsLog_Admin::insert($this->logging_module, $this->db_class->logging_transaction_action, $this->logging_module_id, $this->logging_action, $this->logging_changed, $this->db_class->logging_transaction);
                     }
                 }
             }
         }
         if ($this->batch_query === true) {
             $this->batch_size = $this->db_class->getBatchSize($this->sql_query, $this->batch_select_field);
             $this->batch_to = $this->batch_rows * $this->batch_number;
             if ($this->batch_to > $this->batch_size) {
                 $this->batch_to = $this->batch_size;
             }
             $this->batch_from = $this->batch_rows * ($this->batch_number - 1);
             if ($this->batch_to == 0) {
                 $this->batch_from = 0;
             } else {
                 $this->batch_from++;
             }
         }
         return $this->query_handler;
     }
 }
Example #15
0
 /**
  * Make lists from lines starting with ':', '*', '#', etc.
  *
  * @param string $text
  * @param bool $lineStart Whether or not this is at the start of a line.
  * @return string The lists rendered as HTML
  */
 public static function doBlockLevels($text, $lineStart)
 {
     $pass = new self($text, $lineStart);
     return $pass->execute();
 }
Example #16
0
 /**
  * 	method:	test
  *
  * 	todo: write documentation
  */
 public static function test($value, $type, $required = false, $options = array())
 {
     $v = new self(array("test" => $value));
     $v->add("test", $type, $required, $options);
     $r = array();
     $r["status"] = $v->execute();
     if ($r["status"]) {
         $d = $v->getValidData();
         $r["value"] = $d["test"];
     } else {
         $e = $v->getErrors();
         $r["error"] = $e["test"]["code"];
         $r["error_value"] = $e["test"]["value"];
     }
     if (!isset($r["value"]) && isset($options["default_value"])) {
         $r["value"] = $options["default_value"];
     }
     return $r && isset($r["value"]) && isset($options["return_value"]) ? $r["value"] : $r;
 }
Example #17
0
 protected function getRandomId(dmDoctrineTable $table)
 {
     $id = $table->createQuery('t')->select('t.id, RANDOM() AS rand')->orderBy('rand')->limit(1)->fetchValue();
     if (!$id) {
         $recordLoremizer = new self($this->getOptions());
         $id = $recordLoremizer->execute($table->create())->saveGet()->get('id');
     }
     return $id;
 }
Example #18
0
 /**
  * Magic method to look for direct request methods statically
  * e.g. Router::get('/my-uri', function () {}); , Router::post('/my-uri', function () {});
  * Not truly static...tad hacky. May need to be rethought and built statically.. hmm
  */
 public static function __callStatic($call, $args)
 {
     $call = strtoupper($call);
     $self = new self();
     if (in_array($call, $self->request_types) && $_SERVER['REQUEST_METHOD'] == $call) {
         $self->request($args[0], $args[1]);
         $self->execute(1);
     }
 }
 public static function create($attrs)
 {
     $obj = new self(SLN_Plugin::getInstance(), $attrs);
     return $obj->execute();
 }
 static function format($text)
 {
     $obj = new self($text);
     return $obj->execute();
 }