Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 1e37609

Browse files
authored
Merge pull request #24 from modulusphp/feature/commands-updates
Feature/commands updates
2 parents 62ff810 + 4399bea commit 1e37609

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

Commands/CraftMail.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Console\ModulusCLI;
6+
use AtlantisPHP\Console\Command;
7+
use Modulus\Scaffolding\Template;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class CraftMail extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'craft:mail {name}';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to create a mail';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'craft:mail' => 'Create a new mail',
34+
'name' => 'The name of the class'
35+
];
36+
37+
/**
38+
* @param InputInterface $input
39+
* @param OutputInterface $output
40+
*
41+
* @return void
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output)
44+
{
45+
$name = $input->getArgument('name');
46+
47+
if ($this->add($name)) {
48+
return $output->writeln('<info>Mail "' . $name . '" has been successfully created.</info>');
49+
}
50+
51+
return $output->writeln('Mail "' . $name . '" already exists.');
52+
}
53+
54+
/**
55+
* Add asset
56+
*
57+
* @param string $name
58+
* @return boolean
59+
*/
60+
private function add(string $name) : bool
61+
{
62+
$notifications = ModulusCLI::$appdir . 'app' . DIRECTORY_SEPARATOR . 'Mail';
63+
$notification = $notifications . DIRECTORY_SEPARATOR . $name . '.php';
64+
$namespace = '';
65+
66+
if (substr_count($name, '/') > 0) {
67+
ModulusCLI::_dir(substr($notification, 0, strrpos($notification, DIRECTORY_SEPARATOR)));
68+
$namespace = substr($name, 0, strrpos($name, DIRECTORY_SEPARATOR));
69+
$name = str_replace($namespace . DIRECTORY_SEPARATOR, '', $name);
70+
71+
$namespace = '\\' . str_replace('/', '\\', $namespace);
72+
}
73+
74+
ModulusCLI::_dir($notifications);
75+
76+
$content = Template::asset('mail_template');
77+
$content = str_replace('{mail_name}', $name, $content);
78+
$content = str_replace('{namespace}', $namespace, $content);
79+
80+
if (file_exists($notification)) return false;
81+
82+
file_put_contents($notification, $content);
83+
return true;
84+
}
85+
}

Commands/CraftNotification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CraftNotification extends Command
3030
* @var array
3131
*/
3232
protected $descriptions = [
33-
'craft:notification' => 'Create a new application event',
33+
'craft:notification' => 'Create a new notification',
3434
'name' => 'The name of the class'
3535
];
3636

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "modulusphp/console",
33
"description": "Modulus Commands",
4-
"version": "1.9.6.5",
4+
"version": "1.9.6.6",
55
"license": "MIT",
66
"type": "package",
77
"authors": [{

0 commit comments

Comments
 (0)