Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamielsharief committed Oct 12, 2019
0 parents commit eb2e65a
Show file tree
Hide file tree
Showing 13 changed files with 1,061 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: clover.xml # file generated by phpunit
json_path: coverage.json # file generated by php-coveralls
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/tests export-ignore
/phpunit.xml.dist export-ignore
/phpcs.xml.dist export-ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
composer.lock
phpunit.xml
.phpunit.result.cache
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: php
php:
- 7.2
- 7.3
- 7.4snapshot
dist: xenial
before_script:
- composer install --prefer-source --no-interaction
script:
- vendor/bin/phpunit --coverage-clover=clover.xml
after_script:
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
- php php-coveralls.phar --verbose
cache:
directories:
- $HOME/.composer/cache/files
after_success:
- bash <(curl -s https://codecov.io/bash)
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2019-10-12

This component has been decoupled from the [OriginPHP framework](https://www.originphp.com/).
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2019] [Jamiel Sharief]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Yaml

![license](https://img.shields.io/badge/license-MIT-brightGreen.svg)
[![build](https://travis-ci.org/originphp/yaml.svg?branch=master)](https://travis-ci.org/originphp/yaml)
[![coverage](https://coveralls.io/repos/github/originphp/yaml/badge.svg?branch=master)](https://coveralls.io/github/originphp/yaml?branch=master)


The YAML utility is for reading (parsing) and writing YAML files.

> The YAML utility does not cover the complete specification, it is designed to read and write configuration files, and data from the database so that it can be read and edited in user friendly way.
## Installation

To install this package

```linux
$ composer require originphp/yaml
```

## Create a YAML string

```php
use Origin\Yaml\Yaml;
$employees = [
['name'=>'Jim','skills'=>['php','mysql','puppeteer']],
['name'=>'Amy','skills'=>['ruby','ruby on rails']],
];
$yaml = Yaml::fromArray($employees );
```

That will return the following

```yaml
- name: Jim
skills:
- php
- mysql
- puppeteer
- name: Amy
skills:
- ruby
- ruby on rails
```

Here is an example converting a record using the Bookmark model

```php
$bookmark = $this->Bookmark->get(1,[
'associated'=>[
'User','Tag'
]
]);
$string = Yaml::fromArray($bookmark->toArray());

```

This will create the following YAML string:

```yaml
id: 1
user_id: 1
title: OriginPHP
description: The PHP framework for rapidly building scalable web applications.
url: https://www.originphp.com
category: Computing
created: 2018-12-28 15:25:34
modified: 2019-05-02 13:08:44
user:
id: 1
name: Demo User
email: demo@example.com
password: $2y$10$/clqxdb.aWe43VXDUn8tA.yxKbWHZT3rN7gqITFaj32PZHI3.DkzW
dob: 1999-12-28
created: 2018-12-28 15:24:13
modified: 2018-12-28 15:24:13
tags:
- id: 1
title: Framework
created: 2019-03-07 18:45:43
modified: 2019-03-07 18:45:43
bookmarksTag:
bookmark_id: 1
tag_id: 1
- id: 2
title: PHP
created: 2019-03-07 18:45:43
modified: 2019-03-07 18:45:43
bookmarksTag:
bookmark_id: 1
tag_id: 2
tag_string: Framework,PHP
```

## Read YAML

To create an array from a YAML string

```php
$employee = 'name: Tom
position: developer
skills:
- php
- mysql
- js
addresses:
- street: 14 some road
city: london
- street: 21 some avenue
city: leeds
summary:
this is a text description
for this employee';
$array = Yaml::toArray($employee);
/*
Array
(
[name] => Tom
[position] => developer
[skills] => Array
(
[0] => php
[1] => mysql
[2] => js
)

[addresses] => Array
(
[0] => Array
(
[street] => 14 some road
[city] => london
)

[1] => Array
(
[street] => 21 some avenue
[city] => leeds
)

)

[summary] => this is a text description for this employee
)
*/
```
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "originphp/yaml",
"description": "OriginPHP Yaml",
"type": "library",
"keywords": [
"originphp",
"yaml",
"parser"
],
"homepage": "https://www.originphp.com",
"license": "MIT",
"authors": [
{
"name": "Jamiel Sharief",
"email": "js@originphp.com"
}
],
"autoload": {
"psr-4": {
"Origin\\Yaml\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Origin\\Test\\Yaml\\": "tests/"
}
},
"require": {
"php": "^7.2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
}
}
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="OriginPHP">
<description>The coding standard for OriginPHP.</description>
<rule ref="PSR2"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
</ruleset>
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
backupGlobals="true"
>
<testsuites>
<testsuite name="OriginPHP Yaml">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<const name="PHPUNIT" value="true"/>
<env name="ORIGIN_ENV" value="test"/>
</php>
</phpunit>
22 changes: 22 additions & 0 deletions src/Exception/YamlException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types = 1);
/**
* OriginPHP Framework
* Copyright 2018 - 2019 Jamiel Sharief.
*
* Licensed under The MIT License
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* @copyright Copyright (c) Jamiel Sharief
* @link https://www.originphp.com
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

namespace Origin\Yaml\Exception;

use \Exception;

class YamlException extends Exception
{
}

0 comments on commit eb2e65a

Please sign in to comment.