Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Aug 3, 2021
1 parent 740721e commit 75d97cb
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Template
========
Shop
====

This is a template package.
Common shop description and meta package.
2 changes: 2 additions & 0 deletions common.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions:
shop: Baraja\Shop\ShopExtension
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "baraja-core/template",
"description": "This is a template package.",
"homepage": "https://github.com/baraja-core/template",
"name": "baraja-core/shop",
"description": "Common shop description and meta package.",
"homepage": "https://github.com/baraja-core/shop",
"authors": [
{
"name": "Jan Barášek",
"homepage": "https://baraja.cz"
}
],
"require": {
"php": "^8.0"
"php": "^8.0",
"baraja-core/dynamic-configuration": "^2.1"
},
"require-dev": {
"tracy/tracy": "^2.8",
Expand Down
Empty file removed src/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions src/ShopExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Baraja\Shop;


use Nette\DI\CompilerExtension;

final class ShopExtension extends CompilerExtension
{
public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();
// OrmAnnotationsExtension::addAnnotationPathToManager($builder, 'Baraja\Shop\Address\Entity', __DIR__ . '/Entity');

$builder->addDefinition($this->prefix('shopInfo'))
->setFactory(ShopInfo::class);
}
}
73 changes: 73 additions & 0 deletions src/ShopInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Baraja\Shop;


use Baraja\DynamicConfiguration\Configuration;
use Baraja\DynamicConfiguration\ConfigurationSection;

final class ShopInfo
{
private ConfigurationSection $configuration;


public function __construct(Configuration $configuration)
{
$this->configuration = $configuration->getSection('shop');
}


public function getShopName(): string
{
$name = $this->configuration->get('name');
if ($name === null) {
throw new \LogicException('Shop name must exist.');
}

return $name;
}


public function getDefaultManufacturer(): string
{
return $this->configuration->get('default-manufacturer') ?? $this->getShopName();
}


public function getShopDescription(): ?string
{
return $this->configuration->get('description');
}


public function getContactPersonName(): ?string
{
return $this->configuration->get('contact-person-name');
}


public function getSupportEmail(): ?string
{
return $this->configuration->get('support-email');
}


public function getOrderEmail(): ?string
{
return $this->configuration->get('order-email') ?? $this->getSupportEmail();
}


public function getSupportPhone(): ?string
{
return $this->configuration->get('support-phone');
}


public function getBankAccount(): ?string
{
return $this->configuration->get('bank-account');
}
}

0 comments on commit 75d97cb

Please sign in to comment.