A mini-framework for simple websites, such as URL shorteners.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
boggins
bootstrap
controllers
tests/lib
views
.gitignore
LICENSE.md
README.md

README.md

Boggins

A very simple framework for simple websites, such as URL shorteners.

Rationale

Boggins aims to provide a few useful helper classes, basic routing and MVC functionality, all of which are opt-in rather than forcing any particular style or conventions. Modules are designed to be as independent as possible, so that you can delete any parts you don't want, if you like.

Basics

The directory structure is as follows:

- bootstrap
  - bootstrap.php     If you are using the MVC functionality, load in or define routes here, before invoking Core::run()
  - config.php        Optional file for defining constants, configuration settings etc
  - routes.php        Optional file for defining routes if using MVC
- controllers         If you are using MVC, controllers must be placed in this directory
  - MyController.php  Controllers must follow this file name pattern
- boggins                 Contains various static helper classes, plus the MVC files (Core, Controller, View, RoutingException)
  - data              Contains helpers for interacting with data stores (MySQL, FS, Mongo), plus the Entity class, which represents Models.
- views               If you are using MVC, views must be placed in this directory

The full boggins package also includes unit tests, build info and documentation, you may safely ignore or remove these.

If you are just using the static helper classes of Boggins, such as Request, Response and Valid, all you need to do to get started is define a class loader. Here is an example as used in the default bootstrap/bootstrap.php file:

<?php

function __autoload ($class_name)
{
    include dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class_name) . '.php';
}

You can then use \boggins\Response; in classes, or \boggins\Str::escape($string); for example.

MVC

To use routing, Controllers and Views does not require much more setup:

bootstrap/bootstrap.php

<?php

/**
 * Define some routes
 */
\boggins\Core::addRoute(
    '/',
    'static'
);

\boggins\Core::addRoute(
    '/products/(?P<name>[-a-zA-Z]*)',
    'products',
    'view'
);

/**
 * Invoke routes
 */
try {
    \boggins\Core::run();

} catch(\Exception $e) {
    // Catch all, just in case
    header('HTTP 1.1 500 Internal Server Error');

    // Log exception and show some message to user

    exit;
}

controllers/StaticController.php

<?php

class StaticController extends \boggins\Controller
{
    /**
     * Index
     */
    public function indexAction()
    {
        echo 'I am the index.';
    }
}

controllers/ProductsController.php

<?php

class ProductsController extends \boggins\Controller
{
    /**
     * View a product
     */
    public function viewAction()
    {
        $productName = $this->getParam('name');

        echo View::factory('product', compact('productName'))->render();
    }
}

views/product.php

<?php

<p>This is the page for <?php echo $productName; ?>!</p>

The regular expressions for routes are defined raw rather than being processed or tweaked. Named captures such as name in the example above are passed into Controllers as parameters.

<?php

Core::addRoute(
    '/path/from/root/as/regex',
    'controller',
    'action'  // optional, defaults to "index"
);

Helpers

  • Developer: Convenience methods for debugging, error handling, and profiling.
  • Log: Helper class for logging errors and info.
  • Page: Methods to assist in constructing common HTML elements, like meta tags.
  • Request: Assists with HTTP requests.
  • Response: Assists with HTTP responses.
  • Str: Functions for working with Strings.
  • Valid: Functions for determining data validity.

Data Stores and Entities

A set of classes for working with databases and I/O, Stores and Entities are fairly primitive so far, but already provide basic schema enforcement and a simplified API for interacting with MySQL.

For more information check the API docs.

License

Boggins is licensed under the Simplified BSD License.

Thank you for using Boggins!