bem / bh-php

PHP port of https://github.com/bem/bh. It's cool thing but better use this:
https://github.com/zxqfox/php-fpm-bem-demo-heroku
MIT License
33 stars 8 forks source link

use JSON as argument for apply #1

Closed tadatuta closed 9 years ago

tadatuta commented 9 years ago

I think $BH->apply() should use JSON as an argument or (if it's somehow possible) support both JSON and JS object syntax to have interoperability with current BEMJSON bundles or server responses.

qfox commented 9 years ago

In php you have Arrays and Objects, so for now it supports both (there is temporary conversion from anything to stdObjects tree, because of references). So it should support syntax like

[ 'block' => 'page',
  'styles' => [],
  'content' => [
    'Hello!',
    { 'block' => 'header', 'content' => 'Title' },
    'I\'m here at the end'
  ]
]

So it's almost totally compatible with JS version.

Is this right?

tadatuta commented 9 years ago

Is it possible to call json_decode() if argument was a string?

qfox commented 9 years ago

You mean to pass stringified json instead of arrays or objects? Sure it is.

qfox commented 9 years ago

After a talk with @tadatuta we decided to support this for testing purposes and mocks.

Examples:

// using heredoc notation
$bh->apply(<<<bemjson
{
  block: "page",
  content: [
    'some content here'
    // etc...
  ]
}
bemjson
);

// using standard bemjson files
$bh->apply(trim(trim(file_get_contents('bundles/index/index.bemjson')),"()"));

@tadatuta Please approve it

tadatuta commented 9 years ago

@zxqfox yes, that'd be just great!