小编gen*_*sst的帖子

覆盖Doctrine 2.6中特征属性的关联映射

先决条件:

  • PHP 7.1.8
  • Symfony 3.3.9
  • Doctrine 2.6.x-dev

我想知道是否可以覆盖从inversedBy特征中获取的属性关联映射的属性.

我用作具体用户实体占位符的接口:

ReusableBundle\ModelEntrantInterface.php

interface EntrantInterface
{
    public function getEmail();

    public function getFirstName();

    public function getLastName();
}
Run Code Online (Sandbox Code Playgroud)
  1. 以下架构工作得很好(需要创建User实现的实体EntrantInterface和从这些抽象类派生的所有其他实体AppBundle):

ReusableBundle \实体\ Entry.php

/**
 * @ORM\MappedSuperclass
 */
abstract class Entry
{
    /**
     * @var EntrantInterface
     *
     * @ORM\ManyToOne(targetEntity="ReusableBundle\Model\EntrantInterface", inversedBy="entries")
     * @ORM\JoinColumn(name="user_id")
     */
    protected $user;

    // getters/setters...
}
Run Code Online (Sandbox Code Playgroud)

ReusableBundle \实体\ Timestamp.php

/**
 * @ORM\MappedSuperclass
 */
abstract class Timestamp
{
    /**
     * @var EntrantInterface
     *
     * @ORM\ManyToOne(targetEntity="ReusableBundle\Model\EntrantInterface", inversedBy="timestamps")
     * @ORM\JoinColumn(name="user_id") …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony doctrine-orm symfony-3.3

10
推荐指数
1
解决办法
846
查看次数

PHP:向ios发送推送通知

我正在从php向ios发送推送通知.它工作正常,这是我的代码:

$passphrase = '';
$badge = 1;
$path = base_path('path/to/certificate.pem');
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $path);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx
);

if (!$fp) {
    self::SavePush($device_token, $message, $device_id, $device_type, $user_id, "pending", "normal", null);
}

//echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
    'alert' => $message,
    'badge' => $badge,
    'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $device_token) . pack('n', strlen($payload)) . …
Run Code Online (Sandbox Code Playgroud)

php push-notification ios

8
推荐指数
1
解决办法
1115
查看次数

Symfony UniqueEntity vs UniqueConstraint vs unique = true

任何人都可以解释@UniqueEntity验证器,@UniqueConstraint表注释和注释unique=true选项之间的概念差异@Column.

据我所知,在数据库级别@UniqueConstraint添加UNIQUE索引并@UniqueEntity在ORM级别上验证.那么我应该使用什么选项,还是使用它们?

doctrine symfony doctrine-orm

7
推荐指数
1
解决办法
1269
查看次数

D3 js背景选项卡冻结,同时渲染到画布

我正面临D3.js的问题.将数据渲染到画布时,选项卡在处于非活动状态时会冻结.在几分钟的标签背景下,它很容易变得明显.

我已经创建了一个示例JSFiddle来重现这个问题,它也可以在本地环境中轻松完成,源代码如下.

(() => {
  // data container script
  $(() => {
    let $dataContainer = $('.data');
    setInterval(() => {
      $dataContainer.empty();
      let numbers = [];
      for (let i = 0; i < 10; i++) {
        let randNumber = Math.floor(Math.random() * 100);
        numbers.push(randNumber);
        $dataContainer.append(`<p>${randNumber}</p>`);
      }
      $(document).trigger('data:updated', [numbers])
    }, 1000);
  });

  // actual canvas render
  $(() => {
    // boring stuff
    let base = d3.select(".viz");
    let chart = base.append("canvas")
      .attr("width", 400)
      .attr("height", 300);

    let context = chart.node().getContext("2d");

    let detachedContainer = document.createElement("custom"); …
Run Code Online (Sandbox Code Playgroud)

d3.js

7
推荐指数
0
解决办法
383
查看次数

document.createElement 是 Puppeteer 中的代理

我正在尝试使用 Puppeteer 解析页面。但是,页面上的脚本之一正在尝试覆盖createElement文档对象的属性,这会导致错误。错误信息是:

\n

Uncaught TypeError: Cannot assign to read only property 'createElement' of object '#<HTMLDocument>'

\n

经过研究,我意识到documentPuppeteer 中的属性是由代理对象保护的。

\n

当我document.createElement在 Puppeteer 控制台中运行时,我得到以下信息:

\n

Proxy\xc2\xa0{length: 1, name: "createElement"}

\n

但是,当我在 Chrome 中执行相同操作时,它是一个常规函数,而不是代理。

\n

有没有办法让 Puppeteer 以与 Chrome 相同的方式运行并使document对象可写?

\n

编辑:

\n

我已经尝试过这个,但没有成功。document.createElement仍然是一个代理。

\n
await page.evaluateOnNewDocument(() => {\n    document.createElement = document.__proto__.createElement;\n})\n
Run Code Online (Sandbox Code Playgroud)\n

puppeteer

5
推荐指数
0
解决办法
612
查看次数

显示并统计目录(含子目录)中的所有文件扩展名

我正在使用主题中的命令来查看目录和所有子目录中的所有文件扩展名。

find . -type f -name '*.*' | sed 's|.*\.||' | sort -u

如何统计每个分机的出现次数?

喜欢:

png: 140

bash

3
推荐指数
1
解决办法
666
查看次数

Chai用参数测试失败

我似乎无法完全理解如何正确地使用测试,特别是与Chai库.或者我可能会错过编程基础知识,有点困惑.

鉴于测试:

it("should check parameter type", function(){
    expect(testFunction(1)).to.throw(TypeError);
    expect(testFunction("test string")).to.throw(TypeError);
});
Run Code Online (Sandbox Code Playgroud)

这是我正在测试的一个功能:

function testFunction(arg) {
    if (typeof arg === "number" || typeof arg === "string")
        throw new TypeError;
}
Run Code Online (Sandbox Code Playgroud)

我期待测试通过,但我只是在控制台中看到抛出的错误:

TypeError: Test
    at Object.testFunction (index.js:10:19)
    at Context.<anonymous> (test\index.spec.js:31:28)
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释一下吗?

javascript mocha.js chai

3
推荐指数
1
解决办法
879
查看次数

Symfony2中的依赖注入最佳实践

在Symfony2(本例中为2.8)中,将服务注入其他服务时,最佳做法是什么?

/**
 * Checker constructor.
 * @param EntityManager $em
 * @param EventDispatcherInterface $dispatcher
 */
public function __construct(EntityManager $em, EventDispatcherInterface $dispatcher)
{
    $this->repoUser = $em->getRepository(User::class);
    $this->repoPurchase = $em->getRepository(Purchase::class);
    $this->repoTicket = $em->getRepository(Ticket::class);
    $this->dispatcher = $dispatcher;
}
Run Code Online (Sandbox Code Playgroud)

要么

/**
 * Checker constructor.
 * @param UserRepository $ur
 * @param PurchaseRepository $pr
 * @param TicketRepository $tr
 * @param EventDispatcherInterface $dispatcher
 */
public function __construct(UserRepository $ur, PurchaseRepository $pr, TicketRepository $tr, EventDispatcherInterface $dispatcher)
{
    $this->repoUser = $ur;
    $this->repoPurchase = $pr;
    $this->repoTicket = $tr;
    $this->dispatcher = $dispatcher;
} …
Run Code Online (Sandbox Code Playgroud)

dependency-injection symfony

3
推荐指数
1
解决办法
290
查看次数