/** * @see DirectoryCalculator::calculateDirectory */ public function calculateDirectory(Identifiable $obj) { if (!$obj instanceof Dateable) { throw new LogicException('Expected a dateable'); } $dt = $obj->getDateCreated(); $path = $dt->format($this->getFormat()); return $path; }
/** * @see DirectoryCalculator::calculateDirectory */ public function calculateDirectory(Identifiable $obj) { if (!$obj instanceof UniversallyIdentifiable) { throw new LogicException('Expected an universally identifiable'); } if (!preg_match($this->uuidRegex, $obj->getUuid())) { throw new LogicException('Expected a valid UUID'); } $uuid = str_replace('-', '', $obj->getUuid()); $dirs = []; for ($x = 0; $x < strlen($uuid); $x += 2) { $dirs[] = substr($uuid, $x, 2); } return implode(DIRECTORY_SEPARATOR, $dirs); }
/** * @see DirectoryCalculator::calculateDirectory */ public function calculateDirectory(Identifiable $obj) { if (!is_numeric($obj->getId())) { throw new LogicException(sprintf("Expected a numeric identifier ('%s' was provided)", $obj->getId())); } $directoryLevels = $this->getDirectoryLevels() + 1; $filesPerDirectory = $this->getFilesPerDirectory(); $arr = array(); $tmpfileid = $obj->getId() - 1; for ($count = 1; $count <= $directoryLevels; ++$count) { $lus = $tmpfileid / pow($filesPerDirectory, $directoryLevels - $count); $tmpfileid = $tmpfileid % pow($filesPerDirectory, $directoryLevels - $count); $arr[] = floor($lus) + 1; } array_pop($arr); return implode(DIRECTORY_SEPARATOR, $arr); }