Skip to content

Commit

Permalink
Merge pull request skrz#13 from jakubkulhan/feature-fields
Browse files Browse the repository at this point in the history
Fields - composite set of fields/properties
  • Loading branch information
mzstic committed Feb 18, 2016
2 parents e57de97 + b108edf commit ff8af1b
Show file tree
Hide file tree
Showing 48 changed files with 1,090 additions and 61 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Requirements

`Skrz\Meta` requires PHP `>= 5.3.0` and Symfony `>= 2.7.0`.
`Skrz\Meta` requires PHP `>= 5.4.0` and Symfony `>= 2.7.0`.

## Installation

Expand Down Expand Up @@ -166,6 +166,40 @@ var_export($someCategory->name === "Some category");
// TRUE
```

### Fields

- Fields represent set of symbolic field paths.
- They are composite (fields can have sub-fields).
- Fields can be supplied as `$filter` parameters in `to*()` methods.

```php
use Skrz\API\Category;
use Skrz\API\Meta\CategoryMeta;
use Skrz\Meta\Fields\Fields;

$parentCategory = new Category();
$parentCategory->name = "The parent category";
$parentCategory->slug = "parent-category";

$childCategory = new Category();
$childCategory->name = "The child category";
$childCategory->slug = "child-category";
$childCategory->parentCategory = $parentCategory;


var_export(CategoryMeta::toArray($childCategory, null, Fields::fromString("name,parentCategory{name}")));
// array(
// "name" => "The child category",
// "parentCategory" => array(
// "name" => "The parent category",
// ),
// )
```

Fields are inspired by:

- [Facebook Graph API's `?fields=...` query parameter](https://developers.facebook.com/docs/graph-api/using-graph-api#fields)
- [Google Protocol Buffers' `FieldMask`](https://github.com/google/protobuf/blob/master/src/google/protobuf/field_mask.proto) (and its [JSON serialization](https://developers.google.com/protocol-buffers/docs/proto3#json))

### Annotations

Expand Down
2 changes: 2 additions & 0 deletions bin/generate-reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public function aMethod($aParameter = AClass::A_CONSTANT, AnInterface $anotherPa
$method->getName() !== "getStaticProperties" &&
$method->getName() !== "isCloneable" &&
$method->getName() !== "isVariadic" &&
$method->getName() !== "getType" && // TODO: PHP 7
$method->getName() !== "isAnonymous" && // TODO: PHP 7
// $method->getName() !== "getDefaultProperties" &&
(strncmp($method->getName(), "get", 3) === 0 || ($is = (strncmp($method->getName(), "is", 2) === 0))) &&
($method->getNumberOfParameters() === 0 || $method->getName() === "getProperties" || $method->getName() === "getMethods")
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
}
],
"require": {
"php": ">=5.3",
"php": ">=5.4",
"doctrine/annotations": "~1.2",
"nette/php-generator": "~2.3",
"symfony/finder": "~2.7",
"symfony/console": "~2.7"
"symfony/finder": "~2.7|~3.0",
"symfony/console": "~2.7|~3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/DescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/EnumDescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/EnumOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/EnumValueOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/FieldDescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/FieldOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/FileDescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/FileDescriptorSetMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/FileOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/MessageOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/MethodDescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/MethodOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/OneofDescriptorProtoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/ServiceOptionsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/SourceCodeInfoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
2 changes: 1 addition & 1 deletion gen-src/Google/Protobuf/Meta/UninterpretedOptionMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function fromArray($input, $group = NULL, $object = NULL)
*
* @return array
*/
public static function toArray($object, $group = NULL, array $filter = NULL)
public static function toArray($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -275,7 +275,7 @@ public static function fromObject($input, $group = NULL, $object = NULL)
*
* @return object
*/
public static function toObject($object, $group = NULL, array $filter = NULL)
public static function toObject($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -393,7 +393,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function fromArray($input, $group = NULL, $object = NULL)
*
* @return array
*/
public static function toArray($object, $group = NULL, array $filter = NULL)
public static function toArray($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -276,7 +276,7 @@ public static function fromObject($input, $group = NULL, $object = NULL)
*
* @return object
*/
public static function toObject($object, $group = NULL, array $filter = NULL)
public static function toObject($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -393,7 +393,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function fromArray($input, $group = NULL, $object = NULL)
*
* @return array
*/
public static function toArray($object, $group = NULL, array $filter = NULL)
public static function toArray($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -275,7 +275,7 @@ public static function fromObject($input, $group = NULL, $object = NULL)
*
* @return object
*/
public static function toObject($object, $group = NULL, array $filter = NULL)
public static function toObject($object, $group = NULL, $filter = NULL)
{
if ($object === null) {
return null;
Expand Down Expand Up @@ -391,7 +391,7 @@ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end =
*
* @return string
*/
public static function toProtobuf($object, array $filter = NULL)
public static function toProtobuf($object, $filter = NULL)
{
$output = '';

Expand Down
Loading

0 comments on commit ff8af1b

Please sign in to comment.