ZenstruckGithubBundle

Enables a Github repository to become the host of static content for your cms.

Introduction

Enables a Github repository to become the host of static content for your cms.

Requirements

Installation

  1. Add this bundle and php-github-api to your Symfony2 project:

     $ git submodule add git://github.com/kbond/GithubBundle.git vendor/bundles/Zenstruck/GithubBundle
     $ git submodule add git://github.com/ornicar/php-github-api.git vendor/php-github-api
    
  2. Add the Zenstruck namespace to your autoloader:

     // app/autoload.php
     $loader->registerNamespaces(array(
        'Zenstruck' => __DIR__.'/../vendor/bundles',
        // your other namespaces
     ));
    
  3. Add the Github prefix to your autoloader:

     // app/autoload.php
     $loader->registerPrefixes(array(
         'Github_'            => __DIR__.'/../vendor/php-github-api/lib'
         // your other prefixes
     ));
    
  4. Add this bundle to your application's kernel:

     // app/AppKernel.php
      public function registerBundles()
      {
          return array(
              // ...
              new Zenstruck\Bundle\GithubBundle\ZenstruckGithubBundle(),
              // ...
          );
      }
    

Configuration

# app/config/config.yml
zenstruck_github:
    user: # the github username
    repo: # the github reponame
    branch: master # git branch

Usage

// get service
$repo = $this->get('zenstruck.github.filesystem');

// get file from repo (extension required)
$index = $repo->getFile('index.md');

$contents = $index->getContent();

// get a file from (extension not required)
$index = $repo->getMatchingFile('index');

$contents = $index->getContent();

// get file list
$files = $repo->getFileList();

// get file list in subdir
$files = $repo->getFileList('subdir');

Todo

  • Controller to publish content file based on a github path
  • Allow deeper levels (need slashes in route params - not sure how to do this)
  • Cache?

Copyright (c) Kevin Bond

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.