52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Motion;
|
||
|
|
||
|
use Symfony\Component\Filesystem\Filesystem;
|
||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||
|
use Symfony\Component\Finder\Finder;
|
||
|
use App\Motion\Snapshot;
|
||
|
|
||
|
/**
|
||
|
* class SnapshotRepository.
|
||
|
*
|
||
|
* @author Simon Vieille <simon@deblan.fr>
|
||
|
*/
|
||
|
class SnapshotRepository
|
||
|
{
|
||
|
protected Finder $finder;
|
||
|
|
||
|
protected ParameterBagInterface $parameters;
|
||
|
|
||
|
public function __construct(ParameterBagInterface $parameters)
|
||
|
{
|
||
|
$this->finder = new Finder();
|
||
|
$this->parameters = $parameters;
|
||
|
}
|
||
|
|
||
|
public function find(): array
|
||
|
{
|
||
|
$objects = [];
|
||
|
|
||
|
$files = $this->finder
|
||
|
->files()
|
||
|
->in($this->parameters->get('motion_snapshots_directory'))
|
||
|
->name('/.*\.mp4$/s')
|
||
|
->sortByModifiedTime();
|
||
|
|
||
|
foreach ($files as $file) {
|
||
|
$date = basename($file->getPath());
|
||
|
$time = str_replace(['.mp4', '-'], ['', ':'], $file->getBasename());
|
||
|
|
||
|
$snapshot = new Snapshot();
|
||
|
$snapshot
|
||
|
->setDate(new \DateTime($date.' '.$time))
|
||
|
->setPath($file->getPath().'/'.$file->getBasename());
|
||
|
|
||
|
$objects[] = $snapshot;
|
||
|
}
|
||
|
|
||
|
return $objects;
|
||
|
}
|
||
|
}
|