Example #1
0
 /**
  * @param $response
  * @param $expectProperty
  * @return mixed
  * @throws \ErrorException
  */
 protected function validateResponse($response, $expectProperty)
 {
     if (!is_object($response) || !property_exists($response, $expectProperty)) {
         return Error::exception('Authorization error');
     }
     return $response->{$expectProperty};
 }
Example #2
0
 /**
  * Sorting collection by key
  * 
  * @param string $key - element key
  * @param string $direction - sorting direction (SQL style)
  * @return Collection <\VCAPI\Common\Collection>
  */
 public function sort($key, $direction = 'ASC')
 {
     $keys = array();
     foreach ($this->collection as $item) {
         if (is_array($item)) {
             if (!isset($item[$key])) {
                 continue;
             }
             $keys[] = $item[$key];
         } elseif (is_object($item)) {
             if (!property_exists($item, $key)) {
                 continue;
             }
             $keys[] = $item->{$key};
         }
     }
     if (empty($keys)) {
         Error::exception('No valid data to sort');
         return $this->collection;
     }
     $sorted = $this->collection;
     $direction = $direction == 'DESC' ? SORT_DESC : SORT_ASC;
     array_multisort($keys, $direction, $sorted);
     return $sorted;
 }
 /**
  * Return the view's HTML
  *
  * @return string
  */
 public function __toString()
 {
     try {
         ob_start();
         extract((array) $this);
         require SP . "View/" . $this->__view . EXT;
         return ob_get_clean();
     } catch (\Exception $e) {
         Error::exception($e);
         return '';
     }
 }
| may be used by the developer.
|
*/
require 'core.php';
/*
|--------------------------------------------------------------------------
| Setup Error & Exception Handling
|--------------------------------------------------------------------------
|
| Next we'll register custom handlers for all errors and exceptions so we
| can display a clean error message for all errors, as well as do any
| custom error logging that may be setup by the developer.
|
*/
set_exception_handler(function ($e) {
    Error::exception($e);
});
set_error_handler(function ($code, $error, $file, $line) {
    Error::native($code, $error, $file, $line);
});
register_shutdown_function(function () {
    Error::shutdown();
});
/*
|--------------------------------------------------------------------------
| Report All Errors
|--------------------------------------------------------------------------
|
| By setting error reporting to -1, we essentially force PHP to report
| every error, and this is guranteed to show every error on future
| releases of PHP. This allows everything to be fixed early!
 /**
  * alias for render()
  *
  * @return string
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (\Exception $e) {
         Error::exception($e);
         return '';
     }
 }
 public static function fatal()
 {
     if ($e = error_get_last()) {
         Error::exception(new \ErrorException($e['message'], $e['type'], 0, $e['file'], $e['line']));
     }
 }
 /**
  * Return an HTML pagination string
  *
  * @return string
  */
 public function __toString()
 {
     try {
         // Start and end must be valid integers
         $start = $this->current - $this->links > 0 ? $this->current - $this->links : 1;
         $end = $this->current + $this->links < $this->total ? $this->current + $this->links : $this->total;
         $html = $this->previous();
         for ($i = $start; $i <= $end; ++$i) {
             // Current link is "active"
             $attributes = $this->current == $i ? array('class' => 'active') : array();
             // Wrap the link in a list item
             $html .= HTML::tag('li', HTML::link($this->url($i), $i), $attributes);
         }
         $html .= $this->next();
         return HTML::tag('div', "<ul>\n" . $html . "</ul>\n", $this->attributes);
     } catch (\Exception $e) {
         Error::exception($e);
         return '';
     }
 }
 /**
  * Return the current HTML form as a string
  */
 public function __toString()
 {
     try {
         if ($this->field) {
             return $this->render_field();
         }
         if (!$this->fields) {
             return '';
         }
         $output = '';
         foreach ($this->fields as $field) {
             $output .= $field;
         }
         return $output;
     } catch (\Exception $e) {
         Error::exception($e);
         return '';
     }
 }
Example #9
0
 /**
  * Inject logging logic
  * @see Exception
  */
 public function __construct($message = '', $code = 0, Exception $previous = null)
 {
     parent::__construct((string) $message, (int) $code, $previous);
     Error::exception($this);
 }