Add Litlab

This commit is contained in:
Yevhen Odynets 2025-07-04 13:35:51 +03:00
parent 1cf6e3d7d2
commit dabbf541dc
17 changed files with 159 additions and 17 deletions

3
Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM php:8.3-cli-alpine3.22
ENTRYPOINT ["php", "-S", "localhost:8008", "-t", "public/"]

12
code/decorator.php Normal file
View File

@ -0,0 +1,12 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:39
*/
declare(strict_types = 1);
dump('Decorator');

View File

@ -36,5 +36,5 @@ function client(): void
/** @noinspection ForgottenDebugOutputInspection */
dump($draft);
}
?><img class="diagram" src="/assets/img/diagrams/prototype.png" alt="Adapter DEsign Pattern Diagram"><?php
client();

View File

@ -16,7 +16,7 @@ use Pattern\Creational\{Singleton\Single, Singleton\Singleton};
*
* @noinspection ForgottenDebugOutputInspection
*/
function clientCode(): void
function client(): void
{
$output = [
'where' => trace(),
@ -36,7 +36,8 @@ function clientCode(): void
dump($output, $output['s1']->getValue(), $output['s2']->getValue());
}
clientCode();
?><img class="diagram" src="/assets/img/diagrams/singleton.png" alt="Adapter DEsign Pattern Diagram"><?php
client();
$single = Single::getInstance('from subclass');
$single->setValue('value set from Single::class')->childish();

View File

@ -13,8 +13,7 @@
],
"require": {
"php": "8.3.*",
"ext-simplexml": "*",
"ext-yaml": "*"
"ext-simplexml": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.76"

7
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8d4ed5a63e8da7821980256ec54097f7",
"content-hash": "15fcc4c375fa23daddd63652d90fdeab",
"packages": [],
"packages-dev": [
{
@ -2544,7 +2544,10 @@
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {},
"platform": {
"php": "8.3.*",
"ext-simplexml": "*"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -41,25 +41,28 @@ require '../src/helpers.php';
transform: translate(-50%, -50%);
max-height: 92dvh;
overflow-y: auto;
background-color: attr(data-color type(<color>), #eef0f0);
background-color: attr(data-color type(< color >), #eef0f0);
}
pre, code {
font-family: Consolas, monospace;
font-size: 1.125rem;
}
pre {
align-self: center;
}
img.diagram {
display: block;
max-width: 100%;
margin: 0 auto 1rem;
}
.et {
position: absolute;
top: .5rem;
left: .5rem;
bottom: .5rem;
right: .5rem;
font-size: small;
font-weight: 500;
color: #333;
@ -68,12 +71,10 @@ require '../src/helpers.php';
</head>
<body>
<main data-color="#eef0f0">
<?php require '../src/router.php' ?>
<?php
require '../src/router.php' ?>
</main>
<div class="et">ET: <?= (microtime(true) - $time_start) ?> secs</div>
<script>hljs.highlightAll()</script>
</body>
</html>

View File

@ -0,0 +1,22 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:42
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
class BorderDecorator implements ShapeInterface
{
public function __construct(private ShapeInterface $shape) {}
public function draw(): void
{
echo '<div style="width: 8rem; height: 8rem; border: .5rem solid orange"></div>';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:41
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
class Circle implements ShapeInterface
{
public function draw(): void
{
// TODO: Implement draw() method.
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:43
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
class EmailDecorator implements ShapeInterface
{
public function __construct(private ShapeInterface $shape) {}
public function draw(): void
{
// TODO: Implement draw() method.
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:38
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
interface ShapeInterface
{
public function draw(): void;
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:47
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
class SmileDecorator implements ShapeInterface
{
public function __construct(private ShapeInterface $shape) {}
public function draw(): void
{
// TODO: Implement draw() method.
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 10:41
*/
declare(strict_types = 1);
namespace Pattern\Structural\Decorator;
class Square implements ShapeInterface
{
public function draw(): void
{
// TODO: Implement draw() method.
}
}

View File

@ -9,7 +9,7 @@
declare(strict_types = 1);
namespace Pattern\Creational\Singleton;
namespace RefactoringGuru\Builder\RealWorld\singleton;
interface Loggable
{

View File

@ -12,7 +12,7 @@
declare(strict_types = 1);
namespace Pattern\Creational\Singleton;
namespace RefactoringGuru\Builder\RealWorld\singleton;
use RuntimeException;