Exemple #1
0
 static function value($var)
 {
     $cookie = array_key_exists($var, $_COOKIE) ? $_COOKIE[$var] : NULL;
     $get = array_key_exists($var, $_GET) ? $_GET[$var] : NULL;
     $post = array_key_exists($var, $_POST) ? $_POST[$var] : NULL;
     return DevValue::isNotNull($cookie) ? $cookie : (DevValue::isNotNull($post) ? $post : $get);
 }
Exemple #2
0
 public function parent($object = null)
 {
     if (DevValue::isNotNull($object)) {
         $this->_parent = $object;
     }
     return $this->_parent;
 }
Exemple #3
0
 public function query($query = null)
 {
     $curl = $this->_connection;
     $method = strtolower($this->config('method'));
     if ($curl) {
         if (DevValue::isNotNull($query)) {
             if (DevArray::isAssoc($query)) {
                 //$this->_data = $query;
                 $this->assign($query);
             }
         }
         $data = $this->_data;
         //set the url, number of POST vars, POST data
         if ($method == 'post') {
             curl_setopt($curl, CURLOPT_POST, count($data));
             curl_setopt($curl, CURLOPT_POSTFIELDS, HTTP::query($data));
         } elseif ($method == 'get') {
             curl_setopt($curl, CURLOPT_URL, $this->config('target') . '/' . HTTP::query($data));
         }
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         //execute post
         $this->_result = curl_exec($curl);
         $status = $this->_result ? self::STATUS_SUCCESS : self::STATUS_FAILED;
     } else {
         $status = self::STATUS_NOTCONNECTED;
     }
     $this->status($status);
 }
Exemple #4
0
 public function query($query = null)
 {
     $status = self::STATUS_NOTCONNECTED;
     $context = $this->_connection;
     $wrapper = $this->config('wrapper');
     if ($context) {
         if (DevValue::isNotNull($query)) {
             if (DevArray::isAssoc($query)) {
                 $this->_data = $query;
             } else {
                 if (is_string($query)) {
                     $data = urlencode($query);
                     stream_context_set_option($context, $wrapper, 'content', $data);
                     $this->_result = file_get_contents($target, false, $context);
                     $this->status($this->_result !== false ? self::STATUS_SUCCESS : self::STATUS_FAILED);
                     return true;
                 }
             }
         }
         $data = HTTP::query($this->_data);
         stream_context_set_option($context, $wrapper, 'content', $data);
         $this->_result = file_get_contents($target, false, $context);
         if ($this->_result !== false) {
             $status = self::STATUS_SUCCESS;
         }
     }
     $this->status($status);
 }
Exemple #5
0
 public function query($query = null)
 {
     $db = $this->_connection;
     if ($db) {
         if (DevValue::isNotNull($query)) {
             $this->_query = $query;
             if (DevArray::isAssoc($query)) {
                 $this->_data = $query;
             } else {
                 if (is_string($query)) {
                     $this->_result = $db->query($query);
                     $this->status($db->error ? $db->error : self::STATUS_SUCCESS);
                     return true;
                 }
             }
         }
         $table = $this->config('table');
         $where = '';
         $update = false;
         $key = self::sanitize($this->config('key'));
         if ($this->field($key)) {
             $value = self::sanitize($this->field($key));
             $where = $key ? "`{$key}` = {$value}" : '';
             $update = true;
         }
         $data = $this->_data;
         $type = $update ? $this->config('ignore_null') ? self::UPDATE_SPECIFIED : self::UPDATE : self::INSERT;
         return $this->post($table, $data, $where, $type);
     } else {
         $this->status(self::STATUS_NOTCONNECTED);
         return false;
     }
 }
Exemple #6
0
 public function content($content = null)
 {
     if (DevValue::isNotNull($content)) {
         $content = DevArray::toArray($content);
         $this->_content = $content;
     }
     return $this->_content;
 }
 public function field($field, $value = null)
 {
     if ($this->is(State::READONLY)) {
         $value = null;
     }
     if (DevValue::isNotNull($value)) {
         $this->dispatch(Event::CHANGE);
     }
     return parent::field($field, $value);
 }
Exemple #8
0
 public function __construct($file = null)
 {
     parent::__construct();
     $this->_parser = \xml_parser_create();
     \xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, true);
     \xml_set_object($this->_parser, $this);
     \xml_set_element_handler($this->_parser, array($this, 'startHandler'), array($this, 'endHandler'));
     \xml_set_character_data_handler($this->_parser, array($this, 'dataHandler'));
     if (DevValue::isNotNull($file)) {
         $this->file($file);
         $this->parseXML($file);
     }
 }
Exemple #9
0
 public function query($query = null)
 {
     //
     $db = $this->_connection;
     if ($db) {
         if (DevValue::isNotNull($query)) {
             $this->_query = $query;
             if (DevArray::isAssoc($query)) {
                 $this->_dataset = null;
                 $this->_data = $query;
             } else {
                 if (is_array($query) && !DevArray::isAssoc($query)) {
                     $this->_dataset = $query;
                     $this->_data = $query[0];
                 } else {
                     if (is_string($query)) {
                         $this->_result = $db->command(json_decode($query));
                         $this->status($this->error() ? $this->error() : self::STATUS_SUCCESS);
                         return true;
                     }
                 }
             }
         }
         $collection = $this->config('collection');
         $filter = null;
         $update = false;
         $key = self::sanitize($this->config('key'));
         if ($this->field($key)) {
             $value = self::sanitize($this->field($key));
             $filter = $key ? array($key => $value) : '';
             $update = true;
         }
         $data = $this->_dataset ? $this->_dataset : $this->_data;
         $type = $update ? $this->config('replace') ? self::REPLACE : self::UPDATE : self::INSERT;
         $result = false;
         try {
             $result = $this->post($collection, $data, $filter, $type);
         } catch (Exception $e) {
             $error = $e->getMessage();
             $this->status($error);
         }
         return $result;
     } else {
         $this->status(self::STATUS_NOTCONNECTED);
         return false;
     }
 }
Exemple #10
0
 public function __construct($data = null)
 {
     parent::__construct();
     if (DevValue::isNotNull($data)) {
         if (is_array($data)) {
             $this->config($data);
         } elseif ($this->stringIsDate($data)) {
             $this->date($data);
         } elseif (is_int($data)) {
             $data = $this->timestamp($data);
             $this->_data = $this->info($data);
         } else {
             $data = $this->timestamp(strtotime($data));
             $this->_data = $this->info($data);
         }
     } else {
         $this->date(date($this->config('date_format')));
     }
 }
Exemple #11
0
 static function href($href = null, $secure = false, $doc = true)
 {
     if (DevValue::isNotNull($href)) {
         $href = '';
         if ($doc === false) {
             $href .= $_SERVER['DOCUMENT_ROOT'];
         } else {
             $protocol = $secure ? 'https' : 'http';
             $href = $protocol . '://' . $_SERVER['SERVER_NAME'];
             $href .= $_SERVER['REQUEST_URI'];
             if (DevString::strrpos($href, self::PAGE_EXTENSION)) {
                 $href = substr($href, 0, DevString::strrpos($href, self::PAGE_EXTENSION) + strlen(PAGE_EXTENSION));
             } elseif (DevString::strrpos($href, '/')) {
                 $href = substr($href, 0, DevString::strrpos($href, '/') + strlen('/'));
             }
         }
     }
     return $href;
 }
 private function message($recipientName, $behavior, $arguments = null, $callback = null)
 {
     if ($this->name() == $recipientName) {
         $recipient = $this;
         $behavior->_context = $arguments;
     } else {
         $recipient = $this->_services[$recipientName];
     }
     if (DevValue::isNotNull($callback) && \is_string($callback)) {
         $behavior = new Behavior($callback);
     }
     if ($recipient instanceof Application) {
         $recipient->execute($behavior, $arguments);
     } elseif ($recipient instanceof Service) {
         // echo "yo, I'm ".$recipient->name()." doing $behavior\n";
         $recipient->message($behavior, $arguments);
     } elseif ($recipient instanceof Scheme) {
         $recipient->perform($behavior, $arguments);
     } elseif ($recipient instanceof Dispatcher) {
         $recipient->dispatch($behavior, $arguments);
     } else {
         // var_dump($recipientName);
         call_user_func_array(array($recipient, $behavior->name()), array($arguments));
     }
 }
Exemple #13
0
 public function copy($dest, $original = null, $remove_orig = false)
 {
     $status = false;
     if (!$original && !$this->file) {
         $this->status("No file specified");
         return false;
     }
     $file = DevValue::isNotNull($original) ? $original : $this->path();
     if (!$this->allowedDir($file)) {
         $this->status("Location is outside of allowed path.");
         return false;
     }
     if (!$this->allowedDir($dest)) {
         $this->status("Destination is outside of allowed path.");
         return false;
     }
     if ($file != '') {
         if ($dest != '' && is_dir($dest)) {
             if ($this->exists($file)) {
                 if (!$this->exists($dest) || $overwrite) {
                     //copy process here
                     if ($success) {
                         $status = "Successfully copied file\n";
                         if ($remove_orig) {
                             $this->delete($file);
                             if (!$this->exists($this->file())) {
                                 $this->dirname = $dest;
                             }
                         }
                     } else {
                         $status = "Copy failed: file could not be moved\n";
                     }
                 } else {
                     $status = "Copy aborted. File cannot be overwritten\n";
                 }
             } else {
                 $status = "File '{$file}' does not exist\n";
             }
         } else {
             $status = "No file destination specified or destination does not exist\n";
         }
     } else {
         $status = "No file specified for deletion\n";
     }
     $this->status($status);
 }
Exemple #14
0
 public function field($var, $content = null, $formatted = null)
 {
     if ($formatted) {
         $content = HTML::format($content);
     }
     if (is_string($var)) {
         if (!$content) {
             throw new InvalidArgumentException('Cannot assign empty value.');
         }
         if (DevValue::isNotNull($formatted) && !is_bool($formatted)) {
             throw new InvalidArgumentException('Formatted argument expects boolean');
         }
         return parent::field($var, $content);
     } elseif (is_object($var) || DevArray::isAssoc($var)) {
         if (!$formatted) {
             $formatted = $content;
         }
         foreach ($var as $a => $b) {
             $this->field($a, $b, $formatted);
         }
     } else {
         throw new InvalidArgumentException('Invalid property');
     }
 }
 public function testDoesntRecognizeValueAsNullStatically()
 {
     for ($i = 1; $i < 100; $i++) {
         $falseResult = DevValue::isNull($i);
         $trueResult = DevValue::isNotNull($i);
         $this->assertTrue($trueResult);
         $this->assertFalse($falseResult);
     }
 }
Exemple #16
0
 public static function inDB($field, $value, $table)
 {
     $db = new MysqlLink(array('table' => $table));
     if (DevValue::isNotNull($value)) {
         //$db->field($field, $value);
         $db->query("select from {$table} where {$field} = {$value}");
         $result = $db->result();
         if ($result && count($result->num_rows > 0)) {
             return true;
         }
     }
     return false;
 }