当前位置: 首页>>代码示例>>PHP>>正文


PHP Finder::sortByType方法代码示例

本文整理汇总了PHP中Symfony\Component\Finder\Finder::sortByType方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::sortByType方法的具体用法?PHP Finder::sortByType怎么用?PHP Finder::sortByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Finder\Finder的用法示例。


在下文中一共展示了Finder::sortByType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sortBy

 /**
  * @param string|callable $by
  * @return $this
  */
 public function sortBy($by = self::SORT_BY_NAME)
 {
     if (is_callable($by)) {
         $this->finder->sort($by);
         return $this;
     }
     switch (strtolower($by)) {
         case self::SORT_BY_NAME:
         case 'name':
             $this->finder->sortByName();
             break;
         case self::SORT_BY_CHANGED_TIME:
         case 'ctime':
             $this->finder->sortByChangedTime();
             break;
         case self::SORT_BY_ACCESSED_TIME:
         case 'atime':
             $this->finder->sortByAccessedTime();
             break;
         case self::SORT_BY_TYPE:
         case 'type':
             $this->finder->sortByType();
             break;
         case self::SORT_BY_MODIFIED_TIME:
         case 'mtime':
             $this->finder->sortByModifiedTime();
             break;
         default:
             throw new \InvalidArgumentException($by . ' is not a supported argument for sorting.');
     }
     return $this;
 }
开发者ID:suralc,项目名称:pvra,代码行数:36,代码来源:FileFinderBuilder.php

示例2: getLibraryImagesAction

 /**
  * Returns files from required directory
  *
  * @param Request $request
  */
 public function getLibraryImagesAction(Request $request)
 {
     $finder = new Finder();
     $finder->sortByType();
     $finder->depth('== 0');
     $result = array();
     $files = array();
     $result['thumbsDir'] = $this->container->getParameter('comur_image.thumbs_dir');
     if (!is_dir($request->request->get('dir'))) {
         mkdir($request->request->get('dir') . '/', 0755, true);
     }
     foreach ($finder->in($request->request->get('dir'))->files() as $file) {
         $files[] = $file->getFilename();
     }
     $result['files'] = $files;
     // var_dump(json_encode($result));exit;
     return new Response(json_encode($result));
 }
开发者ID:desmax,项目名称:ComurImageBundle,代码行数:23,代码来源:UploadController.php

示例3: index


//.........这里部分代码省略.........
     /*
     |--------------------------------------------------------------------------
     | File Size
     |--------------------------------------------------------------------------
     |
     | Restrict files by size. Can be chained and allows comparison operators.
     |
     */
     if ($file_size) {
         foreach ($file_size as $size) {
             $finder->size($size);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | File Date
     |--------------------------------------------------------------------------
     |
     | Restrict files by last modified date. Can use comparison operators, and
     | since/after is aliased to >, and until/before to <.
     |
     */
     if ($file_date) {
         $finder->date($file_date);
     }
     /*
     |--------------------------------------------------------------------------
     | Depth
     |--------------------------------------------------------------------------
     |
     | Recursively traverse directories, starting at 0.
     |
     */
     if ($depth) {
         $finder->depth($depth);
     }
     /*
     |--------------------------------------------------------------------------
     | Sort By
     |--------------------------------------------------------------------------
     |
     | Sort by name, file, or type
     |
     */
     if ($sort_by) {
         if ($sort_by === 'file' || $sort_by === 'name') {
             $finder->sortByName();
         } elseif ($sort_by === 'type') {
             $finder->sortByType();
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Assemble File Array
     |--------------------------------------------------------------------------
     |
     | Select the important bits of data on the list of files.
     |
     */
     $matches = $finder->files()->followLinks();
     $files = array();
     foreach ($matches as $file) {
         $files[] = array('extension' => $file->getExtension(), 'filename' => $file->getFilename(), 'file' => Path::toAsset($file->getPathname()), 'name' => Path::toAsset($file->getPathname()), 'size' => File::getHumanSize($file->getSize()), 'size_bytes' => $file->getSize(), 'size_kilobytes' => number_format($file->getSize() / 1024, 2), 'size_megabytes' => number_format($file->getSize() / 1048576, 2), 'size_gigabytes' => number_format($file->getSize() / 1073741824, 2), 'is_image' => File::isImage($file->getPathname()));
     }
     /*
     |--------------------------------------------------------------------------
     | Sort Direction
     |--------------------------------------------------------------------------
     |
     | Set the sort direction, defaulting to "asc" (ascending)
     |
     */
     if ($sort_dir === 'desc') {
         $files = array_reverse($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Randomizing
     |--------------------------------------------------------------------------
     |
     | You can't sort randomly using Symfony finder, so we'll do it manually.
     |
     */
     if ($sort_by === 'random') {
         shuffle($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Limit Files
     |--------------------------------------------------------------------------
     |
     | Limit the number of files returned. Needs to be run after sort_dir to 
     | ensure consistency.
     |
     */
     if ($limit) {
         $files = array_slice($files, 0, $limit);
     }
     return Parse::tagLoop($this->content, $files, true, $this->context);
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:101,代码来源:pi.get_files.php

示例4: getLibraryImagesAction

 /**
  * Returns files from required directory
  *
  * @param Request $request
  */
 public function getLibraryImagesAction(Request $request)
 {
     //allow a pass through from initializeImageManager JS in comur.imagelibrary.js.
     $type = $request->query->get('type', 'image');
     $finder = new Finder();
     $finder->sortByType();
     $finder->depth('== 0');
     $result = array();
     $files = array();
     $thumbsDir = $this->container->getParameter('library_thumbs_dir') . '/' . $type;
     $thumbsDir = str_replace('uploads/../', '', $thumbsDir);
     if (!is_dir($thumbsDir)) {
         mkdir($thumbsDir . '/', 0755, true);
     }
     foreach ($finder->in($thumbsDir)->files() as $file) {
         $files[] = $file->getFilename();
     }
     $result['files'] = $files;
     // var_dump(json_encode($result));exit;
     $result['thumbsDir'] = '../../../thumbs';
     $data = json_encode($result);
     return new Response($data);
 }
开发者ID:HolyJo,项目名称:ComurImageBundle,代码行数:28,代码来源:UploadController.php

示例5: sortByType

 /**
  * @return Finder
  */
 public function sortByType()
 {
     return parent::sortByType();
 }
开发者ID:stopsopa,项目名称:utils,代码行数:7,代码来源:Finder.php


注:本文中的Symfony\Component\Finder\Finder::sortByType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。