Skip to content

Commit

Permalink
Merge branch 'xini-pull-ss5'
Browse files Browse the repository at this point in the history
  • Loading branch information
nyeholt committed Sep 13, 2024
2 parents 80b1036 + 546f927 commit a9c91d8
Show file tree
Hide file tree
Showing 16 changed files with 893 additions and 790 deletions.
8 changes: 2 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.
For more information on changes and releases, please visit [Releases](https://github.com/symbiote/silverstripe-components/releases).

This project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0]

* First version.
This project adheres to [Semantic Versioning](http://semver.org/)
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@ This module allows you to use special <:TemplateName> syntax to include template

## Composer Install

**[SilverStripe 3.X](https://github.com/symbiote/silverstripe-components/tree/1)**
```
composer require symbiote/silverstripe-components:~1.0
```

**[SilverStripe 4.X](https://github.com/symbiote/silverstripe-components/tree/master)**
```
composer require symbiote/silverstripe-components:~3.0
composer require symbiote/silverstripe-components
```

## Requirements

* PHP 5.6+
* SilverStripe 4.0+
* SilverStripe ^5

## Documentation

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
}
],
"require": {
"php": ">=5.4",
"silverstripe/framework": "~4.0"
"silverstripe/framework": "^5"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
"squizlabs/php_codesniffer": "^3",
"phpunit/phpunit": "^9"
},
"scripts": {
"phpstan": "bash ../../../vendor/bin/phpstan analyse src/ tests/ -c \".phpstan.neon\" -a \"tests/bootstrap-phpstan.php\" --level 3",
Expand All @@ -38,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
"dev-master": "4.0.x-dev"
}
},
"replace": {
Expand Down
26 changes: 13 additions & 13 deletions docs/en/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ is output as a string. This is necessary in SilverStripe 4 to ensure passing 'ge
$val .= '
';
$_props = array();
$_props['class'] = array();
if ($scope->locally()->hasValue('getAttribute', array('class'), true)) {
$_props['class'][] = $scope->locally()->obj('getAttribute', array('class'), true)->self();
$_props = [];
$_props['class'] = [];
if ($scope->locally()->hasValue('getAttribute', ['class'], true)) {
$_props['class'][] = $scope->locally()->obj('getAttribute', ['class'], true)->self();
}
$_props['class'][] = ' test';
$_props['class'] = Injector::inst()->createWithArgs('Symbiote\Components\DBComponentField', array('class', $_props['class']));
$_props['class'] = Injector::inst()->createWithArgs('Symbiote\Components\DBComponentField', ['class', $_props['class']]);
$val .= Injector::inst()->get('Symbiote\Components\ComponentService')->renderComponent('FormTextInput', $_props, $scope);
unset($_props);
$val .= '
Expand All @@ -85,22 +85,22 @@ $val .= '

**JSON Output:**
```
$_props = array();
$_props['Cards'] = array();
$_props['Cards'][] = new SilverStripe\ORM\ArrayList(array (
$_props = [];
$_props['Cards'] = [];
$_props['Cards'][] = new SilverStripe\ORM\ArrayList([
0 =>
array (
[
'Title' => 'This is the first card',
'Summary' => 'This is the first card summary',
'Link' => 'https://link1.com',
),
],
1 =>
array (
[
'Title' => 'This is the second card',
'Summary' => 'This is the second card summary',
'Link' => 'https://link2.com',
),
));
],
]);
$_props['Cards'] = \SilverStripe\Core\Injector\Injector::inst()->get(Symbiote\Components\ComponentService::class)->createProperty('Cards', $_props['Cards']);
$val .= \SilverStripe\Core\Injector\Injector::inst()->get(Symbiote\Components\ComponentService::class)->renderComponent('JSONSyntaxTest', $_props, $scope);
```
52 changes: 27 additions & 25 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
<?xml version="1.0"?>
<ruleset name="SS3">
<description>Coding standard for SilverStripe 4.x</description>
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<!-- Don't sniff third party libraries -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/thirdparty/*</exclude-pattern>
<file>src</file>
<file>tests</file>

<!-- Show progress and output sniff names on violation, and add colours -->
<arg value="sp"/>
<arg name="colors"/>
<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
</rule>

<!-- Use PSR-2 as a base standard -->
<rule ref="PSR2">
<!-- Allow classes to not declare a namespace -->
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<!-- use short array syntax -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />

<!-- Allow underscores in class names -->
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>

<!-- Allow non camel cased method names -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>

<!-- Ignore this line too long rule -->
<exclude name="Generic.Files.LineLength"/>

<!-- Allow $____name in ComponentData class -->
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
</rule>
<!-- PHP-PEG generated file not intended for human consumption -->
<exclude-pattern>*/SSTemplateParser.php$</exclude-pattern>
<exclude-pattern>*/_fakewebroot/*</exclude-pattern>
<exclude-pattern>*/fixtures/*</exclude-pattern>
</ruleset>
34 changes: 21 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
<?xml version="1.0"?>
<!-- phpunit.xml -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">.</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>sanitychecks</group>
</exclude>
</groups>
</phpunit>
8 changes: 4 additions & 4 deletions src/Symbiote/ArrayListExportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
*
* var_export calls '__set_state' on classes, so it produces code like:
*
* ArrayList::__set_state(array('items' => [...]))
* ArrayList::__set_state(['items' => [...]])
*
* And because ArrayList doens't implement '__set_state', executing the code throws errors.
* So we work around this by using an ArrayListExportable to produce:
*
* ArrayListExportable::__set_state(array('items' => [...]))
* ArrayListExportable::__set_state(['items' => [...]])
*
* And implement '__set_state' to return a constructed ArrayList.
*/
class ArrayListExportable
{
public function __construct($array = array())
public function __construct($array = [])
{
// need to store items for var_export to recurse
$this->items = $array;
}
public static function __set_state ($array)
public static function __set_state($array)
{
// when executed, we naruto-style body-replace with in an ArrayList
return new ArrayList($array['items']);
Expand Down
17 changes: 9 additions & 8 deletions src/Symbiote/Components/ComponentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ class ComponentData extends ViewableData
*/
protected $____name;

protected $____properties;

public function __construct($name, array $props)
{
parent::__construct();

$this->____name = $name;
foreach ($props as $prop => $value) {
$this->____properties[$prop] = $value;
}

// NOTE(Jake): 2018-08-02
//
// Don't allow use of invalid properties.
Expand All @@ -31,23 +38,17 @@ public function __construct($name, array $props)
// - $beforeExtendCallbacks
//
foreach (get_object_vars($this) as $prop => $value) {
if (isset($props[$prop])) {
if (isset($this->____properties[$prop])) {
throw new ComponentReservedPropertyException($name, $prop);
}
}

//
$this->____name = $name;
foreach ($props as $prop => $value) {
$this->{$prop} = $value;
}
}

/**
* Disable default ViewableData __get behaviour.
*/
public function __get($property)
{
return null;
return $this->____properties[$property] ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($componentName, $propertyName)
{
$this->propertyName = $propertyName;
$this->componentName = $componentName;
$message = 'You cannot use the property "'.$propertyName.'" on "'.$componentName.'" as it\'s already used by ViewableData.';
$message = 'You cannot use the property "' . $propertyName . '" on "' . $componentName . '" as it\'s already used by ViewableData.';
parent::__construct($message);
}
}
Loading

0 comments on commit a9c91d8

Please sign in to comment.