示例#1
0
 public static function getDataProvider(ActiveRecord $model, $attributes)
 {
     $sort = [];
     if (method_exists($model, 'gridViewSort')) {
         $sort = $model->gridViewSort();
     }
     $search = new static($model);
     $dataProvider = new SearchDataProvider(['module' => \Yii::$app->getModule('ycm'), 'query' => $search->getQuery(), 'sort' => $sort, 'pagination' => ['pageSize' => 20]]);
     if (method_exists($model, 'search')) {
         $scenarios = $model->scenarios();
         if (isset($scenarios['ycm-search'])) {
             $model->setScenario('ycm-search');
         }
         $modelSearch = $model->search($attributes);
         if ($modelSearch instanceof ActiveDataProvider) {
             $dataProvider = $modelSearch;
         } elseif (is_array($modelSearch)) {
             // Load data to model
             $model->load($attributes);
             if ($model->validate()) {
                 // Iterate config
                 foreach ($modelSearch as $search_condition) {
                     // Check attribute name and search type exists
                     if (!isset($search_condition[0]) || !isset($search_condition[1])) {
                         throw new \Exception('Search row must contain in 0 offset attribute name, in 1 offset - search type');
                     }
                     // Check used type implemented
                     if (!method_exists($search, $search_condition[1])) {
                         throw new \Exception('Search type' . $search_condition[1] . ' not implemented');
                     }
                     $search->{$search_condition[1]}($search_condition[0]);
                 }
             }
         } else {
             throw new \BadMethodCallException('Search method must be return instance of ActiveDataProvider or config array');
         }
     }
     return $dataProvider;
 }
示例#2
0
文件: Uri.php 项目: haoyanfei/zf2
 /**
  * Convert a relative URI into an absolute URI using a base absolute URI as
  * a reference.
  *
  * This is similar to merge() - only it uses the supplied URI as the
  * base reference instead of using the current URI as the base reference.
  *
  * Merging algorithm is adapted from RFC-3986 section 5.2
  * (@link http://tools.ietf.org/html/rfc3986#section-5.2)
  *
  * @param  Uri|string $baseUri
  * @throws Exception\InvalidArgumentException
  * @return Uri
  */
 public function resolve($baseUri)
 {
     // Ignore if URI is absolute
     if ($this->isAbsolute()) {
         return $this;
     }
     if (is_string($baseUri)) {
         $baseUri = new static($baseUri);
     } elseif (!$baseUri instanceof Uri) {
         throw new Exception\InvalidArgumentException('Provided base URI must be a string or a Uri object');
     }
     // Merging starts here...
     if ($this->getHost()) {
         $this->setPath(static::removePathDotSegments($this->getPath()));
     } else {
         $basePath = $baseUri->getPath();
         $relPath = $this->getPath();
         if (!$relPath) {
             $this->setPath($basePath);
             if (!$this->getQuery()) {
                 $this->setQuery($baseUri->getQuery());
             }
         } else {
             if (substr($relPath, 0, 1) == '/') {
                 $this->setPath(static::removePathDotSegments($relPath));
             } else {
                 if ($baseUri->getHost() && !$basePath) {
                     $mergedPath = '/';
                 } else {
                     $mergedPath = substr($basePath, 0, strrpos($basePath, '/') + 1);
                 }
                 $this->setPath(static::removePathDotSegments($mergedPath . $relPath));
             }
         }
         // Set the authority part
         $this->setUserInfo($baseUri->getUserInfo());
         $this->setHost($baseUri->getHost());
         $this->setPort($baseUri->getPort());
     }
     $this->setScheme($baseUri->getScheme());
     return $this;
 }
示例#3
0
文件: Uri.php 项目: zobzn/zbz-uri
 /**
  * Transform References
  *
  * This function implements the "transform references" algorithm from
  * the RFC3986 specification for URIs.
  *
  * @see http://tools.ietf.org/html/rfc3986#page-31
  *
  * @param string $relative
  * @param bool   $strict
  *
  * @return static
  */
 public function transformReference($relative, $strict = false)
 {
     $base = $this;
     $relative = new static((string) $relative);
     $transformed = new static();
     if (!$strict && $relative->getScheme() == $this->getScheme()) {
         $relative->setScheme(null);
     }
     if ($relative->getScheme() !== null) {
         $transformed->setScheme($relative->getScheme());
         $transformed->setAuthority($relative->getAuthority());
         $transformed->setPath(static::remove_dot_segments($relative->getPath()));
         $transformed->setQuery($relative->getQuery());
     } else {
         if ($relative->getAuthority() !== null) {
             $transformed->setAuthority($relative->getAuthority());
             $transformed->setPath(static::remove_dot_segments($relative->getPath()));
             $transformed->setQuery($relative->getQuery());
         } else {
             if ($relative->getPath() == '') {
                 $transformed->setPath($base->getPath());
                 if ($relative->getQuery() !== null) {
                     $transformed->setQuery($relative->getQuery());
                 } else {
                     $transformed->setQuery($base->getQuery());
                 }
             } else {
                 if ('/' == substr($relative->getPath(), 0, 1)) {
                     $transformed->setPath(static::remove_dot_segments($relative->getPath()));
                 } else {
                     $transformed->setPath(static::merge($base->getPath(), $relative->getPath()));
                     $transformed->setPath(static::remove_dot_segments($transformed->getPath()));
                 }
                 $transformed->setQuery($relative->getQuery());
             }
             $transformed->setAuthority($base->getAuthority());
         }
         $transformed->setScheme($base->getScheme());
     }
     $transformed->setFragment($relative->getFragment());
     return $transformed;
 }