Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
138 additions
and
5 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,10 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidArgument extends Exception | ||
{ | ||
|
||
} |
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,40 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl\Helpers; | ||
|
||
use Nette\SmartObject; | ||
use Wavevision\PropsControl\Exceptions\InvalidArgument; | ||
use Wavevision\Utils\Strings; | ||
|
||
class Style | ||
{ | ||
|
||
use SmartObject; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private $style = []; | ||
|
||
public function __toString(): string | ||
{ | ||
$style = []; | ||
foreach ($this->style as $key => $value) { | ||
$style[] = Strings::camelCaseToDashCase($key) . ':' . $value; | ||
} | ||
return implode(';', $style); | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function add(string $key, $value): self | ||
{ | ||
if (!is_scalar($value)) { | ||
throw new InvalidArgument(sprintf("Style attribute values must be scalar, '%s' given.", gettype($value))); | ||
} | ||
$this->style[$key] = $value; | ||
return $this; | ||
} | ||
|
||
} |
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
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
6 changes: 3 additions & 3 deletions
6
tests/PropsControlTests/Components/TestComponent/templates/default.latte
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,25 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControlTests\Helpers; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Wavevision\PropsControl\Exceptions\InvalidArgument; | ||
use Wavevision\PropsControl\Helpers\Style; | ||
|
||
class StyleTest extends TestCase | ||
{ | ||
|
||
public function testAdd(): void | ||
{ | ||
$style = new Style(); | ||
$this->assertSame($style, $style->add('key', 1)); | ||
} | ||
|
||
public function testAddThrowsInvalidArgument(): void | ||
{ | ||
$style = new Style(); | ||
$this->expectException(InvalidArgument::class); | ||
$style->add('key', new \stdClass()); | ||
} | ||
|
||
} |
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