Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/document/PhabricatorDocumentRef.php
<?php | <?php | ||||
final class PhabricatorDocumentRef | final class PhabricatorDocumentRef | ||||
extends Phobject { | extends Phobject { | ||||
private $name; | private $name; | ||||
private $mimeType; | private $mimeType; | ||||
private $file; | private $file; | ||||
private $byteLength; | private $byteLength; | ||||
private $snippet; | private $snippet; | ||||
private $symbolMetadata = array(); | private $symbolMetadata = array(); | ||||
private $blameURI; | private $blameURI; | ||||
private $coverage = array(); | private $coverage = array(); | ||||
private $data; | |||||
public function setFile(PhabricatorFile $file) { | public function setFile(PhabricatorFile $file) { | ||||
$this->file = $file; | $this->file = $file; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getFile() { | public function getFile() { | ||||
return $this->file; | return $this->file; | ||||
Show All 38 Lines | public function setByteLength($length) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getByteLength() { | public function getByteLength() { | ||||
if ($this->byteLength !== null) { | if ($this->byteLength !== null) { | ||||
return $this->byteLength; | return $this->byteLength; | ||||
} | } | ||||
if ($this->data !== null) { | |||||
return strlen($this->data); | |||||
} | |||||
if ($this->file) { | if ($this->file) { | ||||
return (int)$this->file->getByteSize(); | return (int)$this->file->getByteSize(); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public function setData($data) { | |||||
$this->data = $data; | |||||
return $this; | |||||
} | |||||
public function loadData($begin = null, $end = null) { | public function loadData($begin = null, $end = null) { | ||||
if ($this->data !== null) { | |||||
$data = $this->data; | |||||
if ($begin !== null && $end !== null) { | |||||
$data = substr($data, $begin, $end - $begin); | |||||
} else if ($begin !== null) { | |||||
$data = substr($data, $begin); | |||||
} else if ($end !== null) { | |||||
$data = substr($data, 0, $end); | |||||
} | |||||
return $data; | |||||
} | |||||
if ($this->file) { | if ($this->file) { | ||||
$iterator = $this->file->getFileDataIterator($begin, $end); | $iterator = $this->file->getFileDataIterator($begin, $end); | ||||
$result = ''; | $result = ''; | ||||
foreach ($iterator as $chunk) { | foreach ($iterator as $chunk) { | ||||
$result .= $chunk; | $result .= $chunk; | ||||
} | } | ||||
return $result; | return $result; | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |