示例#1
0
 public function parent($object = null)
 {
     if (DevValue::isNotNull($object)) {
         $this->_parent = $object;
     }
     return $this->_parent;
 }
示例#2
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);
 }
示例#3
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);
 }
示例#4
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);
 }
示例#5
0
 public function type($type = null)
 {
     if (DevValue::isNull($type)) {
         return $this->_type;
     }
     $this->_type = $type;
 }
示例#6
0
 public function content($content = null)
 {
     if (DevValue::isNotNull($content)) {
         $content = DevArray::toArray($content);
         $this->_content = $content;
     }
     return $this->_content;
 }
示例#7
0
 public function contents($data = null)
 {
     if (DevValue::isNull($data)) {
         return $this->_contents;
     }
     $this->_contents = $data;
     $this->perform(Event::CHANGE);
 }
示例#8
0
 public function status($message = null)
 {
     if (DevValue::isNull($message)) {
         $message = end($this->_status);
         return $message;
     }
     $this->_status[] = $message;
     $this->perform(Event::MESSAGE);
 }
示例#9
0
 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);
 }
示例#10
0
 public function write()
 {
     $source = $this->_source;
     $status = self::STATUS_FAILED;
     $data = DevValue::isEmpty($this->_contents) ? HTTP::jsonEncode($this->_data) : $this->_contents;
     $source->flush();
     $source->contents($data);
     $source->write();
     $status = self::STATUS_SUCCESS;
     $this->status($status);
 }
示例#11
0
 public function contents($data = null)
 {
     if (DevValue::isNull($data)) {
         return $this->_rows->current() ? $this->_rows->current() : parent::contents();
     } elseif (is_array($data) && !DevArray::isAssoc($data)) {
         $this->_rows = new Group($data);
     } elseif (DevArray::isAssoc($data)) {
         parent::contents($data);
     }
     $this->perform(Event::CHANGE);
 }
示例#12
0
 public function behavior($behavior, $callback = null)
 {
     if (is_string($behavior) && DevValue::isNotEmpty($behavior)) {
         if (strpos($behavior, 'Do') === 0) {
             $behavior = new Action($behavior);
         } elseif (strpos($behavior, 'Is') === 0) {
             $behavior = new State($behavior);
         } elseif (strpos($behavior, 'On') === 0) {
             $behavior = new Event($behavior);
         } else {
             $behavior = new Behavior($behavior);
         }
     }
     parent::behavior($behavior, $callback);
 }
示例#13
0
 public function behavior($behavior, $callback = null)
 {
     if (is_string($behavior) && DevValue::isNotEmpty($behavior)) {
         $behavior = new Behavior($behavior);
     }
     if (!$behavior instanceof Behavior) {
         throw new InvalidArgumentException("Invalid Behavior Type");
     }
     $this->_behaviors->add($behavior);
     if ($callback) {
         try {
             $this->handler(new Handler($behavior, $callback));
         } catch (InvalidArgumentException $e) {
             error_log($e->getMessage());
         }
     }
 }
示例#14
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;
 }
示例#15
0
 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));
     }
 }
示例#16
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);
 }
示例#17
0
 public function __construct($value = null)
 {
     parent::__construct($value);
     $this->_data = $this->_toArray();
 }
示例#18
0
 public function outputXML($data = null)
 {
     header("Content-Type: XML");
     $xml = 'No XML';
     if (DevValue::isNull($data == '')) {
         $data = $this->_data;
     }
     $xml = $this->buildXML($data);
     echo $xml;
 }
示例#19
0
 public static function difference($time1, $time2, $interval = null)
 {
     if (DevValue::isNull($interval)) {
         $interval = 'seconds';
     }
     $a = strtotime($time1);
     $b = strtotime($time2);
     $difference = $a > $b ? $a - $b : $b - $a;
     $div = 1;
     switch ($interval) {
         case 'years':
             $div *= 12;
         case 'months':
             $div *= 4;
         case 'weeks':
             $div *= 30;
         case 'days':
             $div *= 24;
         case 'hours':
             $div *= 60;
         case 'minutes':
             $div *= 60;
         default:
         case 'seconds':
             $div *= 1;
             break;
     }
     $output = $difference / $div;
     return $output;
 }
示例#20
0
 public function database($database = null)
 {
     if (DevValue::isNull($database)) {
         return $this->config('database');
     }
     // $this->close();
     $this->config('database', $database);
     // $this->open();
     $this->_connection = $this->config('database') ? $this->_current->{$this->config('database')} : null;
 }
示例#21
0
 public function database($database = null)
 {
     if (DevValue::isNull($database)) {
         return $this->config('database');
     }
     $this->config('database', $database);
     $db = $this->_connection;
     $db->select_db($this->config('database'));
 }
示例#22
0
 static function session($var, $value = null, $expire = null, $path = null, $secure = false)
 {
     if (DevValue::isNull($value)) {
         return isset($_SESSION[$var]) ? $_SESSION[$var] : null;
     }
     if (session_id() == '') {
         $domain = $path ? substr($path, 0, strpos($path, '/')) : HTTP::domain();
         $dir = $path ? substr($path, strpos($path, '/'), strlen($path)) : '/';
         $cookiedie = DevNumber::isValid($expire) ? time() + (int) $expire : (int) $expire;
         //expire in one hour
         $cookiesecure = (bool) $secure;
         session_set_cookie_params($cookiedie, $dir, $domain, $cookiesecure);
         session_start();
     }
     $status = ($_SESSION[$var] = $value) ? true : false;
     return $status;
 }
示例#23
0
 static function open($action = '', $name = '', $method = '', $validate = true, $properties = '', $image_path = 'images/', $css_path = 'css/rte.css')
 {
     $output = '';
     $action = HTML::href($action);
     if (DevValue::isNull($method)) {
         $method = 'post';
     }
     $output .= '<form enctype="multipart/form-data" method="' . $method . '" ' . ($name != '' ? 'name="' . $name . '"' : '') . ' ' . ($action != '' ? 'action="' . $action . '"' : '') . ' ' . $properties . '>';
     $output .= "\r";
     /*
     $output .= '
     <script language="JavaScript" type="text/javascript">
     	<!--
     	function submitForm() {
     		//make sure hidden and iframe values are in sync before submitting form
     		//to sync only 1 rte, use updateRTE(rte)
     		//to sync all rtes, use updateRTEs
     		//updateRTE(\'rte1\');
     		updateRTEs();
     		
     		//change the following line to true to submit form
     		return true;
     	}
     	
     	//Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML)
     	initRTE("' . $image_path . '", "", "", true);
     	//-->
     </script>
     <style type="text/css">
         @import url("'.$css_path.'");
         .rteImage {margin: 0px;}
     </style>
     ';
     */
     if ($validate) {
     }
     return $output;
 }
示例#24
0
 public function testDoesntRecognizeValueAsNullStatically()
 {
     for ($i = 1; $i < 100; $i++) {
         $falseResult = DevValue::isNull($i);
         $trueResult = DevValue::isNotNull($i);
         $this->assertTrue($trueResult);
         $this->assertFalse($falseResult);
     }
 }
示例#25
0
 public function renderRecordSet($recordSet, $formatted = null)
 {
     $output = '';
     $count = 0;
     if (DevValue::isNull($formatted)) {
         $formatted = true;
     }
     foreach ($recordSet as $a) {
         $this->clear();
         $this->set($a, $formatted);
         $output .= $this->render();
         Util::parachute($count, $this->config('max_records'));
     }
     return $output;
 }
示例#26
0
 private function message($records = null)
 {
     $records = DevValue::isNull($records) ? $records : $this->config('max_logs');
     $message = array_slice($this->_data, -$records);
     $message = array_filter($message);
     // $output = implode("\n", $message)."\n";
     $output = '';
     foreach ($message as $time => $line) {
         $output .= "{$time} - {$line}\n";
     }
     return $output;
 }
示例#27
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;
 }