Symfony\Component\Finder\Finder::count PHP Method

count() public method

Counts all the results collected by the iterators.
public count ( ) : integer
return integer
    public function count()
    {
        return iterator_count($this->getIterator());
    }

Usage Example

 /**
  * @Route("/inbox", defaults={"_format"="json"})
  */
 public function dirAction(Request $request)
 {
     $dir = $request->query->get("dir", "");
     $type = $request->query->get("type", "file");
     $baseDir = realpath($this->container->getParameter('pumukit2.inbox'));
     /*
     if(0 !== strpos($dir, $baseDir)) {
         throw $this->createAccessDeniedException();
     }
     */
     $finder = new Finder();
     $res = array();
     if ("file" == $type) {
         $finder->depth('< 1')->followLinks()->in($dir);
         $finder->sortByName();
         foreach ($finder as $f) {
             $res[] = array('path' => $f->getRealpath(), 'relativepath' => $f->getRelativePathname(), 'is_file' => $f->isFile(), 'hash' => hash('md5', $f->getRealpath()), 'content' => false);
         }
     } else {
         $finder->depth('< 1')->directories()->followLinks()->in($dir);
         $finder->sortByName();
         foreach ($finder as $f) {
             if (0 !== count(glob("{$f}/*"))) {
                 $contentFinder = new Finder();
                 $contentFinder->files()->in($f->getRealpath());
                 $res[] = array('path' => $f->getRealpath(), 'relativepath' => $f->getRelativePathname(), 'is_file' => $f->isFile(), 'hash' => hash('md5', $f->getRealpath()), 'content' => $contentFinder->count());
             }
         }
     }
     return new JsonResponse($res);
 }
All Usage Examples Of Symfony\Component\Finder\Finder::count