Ejemplo n.º 1
0
 public function testDataGetKeyIsNull()
 {
     $dataArr = array('test' => 42);
     $this->assertEquals($dataArr, dataGet($dataArr, null));
     $this->assertEquals(42, dataGet($dataArr, 'test'));
     $this->assertEquals(43, dataGet($dataArr, 'test-unknown', 43));
 }
Ejemplo n.º 2
0
 public function call(&$response)
 {
     if ($this->shouldAuthenticate($response)) {
         $user = dataGet($_SERVER, 'PHP_AUTH_USER');
         $password = dataGet($_SERVER, 'PHP_AUTH_PW');
         if (!$this->authenticate($user, $password)) {
             app()->abort('401', 'not aut', array("WWW-Authenticate" => sprintf('Basic realm="%s"', $this->options["realm"])));
         }
     }
 }
Ejemplo n.º 3
0
 private function buildRestRoutes($routeBaseName, $routeBaseData)
 {
     $resources = array('index' => array('method' => 'GET', 'append' => ''), 'create' => array('method' => 'GET', 'append' => '/create'), 'store' => array('method' => 'POST', 'append' => ''), 'show' => array('method' => 'GET', 'append' => '/:id'), 'edit' => array('method' => 'GET', 'append' => '/:id/edit'), 'update' => array('method' => 'PUT', 'append' => '/:id'), 'destroy' => array('method' => 'DELETE', 'append' => '/:id'));
     foreach ($resources as $name => $definition) {
         $routeName = $routeBaseName . '.' . $name;
         $routeData = $routeBaseData;
         $routeData['method'] = $definition['method'];
         $routeData['path'] .= $definition['append'];
         $routeData['target'] .= '::' . $name;
         $routeData['parameters'] = array_merge(array('id' => '[0-9]*'), dataGet($routeBaseData, 'parameters', array()));
         $this->buildRoute($routeName, $routeData);
     }
 }
Ejemplo n.º 4
0
 public function parse()
 {
     if (isset($_SERVER['REQUEST_URI'])) {
         $this->setRequestUri($_SERVER['REQUEST_URI']);
         $parseResult = parse_url($_SERVER['REQUEST_URI']);
         $this->path = dataGet($parseResult, 'path');
         $this->query = dataGet($parseResult, 'query');
     }
     if (isset($_SERVER['REQUEST_METHOD'])) {
         $this->setMethod($_SERVER['REQUEST_METHOD']);
     }
     if (isset($_POST['_method'])) {
         $this->setMethod($_POST['_method']);
     }
 }
Ejemplo n.º 5
0
 public static function renderMessages()
 {
     /**
     TODO : call user defined view
     */
     self::read();
     $output = '';
     $availableTypes = array('success' => 'success', 'info' => 'info', 'error' => 'danger');
     foreach ($availableTypes as $type => $displayAlias) {
         $currentMessage = dataGet(self::$items, $type, null);
         if ($currentMessage !== null) {
             $output .= '<div class="alert alert-' . $displayAlias . '">' . implode('<br/>', (array) $currentMessage) . '</div>';
         }
     }
     return $output;
 }
Ejemplo n.º 6
0
 /**
  * Key an associative array by a field.
  *
  * @param  string  $keyBy
  * @return Collection
  */
 public function keyBy($keyBy)
 {
     $results = array();
     foreach ($this->_items as $item) {
         $key = dataGet($item, $keyBy);
         $results[$key] = $item;
     }
     return new self($results);
 }
Ejemplo n.º 7
0
 private function loadRelationManyMany($name)
 {
     $pivot = $this->relations[$name]['pivot'];
     $sourceType = $this->relations[$name]['source_type'];
     $target = dataGet($this->relations[$name], 'target');
     $validate = dataGet($this->relations[$name], 'validate', null);
     $this->relationValues[$name] = $pivot::loadFor($sourceType, $this->{$this->relations[$name]['source']}, $target, $validate);
     return true;
 }
Ejemplo n.º 8
0
 public function sortBy($field, $reverse = false)
 {
     if ($reverse) {
         $sortFunction = function ($a, $b) use($field) {
             $first = dataGet($a, $field);
             $second = dataGet($b, $field);
             if ($first == $second) {
                 return 0;
             }
             return $first > $second ? -1 : 1;
         };
     } else {
         $sortFunction = function ($a, $b) use($field) {
             $first = dataGet($a, $field);
             $second = dataGet($b, $field);
             if ($first == $second) {
                 return 0;
             }
             return $first < $second ? -1 : 1;
         };
     }
     usort($this->items, $sortFunction);
     return $this;
 }