generated from yii-tools/template
-
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.
Add
HasDataValue::class
trait. (#262)
- Loading branch information
1 parent
4eb897b
commit d4ef12a
Showing
8 changed files
with
108 additions
and
32 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
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Attribute\Custom; | ||
|
||
/** | ||
* Is used by widgets that implement the data value method. | ||
*/ | ||
trait HasDataValue | ||
{ | ||
protected string $dataValue = ''; | ||
|
||
/** | ||
* Set the `HTML` data-value attribute for the toggle. | ||
* | ||
* @param string $value The data-value attribute value. | ||
* | ||
* @return static A new instance of the current class with the specified toggle attributes. | ||
*/ | ||
public function dataValue(string $value): static | ||
{ | ||
$new = clone $this; | ||
$new->dataValue = $value; | ||
return $new; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Attribute\Custom; | ||
|
||
use PHPForge\Html\Attribute\Custom\HasDataValue; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HasDataValueTest extends TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use HasDataValue; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->dataValue('')); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests; | ||
|
||
use PHPForge\Html\ButtonToggle; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class Method extends TestCase | ||
{ | ||
public function testPrintMethods(): void | ||
{ | ||
$methods = get_class_methods(ButtonToggle::class); | ||
|
||
sort($methods); | ||
var_dump(implode("\n", $methods)); | ||
die; | ||
} | ||
} |