Skip to content

Commit

Permalink
working autorecipe
Browse files Browse the repository at this point in the history
  • Loading branch information
sergix44 committed Feb 15, 2023
1 parent edb96ba commit 7b2836b
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "MIT",
"autoload": {
"psr-4": {
"SergiX44\\Nutgram\\Symfony\\": "src/"
"SergiX44\\NutgramBundle\\": "src/"
}
},
"authors": [
Expand Down
12 changes: 12 additions & 0 deletions config/nutgram.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
nutgram:
# The Telegram bot token
token: '%env(string:NUTGRAM_TOKEN)%'

# If true, the webhook mode validates the incoming IP range is from a Telegram server
safe_mode: false

# Extra or specific configuration
config: [ ]

# If the nutgram bundle should automatically load the routes from config/telegram.php
routes: true
10 changes: 5 additions & 5 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
services:

SergiX44\Nutgram\Symfony\DependencyInjection\Factory\NutgramFactory: ~
SergiX44\NutgramBundle\DependencyInjection\Factory\NutgramFactory: ~

SergiX44\Nutgram\Symfony\NutgramConfigurator:
SergiX44\NutgramBundle\NutgramConfigurator:
autowire: true
arguments: [ '%nutgram.config%' ]

SergiX44\Nutgram\Nutgram:
autowire: true
public: true
factory: [ '@SergiX44\Nutgram\Symfony\DependencyInjection\Factory\NutgramFactory', 'createNutgram' ]
factory: [ '@SergiX44\NutgramBundle\DependencyInjection\Factory\NutgramFactory', 'createNutgram' ]
arguments: [ '%nutgram.config%', '@service_container' ]
configurator: [ '@SergiX44\Nutgram\Symfony\NutgramConfigurator', 'configure' ]
configurator: [ '@SergiX44\NutgramBundle\NutgramConfigurator', 'configure' ]

SergiX44\Nutgram\Symfony\Console\:
SergiX44\NutgramBundle\Console\:
resource: '../src/Console/'
autowire: true
tags: [ 'console.command' ]
50 changes: 50 additions & 0 deletions src/Console/BundleInitCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace SergiX44\NutgramBundle\Console;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelInterface;

#[AsCommand(
name: 'nutgram:init',
description: 'Creates the route and the config file',
)]
class BundleInitCommand extends Command
{

private KernelInterface $kernel;

public function __construct(KernelInterface $kernel, string $name = null)
{
parent::__construct($name);
$this->kernel = $kernel;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$configDir = $this->kernel->getProjectDir().'/config/';

$config = "$configDir/packages/nutgram.yaml";
if (!file_exists($config)) {
copy(__DIR__.'/../../config/nutgram.yaml', $config);
}

$routes = "$configDir/telegram.php";
if (!file_exists($routes)) {
copy(__DIR__.'/../../config/telegram.php', $routes);
}

$io->success('Config and routes files created!');

return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Console/LogoutCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/RegisterCommandsCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/RunCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/WebhookInfoCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/WebhookRemoveCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/WebhookSetCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\Console;
namespace SergiX44\NutgramBundle\Console;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\DependencyInjection;
namespace SergiX44\NutgramBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand All @@ -14,9 +14,9 @@ public function getConfigTreeBuilder(): TreeBuilder
$treeBuilder->getRootNode()
->children()
->scalarNode('token')->end()
->booleanNode('safe_mode')->end()
->booleanNode('safe_mode')->defaultFalse()->end()
->arrayNode('config')->end()
->booleanNode('routes')->end()
->booleanNode('routes')->defaultTrue()->end()
->end()
->end();

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Factory/NutgramFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\DependencyInjection\Factory;
namespace SergiX44\NutgramBundle\DependencyInjection\Factory;

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/NutgramExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony\DependencyInjection;
namespace SergiX44\NutgramBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/NutgramBundle.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace SergiX44\Nutgram\Symfony;
namespace SergiX44\NutgramBundle;

use SergiX44\Nutgram\Symfony\DependencyInjection\NutgramExtension;
use SergiX44\NutgramBundle\DependencyInjection\NutgramExtension;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down
2 changes: 1 addition & 1 deletion src/NutgramConfigurator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SergiX44\Nutgram\Symfony;
namespace SergiX44\NutgramBundle;

use SergiX44\Nutgram\Nutgram;
use Symfony\Component\Config\FileLocator;
Expand Down

0 comments on commit 7b2836b

Please sign in to comment.