2017 © Pedro Peláez
 

library markaround

image

jamesflight/markaround

  • Monday, September 14, 2015
  • by jamesflight
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Markaround

Build Status, (*1)

Markaround is a PHP library for interacting with directories of Markdown files as if they were a read only database, and imitates the syntax of Eloquent ORM from Laravel., (*2)

The purpose of this is to make it super easy to create blogs and document readers in PHP with no database, using directories of markdown files instead., (*3)

Bootstrapping

Creating a new instance: <?php, (*4)

$config = [
    'default_path' => 'path/to/markdown/files'
];

$markaround = Jamesflight\Markaround\Factory::create($config);

Usage

Saving Markdown files:

Markdown files should be saved with one of the following naming conventions:, (*5)

File retrievable by slug:, (*6)

file-slug.md, (*7)

File retrievable by id:, (*8)

01_.md, (*9)

File retrievable by date:, (*10)

2001-01-01.md, (*11)

These can be combined in any combination, in the order id, date, slug:, (*12)

01_2001-01-01-file-slug.md, (*13)

01_file-slug.md, (*14)

2001-01-01-file-slug.md, (*15)

Retrieving files:

Retrieving all files:, (*16)

$posts = $markaround->all();

Retrieving a file by id:, (*17)

$posts = $markaround->find(1);
$posts = $markaround->findOrFail(1); // Throws a MarkdownFileNotFoundException if not found

Retrieving files by date, (*18)

Note: any valid PHP datetime format can be used., (*19)

$posts = $markaround->where('date', '1st January 2015')->get();

Retrieving files by slug, (*20)

$posts = $markaround->where('slug', 'file-slug')->get();

Retrieving the first entry from the result collection, (*21)

$post = $markaround->where('date', '1st January 2015')->first();
$post = $markaround->where('date', '1st January 2015')->firstOrFail(); // Throws a MarkdownFileNotFoundException if not found

Retrieving where one condition or another is true, (*22)

$post = $markaround->where('id', 1)
            ->orWhere('id', 2)
            ->get();

Comparison operators

You can provide a comparison operator as the second argument in a where (or orWhere) query:, (*23)

$posts = $markaround->where('id', '=', 1)->first();

Available operators are:, (*24)

Equal to: =, (*25)

Not equal to: !=, (*26)

Less than: <, (*27)

Greater than: >, (*28)

Greater than or equal to: >=, (*29)

Less than or equal to: <=, (*30)

Here are some examples of their use:, (*31)

$posts = $markaround->where('id', '!=', 1)->get();
$posts = $markaround->where('date', '>=', '1st January 2015')->get();

Custom Fields

At the top of each markdown file, you have the option of adding extra fields using YAML that you can also query by:, (*32)

---
foofield: foo
barfield: bar
---
Markdown goes here

Supplying these custom fields allows for the following:, (*33)

$posts = $markdown->where('foofield', '=', 'foo')->first();

The Versions