2017 © Pedro Peláez
 

silverstripe-module silverstripe-flexibledataformatters

image

heyday/silverstripe-flexibledataformatters

  • Wednesday, August 21, 2013
  • by heyday
  • Repository
  • 24 Watchers
  • 3 Stars
  • 862 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

Flexible Data Formatters

Provides a way to easily format a selection of a DataObject's fields used in a custom API. This is often useful when creating your own RESTful API that doesn't use SilverStripes RestfulServer, (*1)

For a SilverStripe 2.4 compatible version see the branch 0.2., (*2)

Installation (with composer)

$ composer require heyday/silverstripe-flexibledataformatters:~0.1

Usage

class MyDataObject extends DataObject implements FlexibleDataFormatterInterface
{
    public static $db = array(
        'Title' => 'Varchar(255)'
    );

    public function getReadableFields()
    {
        return array(
            'Title'
        );
    }

    public function getDynamicFields()
    {
        return array();
    }
}

$dataObject = new MyDataObject(array('Title' => 'Hello'));
$formatter = new FlexibleJsonDataFormatter();
echo $formatter->convertDataObject($dataObject);

//  Results:
//  {
//      "Title": "Hello"
//  }

Unit testing

Install dev dependencies from within module:, (*3)

silverstripe-flexibledataformatters/ $ composer install --dev

Use standard phpunit command, (*4)

silverstripe-flexibledataformatters/ $ phpunit

If you don't have phpunit installed globally:, (*5)

silverstripe-flexibledataformatters/ $ vendor/bin/phpunit

License

Flexible Data Formatters is licensed under an MIT license, (*6)

The Versions