Skip to content

Commit a890a06

Browse files
committed
initial commit
0 parents  commit a890a06

22 files changed

+650
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = tab
9+
indent_size = tab
10+
tab_width = 4
11+
12+
[*.yml]
13+
indent_style = space
14+
indent_size = 4
15+
16+
[composer.json]
17+
indent_style = space
18+
indent_size = 4

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## ide
2+
/.idea/
3+
4+
## composer
5+
/composer.lock
6+
/vendor/

.travis.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
language: php
2+
php:
3+
- 7.4
4+
5+
before_install:
6+
- phpenv config-rm xdebug.ini || return 0 # Turn off XDebug
7+
8+
install:
9+
- travis_retry composer install --no-progress --prefer-dist # Install dependencies
10+
11+
after_failure:
12+
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done # Print *.actual content
13+
14+
jobs:
15+
include:
16+
- stage: Tests
17+
php: 7.4
18+
script:
19+
- make tests
20+
21+
- stage: Code style
22+
php: 7.4
23+
script:
24+
- make cs
25+
26+
- stage: PHPStan
27+
php: 7.4
28+
script:
29+
- make phpstan
30+
31+
sudo: false
32+
33+
cache:
34+
directories:
35+
- $HOME/.composer/cache

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: phpstan tests cs csfix lint
2+
3+
check: tests cs phpstan lint
4+
5+
vendor: composer.json composer.lock
6+
composer install
7+
8+
tests: vendor
9+
vendor/bin/tester -s -p php --colors 1 -C tests/cases
10+
11+
lint: vendor
12+
vendor/bin/linter src tests
13+
14+
cs: vendor
15+
vendor/bin/codesniffer src tests
16+
17+
csfix: vendor
18+
vendor/bin/codefixer src tests
19+
20+
phpstan: vendor
21+
vendor/bin/phpstan analyse -l max -c phpstan.neon src

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## nette utility
2+
3+
[![Build Status](https://travis-ci.org/utilitte/nette.svg?branch=master)](https://travis-ci.org/utilitte/nette)
4+
[![Licence](https://img.shields.io/packagist/l/utilitte/nette.svg)](https://packagist.org/packages/utilitte/nette)
5+
[![Latest stable](https://img.shields.io/packagist/v/utilitte/nette.svg)](https://packagist.org/packages/utilitte/nette)

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "utilitte/nette",
3+
"description": "",
4+
"license": "proprietary",
5+
"type": "library",
6+
"require": {
7+
"php": ">=7.4",
8+
"utilitte/php": "~1.0"
9+
},
10+
"require-dev": {
11+
"phpstan/phpstan": "^0.12.33",
12+
"phpstan/extension-installer": "^1.0",
13+
"phpstan/phpstan-deprecation-rules": "^0.12.2",
14+
"utilitte/qa": "~1.0.0",
15+
"nette/tester": "^2.3.0",
16+
"nette/application": "^3.0",
17+
"latte/latte": "^2.8",
18+
"doctrine/orm": "^2.7",
19+
"nette/di": "^3.0",
20+
"utilitte/doctrine": "^1.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Utilitte\\Nette\\": "src/"
25+
}
26+
}
27+
}

phpstan.neon

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Utilitte\Nette\DI;
4+
5+
use Nette\DI\ContainerBuilder;
6+
use Nette\DI\Definitions\FactoryDefinition;
7+
8+
final class CompilerExtensionUtility
9+
{
10+
11+
public static function getFactoryDefinitionByType(ContainerBuilder $builder, string $type): FactoryDefinition
12+
{
13+
$definition = $builder->getDefinitionByType($type);
14+
assert($definition instanceof FactoryDefinition);
15+
16+
return $definition;
17+
}
18+
19+
}

src/DI/UtilityExtension.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Utilitte\Nette\DI;
4+
5+
use Doctrine\ORM\EntityManagerInterface;
6+
use Nette\Bridges\ApplicationLatte\ILatteFactory;
7+
use Nette\DI\CompilerExtension;
8+
use Nette\Schema\Expect;
9+
use Nette\Schema\Schema;
10+
use Utilitte\Doctrine\DoctrineIdentityExtractor;
11+
use Utilitte\Nette\Latte\Macros;
12+
use Utilitte\Nette\UI\FlexibleMultiplierByIdentifierFactory;
13+
14+
final class UtilityExtension extends CompilerExtension
15+
{
16+
17+
public function getConfigSchema(): Schema
18+
{
19+
return Expect::structure([
20+
'latte' => Expect::structure([
21+
'enable' => Expect::bool(interface_exists(ILatteFactory::class)),
22+
'macros' => Expect::structure([
23+
'confirmMessage' => Expect::string('Do you really want to continue?'),
24+
]),
25+
]),
26+
]);
27+
}
28+
29+
public function loadConfiguration(): void
30+
{
31+
$builder = $this->getContainerBuilder();
32+
33+
$builder->addDefinition($this->prefix('flexibleMultiplier'))
34+
->setFactory(FlexibleMultiplierByIdentifierFactory::class);
35+
36+
if (interface_exists(EntityManagerInterface::class) && class_exists(DoctrineIdentityExtractor::class)) {
37+
$builder->addDefinition($this->prefix('doctrine.identityExtractor'))
38+
->setType(DoctrineIdentityExtractor::class);
39+
}
40+
}
41+
42+
public function beforeCompile(): void
43+
{
44+
$builder = $this->getContainerBuilder();
45+
$config = $this->getConfig();
46+
47+
if ($config->latte->enable) {
48+
$service = CompilerExtensionUtility::getFactoryDefinitionByType($builder, ILatteFactory::class);
49+
50+
$service->getResultDefinition()
51+
->addSetup('?->onCompile[] = function ($engine) { ?::install($engine->getCompiler(), ?); }', [
52+
'@self',
53+
Macros::class,
54+
(array) $config->latte->macros,
55+
]);
56+
}
57+
}
58+
59+
}

0 commit comments

Comments
 (0)