Skip to content

Commit

Permalink
1.3.1
Browse files Browse the repository at this point in the history
Compatibility Fixes
  • Loading branch information
Blaxus committed May 14, 2017
1 parent 7b8741c commit 3009a61
Showing 1 changed file with 46 additions and 23 deletions.
69 changes: 46 additions & 23 deletions src/frontmatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
*/
class FrontMatter
{
/**
* All the parameters.
* @param array $data metadata & content
*/
public $data;
/**
* All the parameters.
* @param array $data metadata & content
*/
public $data;

/**
* Constructor method, checks a file and then puts the contents into custom strings for usage
* @param string $file The input file
*/
public function __construct($file)
{
if(file_exists($file)) {
$document = file_get_contents($file);
}
/**
* Constructor method, checks a file and then puts the contents into custom strings for usage
* @param string $file The input file
*/
public function __construct($file)
{
$document = (file_exists($file)) ? file_get_contents($file) : $file;

# Split into chunks
$chars = explode('---', $document);
Expand All @@ -41,14 +39,39 @@ public function __construct($file)
}
$this->data = array_merge($array1, $array2);
#$this->data = json_decode(json_encode($merge), FALSE);
}
}

/**
* fetch method returns the value of a given key
* @return string $value The value for a given key
*/
public function fetch($key)
{
return $this->data[$key];
}

/**
* fetchKeys method returns an array of all meta data without the content
* @return [array] collection of all meta keys provided to FrontMatter
*/
public function fetchKeys()
{
# Load the keys so we don't edit the native object data
$keys = $this->data;

# Remove $data[content] from the keys so we only have the meta data
unset($keys['content']);

return $keys;
}

/**
* fetch method returns the value of a given key
* @return string $value The value for a given key
*/
public function fetch($key)
{
return $this->data[$key];
}
/**
* keyExists method Checks to see if a key exists
* @return bool
*/
public function keyExists($key)
{
#return (isset($this->data[$key])) ? true : false; # Isset Version
return array_key_exists($key, $this->data); # array_key_exists version
}
}

0 comments on commit 3009a61

Please sign in to comment.