/** * Lazy-loading attributes on accessing them using external resources. * * Object attributes are protected by default, but made read-only with * this magic method. * * @param string $attribute The name of the attribute to accesss. * @throws PHPTracker_Error When trying to access non-existent attribute. * @return mixed */ public function __get($attribute) { switch ($attribute) { case 'pieces': if (!isset($this->pieces)) { $this->pieces = $this->file->getHashesForPieces($this->size_piece); } return $this->pieces; break; case 'length': if (!isset($this->length)) { $this->length = $this->file->size(); } return $this->length; break; case 'name': if (!isset($this->name)) { $this->name = $this->file->basename(); } return $this->name; break; case 'file_path': if (!isset($this->file_path)) { $this->file_path = $this->file . ''; } return $this->file_path; break; case 'info_hash': if (!isset($this->info_hash)) { $this->info_hash = $this->calculateInfoHash(); } return $this->info_hash; break; case 'size_piece': return $this->size_piece; break; default: throw new PHPTracker_Error("Can't access attribute {$attribute} of " . __CLASS__); } }
public function testBasename() { $this->assertEquals(basename($this->original_path), $this->object->basename()); }