/**
  * Find all objects within a directory / namespace
  *
  * @param $namespace    string
  * @param $query        Query   Optional query to filter items.
  *                              Call EntityManager::query() to get instance
  * @return array
  */
 public function findAll($namespace, Query $query = null)
 {
     $finder = new Finder();
     $finder->files()->in($this->location . '/' . $namespace)->name('*.json')->notName('_meta.json');
     $entities = [];
     $idToFileMapping = [];
     foreach ($finder as $file) {
         /**
          * @var \SplFileInfo $file
          */
         $realPath = $file->getRealPath();
         $id = str_replace($this->location, '', $realPath);
         $id = $this->normaliseIdFromRelativeFilename($id);
         $idToFileMapping[$id] = $file->getFilename();
         $entities[] = $this->find($id);
     }
     // Filter the items
     if (null !== $query) {
         $entities = $query->getFilteredEntities($entities);
     }
     // Sort the items
     // TODO: Allow user-defined sorting
     $accessor = $this->accessor;
     usort($entities, function ($obj1, $obj2) use($idToFileMapping, $accessor) {
         return strnatcasecmp($idToFileMapping[$this->accessor->getValue($obj1, 'id')], $idToFileMapping[$this->accessor->getValue($obj2, 'id')]);
     });
     // Sometimes array keys can be out of order, i.e. no 0
     $entities = array_values($entities);
     return $entities;
 }