• 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/GModel.php
1
<?php
2

3
namespace Miaoxing\Plugin\Command;
4

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

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

16
    /**
17
     * @return int
18
     * @throws \Exception
19
     */
20
    public function handle()
21
    {
22
        $name = $this->input->getArgument('name');
×
23
        $id = $this->getPluginId();
×
24

25
        $plugin = wei()->plugin->getOneById($id);
×
26

27
        $class = ucfirst($name);
×
28
        $file = $this->getFile($plugin, $class);
×
29
        $this->createDir(dirname($file));
×
30

31
        $namespace = $this->getNamespace($plugin);
×
32

33
        $this->createFile($file, $namespace, $class);
×
34

35
        Plugin::loadConfig(true);
×
36
        $this->runCommand('g:auto-completion', ['plugin-id' => $id]);
×
37
        $this->runCommand('g:metadata', ['plugin-id' => $id]);
×
38

39
        return $this->suc('创建成功');
×
40
    }
41

42
    protected function configure()
43
    {
UNCOV
44
        $this
×
45
            ->addArgument('name', InputArgument::REQUIRED, 'The name of model')
×
46
            ->addArgument('plugin-id', InputArgument::OPTIONAL, 'The id of plugin');
×
47
    }
48

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

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

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

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

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

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

79
        file_put_contents($file, $content);
×
80
        chmod($file, 0777);
×
81
    }
82
}
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