12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Elgg;
- class EntityDirLocator {
-
- const BUCKET_SIZE = 5000;
-
- public function __construct($guid) {
- $guid = (int) $guid;
- if (!$guid || $guid < 1) {
-
- throw new \InvalidArgumentException("GUIDs must be integers > 0.");
- }
- $this->guid = $guid;
- }
-
-
- public function getPath() {
- $bound = $this->getLowerBucketBound($this->guid);
- return "$bound/$this->guid/";
- }
-
- public function __toString() {
- return $this->getPath();
- }
-
- private static function getLowerBucketBound($guid, $bucket_size = null) {
- if (!$bucket_size || $bucket_size < 1) {
- $bucket_size = self::BUCKET_SIZE;
- }
- if ($guid < 1) {
- return false;
- }
- return (int) max(floor($guid / $bucket_size) * $bucket_size, 1);
- }
- }
|