Skip to content

Commit 67c0b1a

Browse files
author
Celano, Jose
committed
first commit
0 parents  commit 67c0b1a

15 files changed

+544
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/tests/ export-ignore
2+
/.editorconfig export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/.php_cs export-ignore
6+
/.styleci.yml export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build/
2+
doc/_build/
3+
vendor/
4+
composer.lock
5+
phpunit.xml
6+
.idea/

.php_cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';
4+
5+
use SLLH\StyleCIBridge\ConfigBridge;
6+
7+
return ConfigBridge::create();

.scrutinizer.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filter:
2+
paths: [src/*]
3+
checks:
4+
php:
5+
code_rating: true
6+
duplication: true
7+
tools:
8+
external_code_coverage: true

.styleci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
preset: symfony
2+
3+
finder:
4+
path:
5+
- "src"
6+
- "tests"
7+
8+
enabled:
9+
- short_array_syntax

.travis.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
language: php
2+
3+
sudo: false
4+
5+
addons:
6+
apt_packages:
7+
- enchant
8+
9+
cache:
10+
directories:
11+
- $HOME/.cache/pip
12+
- $HOME/.composer/cache/files
13+
14+
php:
15+
- 5.5
16+
- 5.6
17+
- 7.0
18+
- 7.1
19+
- hhvm
20+
21+
env:
22+
global:
23+
- TEST_COMMAND="composer test"
24+
25+
branches:
26+
except:
27+
- /^analysis-.*$/
28+
29+
matrix:
30+
fast_finish: true
31+
include:
32+
- php: 5.5
33+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest --ignore-platform-reqs" COVERAGE=true TEST_COMMAND="composer test-ci"
34+
35+
before_install:
36+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
37+
38+
install:
39+
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
40+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
41+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
42+
- pip install --user -r doc/requirements.txt
43+
44+
script:
45+
- $TEST_COMMAND
46+
- make -C doc SPHINXOPTS='-nW' html
47+
- make -C doc spelling
48+
49+
after_success:
50+
- if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
51+
- if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/unit_coverage.xml; fi

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change Log
2+
3+
## 1.0.0 - 2017-03-24
4+
5+
### Added
6+
7+
- First commit

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2011-2016 Jose Celano
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Object
2+
3+
[![Latest Version](https://img.shields.io/github/release/josecelano/php-object-literal.svg?style=flat-square)](https://github.com/josecelano/php-object-literal/releases)
4+
[![Build Status](https://img.shields.io/travis/josecelano/php-object-literal.svg?style=flat-square)](https://travis-ci.org/josecelano/php-object-literal)
5+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/josecelano/php-object-literal.svg?style=flat-square)](https://scrutinizer-ci.com/g/josecelano/php-object-literal)
6+
[![Quality Score](https://img.shields.io/scrutinizer/g/josecelano/php-object-literal.svg?style=flat-square)](https://scrutinizer-ci.com/g/josecelano/php-object-literal)
7+
[![Total Downloads](https://img.shields.io/packagist/dt/josecelano/php-object-literal.svg?style=flat-square)](https://packagist.org/packages/josecelano/php-object-literal)
8+
9+
[![Email](https://img.shields.io/badge/email-josecelano@gmail.com-blue.svg?style=flat-square)](mailto:josecelano@gmail.com)
10+
11+
PHP 5.5+ library to create object literals like JavaScript or Ruby.
12+
13+
Creating object literals in PHP is not as easy (or elegant) as in JavaScript or Ruby.
14+
15+
You can create object literals this way:
16+
17+
``` php
18+
$object = new Object([
19+
"name" => "Fido",
20+
"barks" => true,
21+
"age" => 10
22+
]);
23+
```
24+
25+
instead of:
26+
27+
``` php
28+
$object = new Object();
29+
$object->name = 'Fido';
30+
$object->barks = true;
31+
$object->age = 10;
32+
```
33+
34+
This class was inspired by these two blog posts:
35+
36+
* https://www.sitepoint.com/php-vs-ruby-lets-all-just-get-along/
37+
* https://www.phpied.com/javascript-style-object-literals-in-php/
38+
39+
In fact, there is am old PHP RFC (2011-06-04) which have not been completely implemented:
40+
41+
* https://wiki.php.net/rfc/objectarrayliterals
42+
43+
This class could be used while the RFC is not implemented.
44+
45+
46+
## Install
47+
48+
Via Composer
49+
50+
``` bash
51+
$ composer require josecelano/php-object-literal
52+
```
53+
54+
## Features
55+
56+
- Build from array.
57+
- Build from json.
58+
- Build from json with dynamic keys and values.
59+
60+
## Documentation
61+
62+
Please see the [official documentation](http://moneyphp.org).
63+
64+
65+
## Testing
66+
67+
I try to follow TDD, as such I use [phpunit](https://phpunit.de) to test this library.
68+
69+
``` bash
70+
$ composer test
71+
```
72+
73+
## TODO
74+
75+
- Add magic getters and setters.
76+
- Allow to replace variable values in Json like JavaScript:
77+
From:
78+
```php
79+
$object = new Object("{
80+
\"name\" : \"" . $valueForName . "\",
81+
\"barks\" : true,
82+
\"age\" : 10
83+
}");
84+
```
85+
To:
86+
```php
87+
$object = new Object('{
88+
"name" : $valueForName,
89+
"barks" : true,
90+
"age" : 10
91+
}', get_defined_vars());
92+
```
93+
Replacing `$valueForName` by its value.
94+
- Allow current invalid PHP json formats.
95+
```php
96+
$invalidJson1 = "{ 'bar': 'baz' }";
97+
$invalidJson2 = '{ bar: "baz" }';
98+
$invalidJson3 = '{ bar: "baz", }';
99+
```
100+
- Add callable in json format.
101+
- Allow property value shorthand like ES6:
102+
```php
103+
$object = new Object('{
104+
$name,
105+
$barks,
106+
$age
107+
}', get_defined_vars());
108+
```
109+
110+
## License
111+
112+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

0 commit comments

Comments
 (0)