2017 © Pedro Peláez
 

library common

Utility module with Soflomo common classes

image

soflomo/common

Utility module with Soflomo common classes

  • Tuesday, November 4, 2014
  • by juriansluiman
  • Repository
  • 4 Watchers
  • 2 Stars
  • 602 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Soflomo\Common

Soflomo\Common is a small utility module with a few helper classes. Its purpose is to provide some plugin/helper classes to provide functionalities common for many different projects., (*1)

At this moment, it provides the following classes:, (*2)

  • Accept controller plugin, to check specific content types in the request
  • Attachment controller plugin, to send a file as attachment in the response
  • Version view helper, to load the version of the application from git as a cache buster in public assets

Installation

Soflomo\Common is available through composer. Add "soflomo/common" to your composer.json list. During development of Soflomo\Common, you can specify the latest available version:, (*3)

"soflomo/common": "dev-master"

Enable the module in your config/application.config.php file. Add an entry Soflomo\Common to the list of enabled modules., (*4)

Usage

Example of usage is listed below for every single helper class., (*5)

Accept controller plugin

Say you perform a delete request to the uri /books/123. An AJAX request might expect a 200 OK with a body message, while for a normal request you want to redirect to /books again., (*6)

// Remove the book with id 123

if ($this->accept('application/json')) {
    return new JsonModel(array(
        'status' => 'success',
        'book'   => array(
            'id' => 123
        )
    ));
}

return $this->redirect()->toRoute('books');

Attachment controller plugin

You have created a pdf file and you want to let the user download that file., (*7)

return $this->attachment()
            ->fromFile('data/invoice/123.pdf', 'Invoice 123.pdf', 'application/pdf');

Available methods are fromFile($path, $name=null, $type=null, $disposition=null) and fromBlob($blob, $name, $type=null, $disposition=null). A fromStream() method is not implemented yet, but is planned in a future version., (*8)

Version view helper

For all styles, images and javascript files, a new deployed version might be changed but is available under the same URI. You want to force a reload as a cache busting mechanism, but you do not want to update the version manually each time., (*9)

This view helper loads a version description from git with git describe --always. For a tag it will return the tag (e.g. v.1.0.4). If no tag is checked out (for example, on your staging environment) it loads a mixed version (e.g. v1.0.4-14-g2414721 or when nothing has been tagged g2414721). The version can be appended as query string: css/style.css?v1.0.4:, (*10)

<?php echo $this->headLink()
                ->appendStylesheet($this->basePath() . 'css/style.css?' . $this->version()); ?>

The Versions

04/11 2014

dev-master

9999999-dev https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

04/11 2014

v0.8.0

0.8.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

05/03 2014

v0.7.0

0.7.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

05/02 2014

v0.6.0

0.6.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

11/11 2013

dev-hotfix/menu-depth-recursive

dev-hotfix/menu-depth-recursive https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

13/09 2013

v0.5.0

0.5.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

29/04 2013

v0.4.1

0.4.1.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

23/04 2013

v0.4.0

0.4.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

23/04 2013

v0.3.1

0.3.1.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

20/04 2013

v0.3.0

0.3.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

09/04 2013

v0.2.0

0.2.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2

14/03 2013

v0.1.0

0.1.0.0 https://github.com/Soflomo/Common

Utility module with Soflomo common classes

  Sources   Download

BSD-3-Clause

The Requires

 

zf2