當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。