Elgg  Version 1.9
EntityDirLocator.php
Go to the documentation of this file.
1 <?php
2 
16 
20  const BUCKET_SIZE = 5000;
21 
29  public function __construct($guid) {
30  $guid = (int) $guid;
31 
32  if (!$guid || $guid < 1) {
33  // Don't throw a ClassException to keep this class completely atomic.
34  throw new InvalidArgumentException("GUIDs must be integers > 0.");
35  }
36 
37  $this->guid = $guid;
38  }
39 
47  public function getPath() {
48  $bound = $this->getLowerBucketBound($this->guid);
49  return "$bound/$this->guid/";
50  }
51 
57  public function __toString() {
58  return $this->getPath();
59  }
60 
68  private static function getLowerBucketBound($guid, $bucket_size = null) {
69  if (!$bucket_size || $bucket_size < 1) {
70  $bucket_size = self::BUCKET_SIZE;
71  }
72  if ($guid < 1) {
73  return false;
74  }
75  return (int) max(floor($guid / $bucket_size) * $bucket_size, 1);
76  }
77 }
$guid
Removes an admin notice.
__toString()
String casting magic method.
__construct($guid)
Find an entity&#39;s data dir.
const BUCKET_SIZE
Number of entries per matrix dir.
getPath()
Construct a file path matrix for an entity.