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

miaoxing / plugin / 4030261158

pending completion
4030261158

push

github

twinh
feat(Model): 增加 `IpTrait`,用于为模型记录用户 IP 和端口

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

870 of 2273 relevant lines covered (38.28%)

19.01 hits per line

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

0.0
/src/Model/IpTrait.php
1
<?php
2

3
namespace Miaoxing\Plugin\Model;
4

5
/**
6
 * Add user IP to model object
7
 *
8
 * @property-read string $createdIpColumn The column contains create user IP
9
 */
10
trait IpTrait
11
{
12
    public static function bootIpTrait(): void
13
    {
NEW
14
        static::onModelEvent('init', 'initIpModel');
×
NEW
15
        static::onModelEvent('beforeCreate', 'setIpValue');
×
16
    }
17

18
    protected function getCreatedIpColumn(): string
19
    {
NEW
20
        return $this->createdIpColumn ?? $this->convertToPhpKey('created_ip');
×
21
    }
22

23
    /**
24
     * @internal
25
     */
26
    protected function initIpModel(): void
27
    {
NEW
28
        $createdIpColumn = $this->getCreatedIpColumn();
×
NEW
29
        $this->hidden[] = $createdIpColumn;
×
NEW
30
        $this->guarded[] = $createdIpColumn;
×
NEW
31
        $this->columns[$createdIpColumn]['cast'] = 'ip';
×
32
    }
33

34
    /**
35
     * @internal
36
     */
37
    protected function setIpValue(): void
38
    {
NEW
39
        $this->setColumnValue($this->getCreatedIpColumn(), $this->req->getIp());
×
40
    }
41
}
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

© 2025 Coveralls, Inc