Elgg  Version 3.0
EntityDirLocator.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
18 
22  const BUCKET_SIZE = 5000;
23 
27  protected $guid;
28 
36  public function __construct($guid) {
37  $guid = (int) $guid;
38 
39  if (!$guid || $guid < 1) {
40  // Don't throw a ClassException to keep this class completely atomic.
41  throw new \InvalidArgumentException("GUIDs must be integers > 0.");
42  }
43 
44  $this->guid = $guid;
45  }
46 
54  public function getPath() {
55  $bound = $this->getLowerBucketBound($this->guid);
56  return "$bound/$this->guid/";
57  }
58 
64  public function __toString() {
65  return $this->getPath();
66  }
67 
75  private static function getLowerBucketBound(int $guid, int $bucket_size = 0) {
76  if ($bucket_size < 1) {
77  $bucket_size = self::BUCKET_SIZE;
78  }
79 
80  return (int) max(floor($guid / $bucket_size) * $bucket_size, 1);
81  }
82 }
getPath()
Construct a file path matrix for an entity.
$guid
Removes an admin notice.
Locate the relative path of an entity&#39;s data dir.
Configuration exception.
__construct($guid)
Find an entity&#39;s data dir.
__toString()
String casting magic method.