Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
EntityDirLocator.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
17 
21  const BUCKET_SIZE = 5000;
22 
30  public function __construct($guid) {
31  $guid = (int) $guid;
32 
33  if (!$guid || $guid < 1) {
34  // Don't throw a ClassException to keep this class completely atomic.
35  throw new \InvalidArgumentException("GUIDs must be integers > 0.");
36  }
37 
38  $this->guid = $guid;
39  }
40 
48  public function getPath() {
49  $bound = $this->getLowerBucketBound($this->guid);
50  return "$bound/$this->guid/";
51  }
52 
58  public function __toString() {
59  return $this->getPath();
60  }
61 
69  private static function getLowerBucketBound($guid, $bucket_size = null) {
70  if (!$bucket_size || $bucket_size < 1) {
71  $bucket_size = self::BUCKET_SIZE;
72  }
73  if ($guid < 1) {
74  return false;
75  }
76  return (int) max(floor($guid / $bucket_size) * $bucket_size, 1);
77  }
78 }
getPath()
Construct a file path matrix for an entity.
$guid
Removes an admin notice.
__construct($guid)
Find an entity's data dir.
__toString()
String casting magic method.