1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<?php
namespace Gedcomx\GedcomxFile;
/**
* Represents a GEDCOM X file entry within a zip file.
*
* Class GedcomxFileEntry
*
* @package Gedcomx\GedcomxFile
*/
class GedcomxFileEntry
{
/**
* @var string Entry name
*/
private $name;
/**
* @var string The contents of the archive entry
*/
private $contents;
/**
* @var string[] Associative array of attributes from the METAINF.MF file
*/
private $attributes;
/**
* Create a new GedcomxFileEntry
*
* @param string $name
* @param string $content
* @param null $attributes
*/
public function __construct($name, $content = null, $attributes = null)
{
$this->name = $name;
$this->contents = $content;
$this->attributes = $attributes;
}
/**
* Return the name in the archive
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the name of the entry
*
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Return the contents of this entry
*
* @return string|null
*/
public function getContents()
{
return $this->contents;
}
/**
* The contents of the zip file entry
*
* @param string $contents
*/
public function setContents($contents)
{
$this->contents = $contents;
}
/**
* Return the attributes of this entry
*
* @return mixed
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* Set the attributes array
*
* @param array $attributes
*/
public function setAttributes($attributes)
{
$this->attributes = $attributes;
}
/**
* Add an attribute to the list
*
* @param string $key
* @param string $value
*/
public function addAttribute($key, $value)
{
$this->attributes[$key] = $value;
}
/**
* Return the value of a given key
*
* @param string $key
*
* @return null|string
*/
public function getAttribute($key)
{
return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
}
/**
* Return the content type stored with this entry.
*
* @return null|string
*/
public function getContentType()
{
return $this->getAttribute("Content-Type");
}
/**
* Parse the attributes from a data block in the MANIFEST file
*
* @param string $block
*/
public function parseEntryData($block)
{
$lines = explode("\n",$block);
foreach ($lines as $line) {
list($key, $value) = explode(": ", $line);
$this->addAttribute($key, $value);
if ($key == "Name") {
$this->setName($value);
}
}
}
}