diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index e901667..0000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,21 +0,0 @@ -## How to contribute - -We prefer a minimalism approach. The [MicroPHP Manifesto](http://microphp.org) says it best. But in short: - -> I want to write and manage less code. - -We aim for simplicity and ease of use. Not cluttering and endless dependencies. By contributing you recognize our standards. And try to adhere to them. - -### Semantic Versioning - -We adhere to [Semantic Versioning](http://semver.org). So when it come down to Releases it is important to understand the differences and changes that you make. - -### Documentation - -Making code changes is not the only contribution you can make. If you did, it is also nice to update the documentation. - -You may also clean-up and update the Documentation if necessary. - -### Core Development Discussion - -Contact the core Maintainer(s) [@blaxus](https://github.com/blaxus) if you want to become a maintainer/support, have feature requests or other questions. \ No newline at end of file diff --git a/src/frontmatter.php b/src/frontmatter.php index 937fbdb..b919743 100644 --- a/src/frontmatter.php +++ b/src/frontmatter.php @@ -4,7 +4,6 @@ * PHP YAML FrontMatter Class * An easy to use class for handling YAML frontmatter in PHP. * - * @author Blaxus * @package Modularr/YAML-FrontMatter */ class FrontMatter @@ -14,7 +13,7 @@ class FrontMatter * @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 @@ -24,13 +23,12 @@ public function __construct($file) $file = (file_exists($file)) ? $this->Read($file) : str_replace(array("\r\n", "\r", "\n"), "\n", $file); $this->yaml_separator = "---\n"; $fm = $this->FrontMatter($file); - - foreach($fm as $key => $value) - { + + foreach($fm as $key => $value) { $this->data[$key] = $value; } } - + /** * fetch method returns the value of a given key * @return string $value The value for a given key @@ -39,7 +37,7 @@ public function fetch($key) { return $this->data[$key]; } - + /** * keyExists method Checks to see if a key exists * @return bool @@ -49,7 +47,7 @@ public function keyExists($key) #return (isset($this->data[$key])) ? true : false; # Isset Version return array_key_exists($key, $this->data); # array_key_exists version } - + /** * fetchKeys method returns an array of all meta data without the content * @return [array] collection of all meta keys provided to FrontMatter @@ -58,13 +56,13 @@ public function fetchKeys() { # Cache 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 array_pop($keys); - + return $keys; } - + /** * FrontMatter method, rturns all the variables from a YAML Frontmatter input * @param string $input The input string @@ -72,8 +70,7 @@ public function fetchKeys() */ function FrontMatter($input) { - if (!$this->startsWith($input, $this->yaml_separator)) - { + if (!$this->startsWith($input, $this->yaml_separator)) { # No front matter # Store Content in Final array $final['content'] = $input; @@ -83,9 +80,8 @@ function FrontMatter($input) # Explode Seperators. At most, make three pieces out of the input file $document = explode($this->yaml_separator,$input, 3); - - switch( sizeof($document) ) - { + + switch( sizeof($document) ) { case 0: case 1: // Empty document @@ -102,21 +98,21 @@ function FrontMatter($input) $front_matter = $document[1]; $content = $document[2]; } - + # Parse YAML try { $final = Yaml::parse($front_matter); } catch (ParseException $e) { printf("Unable to parse the YAML string: %s", $e->getMessage()); } - + # Store Content in Final array $final['content'] = $content; - + # Return Final array return $final; } - + /** * A convenience wrapper around strpos to check the start of a string * From http://stackoverflow.com/a/860509/270334 @@ -128,7 +124,7 @@ private function startsWith($haystack,$needle,$case=true) return strpos($haystack, $needle, 0) === 0; return stripos($haystack, $needle, 0) === 0; } - + /** * Read Method, Read file and returns it's contents * @return string $data returned data @@ -137,25 +133,21 @@ protected function Read($file) { # Open File $fh = fopen($file, 'r'); - $fileSize = filesize($file); - - if(!empty($fileSize)) - { + + if(!empty($fileSize)) { # Read Data $data = fread($fh, $fileSize); - + # Fix Data Stream to be the exact same format as PHP's strings $data = str_replace(array("\r\n", "\r", "\n"), "\n", $data); - } - else - { + } else { $data = ''; } - + # Close File fclose($fh); - + # Return Data return $data; }