-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- backport JsonArray, SchemaLockedArray, XArray::getKeys, XArray::toF…
…lattenedArray to php72 without breaking API - switch to github actions
- Loading branch information
1 parent
c700f4a
commit edf0bdb
Showing
56 changed files
with
2,085 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: [ php72 ] | ||
pull_request: | ||
branches: [ php72 ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [7.2, 7.3, 7.4] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Validate dependencies | ||
run: composer validate | ||
|
||
- name: Get dependency cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-php- | ||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run static analysis | ||
run: vendor/bin/phpstan analyse | ||
|
||
- name: Run test suite | ||
run: vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-clover=coverage.xml | ||
|
||
- uses: codecov/codecov-action@v1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
parameters: | ||
bootstrapFiles: | ||
- %currentWorkingDirectory%/_bootstrap.php | ||
checkMissingIterableValueType: false | ||
level: 7 | ||
paths: | ||
- src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* XArray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
namespace modethirteen\XArray\Exception; | ||
|
||
use Exception; | ||
|
||
class SchemaLockedArrayUndefinedKeyException extends Exception { | ||
|
||
/** | ||
* @param string $key | ||
*/ | ||
public function __construct(string $key) { | ||
parent::__construct('Could not set array key not defined in schema: ' . $key); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* XArray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
namespace modethirteen\XArray; | ||
|
||
class JsonArray extends XArray { | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $isPrettyPrintEnabled = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $isUnescapedSlashesEnabled = false; | ||
|
||
/** | ||
* @param string $json | ||
* @return JsonArray | ||
*/ | ||
public static function newJsonArrayFromJson(string $json) : JsonArray { | ||
return new JsonArray(json_decode($json, true)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toJson() : string { | ||
$options = 0; | ||
if($this->isPrettyPrintEnabled) { | ||
$options = $options | JSON_PRETTY_PRINT; | ||
} | ||
if($this->isUnescapedSlashesEnabled) { | ||
$options = $options | JSON_UNESCAPED_SLASHES; | ||
} | ||
$result = $options > 0 ? json_encode($this->array, $options) : json_encode($this->array); | ||
return is_string($result) ? $result : '{}'; | ||
} | ||
|
||
/** | ||
* Remove forward slash escaping with serializing to JSON text | ||
* | ||
* @note slashes should always remain escaped if JSON is embedded in, or contains, HTML | ||
* @return JsonArray | ||
*/ | ||
public function withUnescapedSlashes() : JsonArray { | ||
|
||
// even though this is a clone, we should not create a new array reference - there is no change to the underlying array data | ||
$instance = clone $this; | ||
$instance->isUnescapedSlashesEnabled = true; | ||
return $instance; | ||
} | ||
|
||
/** | ||
* Add line spacing and indentation when serializing to JSON text | ||
* | ||
* @note Even though this is a clone, we should not create a new array reference - there is no change to the underlying array data | ||
* @return JsonArray | ||
*/ | ||
public function withPrettyPrint() : JsonArray { | ||
|
||
// even though this is a clone, we should not create a new array reference - there is no change to the underlying array data | ||
$instance = clone $this; | ||
$instance->isPrettyPrintEnabled = true; | ||
return $instance; | ||
} | ||
} |
Oops, something went wrong.