68 lines
1.3 KiB
PHP
68 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace PharLite;
|
|
|
|
/**
|
|
* Class representing a single object to be added to a phar
|
|
*
|
|
*
|
|
*/
|
|
class ManifestObject
|
|
{
|
|
protected $filename;
|
|
|
|
protected $localname;
|
|
|
|
protected $stripped = false;
|
|
|
|
public function __construct($filename, $localname=null)
|
|
{
|
|
$this->filename = $filename;
|
|
$this->localname = $localname;
|
|
}
|
|
|
|
public function setStripped(bool $stripped)
|
|
{
|
|
$this->stripped = $stripped;
|
|
}
|
|
|
|
public function getStripped():bool
|
|
{
|
|
return $this->stripped;
|
|
}
|
|
|
|
public function getFilename():string
|
|
{
|
|
return $this->filename;
|
|
}
|
|
|
|
public function getLocalName():string
|
|
{
|
|
return $this->localname;
|
|
}
|
|
|
|
public function addToPhar(\Phar $phar)
|
|
{
|
|
if ($this->stripped) {
|
|
// strip and add
|
|
} else {
|
|
$phar->addFile(
|
|
$this->getFilename(),
|
|
$this->getLocalName()
|
|
);
|
|
}
|
|
}
|
|
|
|
public function addFiltered(\Phar $phar, callable $filter)
|
|
{
|
|
$body = file_get_contents($this->filename);
|
|
$body = call_user_func($filter, $body);
|
|
$phar->addFromString($this->getLocalName(), $body);
|
|
}
|
|
|
|
public function getFilesize()
|
|
{
|
|
return filesize($this->filename);
|
|
}
|
|
}
|