• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / plugin / 3766633246

pending completion
3766633246

push

github

twinh
feat(plugin): `BasePage` 增加 `pageInit` 事件

0 of 1 new or added line in 1 file covered. (0.0%)

84 existing lines in 24 files now uncovered.

902 of 2275 relevant lines covered (39.65%)

19.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Command/GService.php
1
<?php
2

3
namespace Miaoxing\Plugin\Command;
4

5
use Miaoxing\Plugin\BasePlugin;
6
use Symfony\Component\Console\Input\InputArgument;
7

8
/**
9
 * @mixin \PluginMixin
10
 */
11
class GService extends BaseCommand
12
{
13
    use PluginIdTrait;
14

15
    protected function configure()
16
    {
UNCOV
17
        $this
×
18
            ->addArgument('name', InputArgument::REQUIRED, 'The name of service')
×
19
            ->addArgument('plugin-id', InputArgument::OPTIONAL, 'The id of plugin');
×
20
    }
21

22
    /**
23
     * @return int
24
     * @throws \Exception
25
     */
26
    protected function handle()
27
    {
28
        $name = $this->input->getArgument('name');
×
29
        $id = $this->getPluginId();
×
30

31
        $plugin = wei()->plugin->getOneById($id);
×
32

33
        $class = ucfirst($name);
×
34
        $file = $this->getFile($plugin, $class);
×
35
        $this->createDir(dirname($file));
×
36

37
        $namespace = $this->getNamespace($plugin);
×
38

39
        $this->createFile($file, $namespace, $class);
×
40

41
        $this->plugin->getConfig(true);
×
42

43
        $this->runCommand('g:auto-completion', ['plugin-id' => $id]);
×
44

45
        return $this->suc('创建成功');
×
46
    }
47

48
    protected function getFile(BasePlugin $plugin, $name)
49
    {
50
        return $plugin->getBasePath() . '/src/Service/' . ucfirst($name) . '.php';
×
51
    }
52

53
    protected function createDir($dir)
54
    {
55
        if (!is_dir($dir)) {
×
56
            mkdir($dir, 0777, true);
×
57
            chmod($dir, 0777);
×
58
        }
59
    }
60

61
    protected function getNamespace(BasePlugin $plugin)
62
    {
63
        $class = get_class($plugin);
×
64
        $parts = explode('\\', $class);
×
65
        array_pop($parts);
×
66

67
        return implode('\\', $parts) . '\Service';
×
68
    }
69

70
    protected function createFile($file, $namespace, $class)
71
    {
72
        $this->suc('生成文件 ' . $file);
×
73

74
        ob_start();
×
75
        require $this->plugin->getById('plugin')->getBasePath() . '/stubs/service.php';
×
76
        $content = ob_get_clean();
×
77

78
        file_put_contents($file, $content);
×
79
        chmod($file, 0777);
×
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc