Skip to content

Commit

Permalink
[16] Architecture patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
atlance committed Aug 4, 2023
1 parent cee20e9 commit 878fe0a
Show file tree
Hide file tree
Showing 55 changed files with 1,639 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .env.dev.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# app.
SERVER_NAME=localhost
APP_NAME=otus/architecture-patterns
APP_ENV=dev
APP_VERSION=0.0.1
APP_DIR=/app
# php.
PHP_VERSION=8.1.5
PHP_CLI_IMAGE=php:${PHP_VERSION}-cli-alpine
PHP_IDE_CONFIG=serverName=${SERVER_NAME}
XDEBUG_MODE=develop,debug,coverage
XDEBUG_TRIGGER=1
# docker.
COMPOSE_DOCKER_CLI_BUILD=1
DOCKER_BUILDKIT=1
USER=1000
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
**/.*

!.github

!app
app/vendor
app/var
app/composer.lock
app/coverage.xml

!docker
!make
!docs

!Makefile
!phpcs.xml
!.gitignore
!docker-compose.*.yml
docker-compose.yml

**.cache
**.env
!.*.dist
!*.dist
!**.md
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$(shell cp -n .env.dev.dist .env)

include ./.env
export $(shell sed 's/=.*//' ./.env)

-include ./make/${APP_ENV}/*.mk

RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)

env:
cp .env.${RUN_ARGS}.dist .env

init: ## Build & run app developments containers.
@make env ${RUN_ARGS}
@make docker-compose ${RUN_ARGS}
@make docker-build
@make docker-up
@make composer-install

down-clear: ## Down service and remove volumes.
docker-compose down --remove-orphans -v
rm -rf ./app/var/*

.PHONY: help

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-12s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# PHP_2022
# PHP_2022

#### Домашние задания:

16. [Паттерны проектирования.](./docs/hw16.md)
21 changes: 21 additions & 0 deletions app/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

require dirname(__DIR__) . '/vendor/autoload.php';

use App\Application;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

$containerBuilder = new ContainerBuilder();

$loader = new YamlFileLoader($containerBuilder, new FileLocator(dirname(__DIR__) . '/config'));
$loader->import('*.yaml');

$containerBuilder->compile(true);

$containerBuilder->get(Application::class)->run();
73 changes: 73 additions & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"name": "atlance/architecture-patterns",
"description": "Course of «PHP Developer. Professional» from OTUS. Homework.",
"license": "MIT",
"type": "project",
"authors": [
{
"name": "Anton Stepanov",
"email": "[email protected]"
}
],
"require": {
"php": "^8.1",
"symfony/config": "^6.3",
"symfony/console": "^6.3",
"symfony/dependency-injection": "^6.3",
"symfony/mime": "^6.3",
"symfony/yaml": "^6.3"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.30",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.0",
"vimeo/psalm": "^5.8"
},
"autoload": {
"psr-4": {
"App\\": "src/",
"App\\Exceptions\\": "exceptions"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"php-http/discovery": true,
"phpstan/extension-installer": true,
"symfony/runtime": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.3.*"
}
},
"scripts": {
"all": [
"@php-analyze",
"@test"
],
"php-analyze": [
"@phpstan",
"@psalm"
],
"phpstan": "vendor/bin/phpstan analyse --no-progress",
"psalm": "vendor/bin/psalm",
"test": "XDEBUG_MODE=coverage vendor/bin/phpunit"
}
}
38 changes: 38 additions & 0 deletions app/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
parameters:

services:
_defaults:
autowire: true
autoconfigure: true

_instanceof:
Symfony\Component\Console\Command\Command:
tags:
- { name: 'console.command' }

App\Infrastructure\Cli\DirectoryTree\View\Contract\PresentationTagInterface:
tags: [ 'app.cli.directory_tree_presenter' ]

App\Infrastructure\Cli\DirectoryTree\View\File\Content\Contract\ContentTagFetcherInterface:
tags: [ 'app.cli.directory_tree_content' ]


App\:
resource: './../src'

App\Infrastructure\Cli\DirectoryTree\View\File\Content\Contract\ContentFetcherInterface:
class: App\Infrastructure\Cli\DirectoryTree\View\File\Content\Fetcher
arguments:
$handlers: !tagged_locator { tag: 'app.cli.directory_tree_content', default_index_method: 'tag' }

App\Infrastructure\Cli\DirectoryTree\View\Contract\PresentationInterface:
class: App\Infrastructure\Cli\DirectoryTree\View\Presenter
arguments:
$presenters: !tagged_locator { tag: 'app.cli.directory_tree_presenter', default_index_method: 'tag' }

App\Application:
public: true
arguments:
$commands: !tagged 'console.command'
$name: '%env(APP_NAME)%'
$version: '%env(APP_VERSION)%'
18 changes: 18 additions & 0 deletions app/exceptions/Assert/Assert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Exceptions\Assert;

final class Assert
{
public static function match(string $pattern, string $value, ?string $message = null): void
{
Regexp\RegexpMatch::assert($pattern, $value, $message);
}

public static function dir(string $value, ?string $message = null): void
{
FileStorage\Directory::assert($value, $message);
}
}
18 changes: 18 additions & 0 deletions app/exceptions/Assert/FileStorage/Directory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Exceptions\Assert\FileStorage;

use App\Exceptions\UnexpectedValueException;

class Directory
{
public static function assert(string $value, ?string $message = null): void
{
if (!is_dir($value)) {
$message ??= sprintf('%s is not a directory.', $value);
throw new UnexpectedValueException($message);
}
}
}
18 changes: 18 additions & 0 deletions app/exceptions/Assert/Regexp/RegexpMatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Exceptions\Assert\Regexp;

use App\Exceptions\UnexpectedValueException;

class RegexpMatch
{
public static function assert(string $pattern, string $value, ?string $message = null): void
{
if (false === preg_match($pattern, $value)) {
$message ??= sprintf('The value %s does not match the expected pattern.', $pattern);
throw new UnexpectedValueException($message);
}
}
}
9 changes: 9 additions & 0 deletions app/exceptions/UnexpectedValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace App\Exceptions;

class UnexpectedValueException extends \RuntimeException
{
}
15 changes: 15 additions & 0 deletions app/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
tmpDir: var/analyze
fileExtensions:
- php
paths:
- src
excludePaths:
- vendor
- src/Domain/DirectoryTree/Filter/SizeFilter.php
bootstrapFiles:
- vendor/autoload.php
ignoreErrors:
18 changes: 18 additions & 0 deletions app/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="true" stopOnFailure="true" backupGlobals="false" cacheResult="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="coverage/xml/clover.xml"/>
<html outputDirectory="coverage/html"/>
</report>
</coverage>
<testsuites>
<testsuite name="otus">
<directory>src</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
63 changes: 63 additions & 0 deletions app/psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
cacheDirectory="var/analyze/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />
<MixedArgumentTypeCoercion errorLevel="info" />

<MissingClosureParamType>
<errorLevel type="suppress">
</errorLevel>
</MissingClosureParamType>

<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />

<MissingClosureReturnType>
<errorLevel type="suppress">
</errorLevel>
</MissingClosureReturnType>

<MissingConstructor errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<RawObjectIteration errorLevel="info" />

<InvalidStringClass errorLevel="info" />
</issueHandlers>
</psalm>
Loading

0 comments on commit 878fe0a

Please sign in to comment.