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

Commit 8ec74d3

Browse files
authored
Merge pull request #15 from modulusphp/feature/deep-dive
Feature/deep dive
2 parents 774ef48 + 3682645 commit 8ec74d3

8 files changed

Lines changed: 459 additions & 6 deletions

File tree

Commands/ClearCache.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Hibernate\Cache;
6+
use Modulus\Console\ModulusCLI;
7+
use Modulus\Support\Filesystem;
8+
use AtlantisPHP\Console\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class ClearCache extends Command
13+
{
14+
/**
15+
* The name and signature of the console command.
16+
*
17+
* @var string
18+
*/
19+
protected $signature = 'clear:cache';
20+
21+
/**
22+
* The full command description.
23+
*
24+
* @var string
25+
*/
26+
protected $help = 'This command allows you to clear hibernate cache';
27+
28+
/**
29+
* The descriptions of the console commands.
30+
*
31+
* @var array
32+
*/
33+
protected $descriptions = [
34+
'clear:cache' => 'Clear hibernate cache',
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+
$results = Cache::flush();
46+
47+
if ($results) return $output->writeln('<info>Cleared cache!</info>');
48+
49+
return $output->writeln('Nothing to clear');
50+
}
51+
}

Commands/CraftException.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 CraftException extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'craft:exception {name}';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to create a custom exception class';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'craft:exception' => 'Create a new custom exception class',
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>Exception "' . $name . '" has been successfully created.</info>');
49+
}
50+
51+
return $output->writeln('File "' . $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+
$appdir = ModulusCLI::$appdir . 'app' . DIRECTORY_SEPARATOR . 'Exceptions';
63+
$app = $appdir . DIRECTORY_SEPARATOR . $name . '.php';
64+
$namespace = '';
65+
66+
if (substr_count($name, '/') > 0) {
67+
ModulusCLI::_dir(substr($app, 0, strrpos($app, 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($appdir);
75+
76+
$content = Template::asset('exception_template');
77+
$content = str_replace('{name}', $name, $content);
78+
$content = str_replace('{namespace}', $namespace, $content);
79+
80+
if (file_exists($app)) {
81+
return false;
82+
}
83+
else {
84+
file_put_contents($app, $content);
85+
return true;
86+
}
87+
}
88+
89+
}

Commands/CraftTest.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 CraftTest extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'craft:test {name} {unit=false}';
19+
20+
/**
21+
* The full command description.
22+
*
23+
* @var string
24+
*/
25+
protected $help = 'This command allows you to create a Application event';
26+
27+
/**
28+
* The descriptions of the console commands.
29+
*
30+
* @var array
31+
*/
32+
protected $descriptions = [
33+
'craft:test' => 'Create a new test class',
34+
'name' => 'The name of the class',
35+
'unit' => 'Create a unit test'
36+
];
37+
38+
/**
39+
* @param InputInterface $input
40+
* @param OutputInterface $output
41+
*
42+
* @return void
43+
*/
44+
protected function execute(InputInterface $input, OutputInterface $output)
45+
{
46+
$isUnit = strtolower($input->getOption('unit')) == 'true' ? true : false;
47+
48+
$name = $input->getArgument('name');
49+
50+
if ($this->add($name, $isUnit)) {
51+
return $output->writeln('<info>Test "' . $name . '" has been successfully created.</info>');
52+
}
53+
54+
return $output->writeln('Test "' . $name . '" already exists.');
55+
}
56+
57+
/**
58+
* Add asset
59+
*
60+
* @param string $name
61+
* @param boolean $isUnit
62+
* @return boolean
63+
*/
64+
private function add(string $name, bool $isUnit) : bool
65+
{
66+
$tests = ModulusCLI::$appdir . 'tests' . DIRECTORY_SEPARATOR . ($isUnit ? 'Unit' : 'Feature');
67+
$test = $tests . DIRECTORY_SEPARATOR . $name . '.php';
68+
$namespace = '';
69+
70+
if (substr_count($name, '/') > 0) {
71+
ModulusCLI::_dir(substr($test, 0, strrpos($test, DIRECTORY_SEPARATOR)));
72+
$namespace = substr($name, 0, strrpos($name, DIRECTORY_SEPARATOR));
73+
$name = str_replace($namespace . DIRECTORY_SEPARATOR, '', $name);
74+
75+
$namespace = '\\' . str_replace('/', '\\', $namespace);
76+
}
77+
78+
ModulusCLI::_dir($tests);
79+
80+
$template = ($isUnit ? 'unit_test_template' : 'feature_test_template');
81+
82+
$content = Template::asset($template);
83+
$content = str_replace('{test_name}', $name, $content);
84+
$content = str_replace('{namespace}', $namespace, $content);
85+
86+
if (file_exists($test)) {
87+
return false;
88+
}
89+
else {
90+
file_put_contents($test, $content);
91+
return true;
92+
}
93+
}
94+
95+
}

Commands/Shell.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Psy\Shell as PyShell;
6+
use AtlantisPHP\Console\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class Shell extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'shell';
18+
19+
/**
20+
* The full command description.
21+
*
22+
* @var string
23+
*/
24+
protected $help = 'An interactive shell for modern PHP';
25+
26+
/**
27+
* The descriptions of the console commands.
28+
*
29+
* @var array
30+
*/
31+
protected $descriptions = [
32+
'shell' => 'An interactive shell for modern PHP'
33+
];
34+
35+
/**
36+
* @param InputInterface $input
37+
* @param OutputInterface $output
38+
*
39+
* @return void
40+
*/
41+
protected function execute(InputInterface $input, OutputInterface $output)
42+
{
43+
(new PyShell)->run();
44+
}
45+
46+
}

Commands/StorageLink.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Modulus\Console\Commands;
4+
5+
use Modulus\Console\ModulusCLI;
6+
use AtlantisPHP\Console\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class StorageLink extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'storage:link {dest=storage}';
18+
19+
/**
20+
* The full command description.
21+
*
22+
* @var string
23+
*/
24+
protected $help = 'Create a symbolic link from "public/storage" to "storage/app/public"';
25+
26+
/**
27+
* The descriptions of the console commands.
28+
*
29+
* @var array
30+
*/
31+
protected $descriptions = [
32+
'storage:link' => 'Create a symbolic link from "public/storage" to "storage/app/public"',
33+
'dest' => 'The destination of the documetations',
34+
];
35+
36+
/**
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
*
40+
* @return void
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
$docs = ModulusCLI::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public';
45+
$dest = ModulusCLI::$appdir . 'public' . DIRECTORY_SEPARATOR . $this->getDest($input->getOption('dest'));
46+
47+
if (is_dir($docs)) {
48+
if (!is_dir($dest) || !is_link($dest)) {
49+
symlink($docs, $dest);
50+
51+
if (is_link($dest)) {
52+
return $output->writeln("<info>The [public/{$this->getDest($input->getOption('dest'))}] directory has been linked</info>");
53+
}
54+
} else {
55+
return $output->writeln('Destination is already in use.');
56+
}
57+
}
58+
59+
return $output->writeln('Folder doesn\'t exist');
60+
}
61+
62+
/**
63+
* Get destination
64+
*
65+
* @param string $dest
66+
* @return string
67+
*/
68+
private function getDest(string $dest)
69+
{
70+
return substr($dest, 0, 1) == DIRECTORY_SEPARATOR ? substr($dest, 1) : $dest;
71+
}
72+
73+
}

0 commit comments

Comments
 (0)