a) 每次处理代码时 __destruct 都会单独运行吗
b) 或者,不,您需要使用 unset($objectName) 才能运行(另一个选项是 register_shutdown_function() )。
c) 还有其他方面与此相关吗?就像它在这个或那个时自行工作一样,你也可以使用这个或那个来让它运行,任何东西......
我在 Raspberry Pi 上的 GPIO 引脚上有一个簧片开关,用于监视门是打开还是关闭。
这在浏览器中显示 OK:
<?php
echo "Today is " . date("l, jS F Y") . "<br>";
?>
</br>
<?php
// Set up valid status list
$state[1] = "open";
$state[0] = "closed";
?>
<p style="font-family: calibri; font-size:14pt; font-style:italic">
The door is currently
<?php $pinStatus = trim(shell_exec("gpio -g read 18"));
//returns 0 = low; 1 = high
echo $state[$pinStatus];?>
</p>
Run Code Online (Sandbox Code Playgroud)
我想用不同的颜色显示“打开”和“关闭”这两个词,但不知道如何做到这一点。打开/关闭可以很容易地加粗,但让它们着色似乎相当棘手。
基于 DTO 创建了一个非常简单的资源。所有逻辑都将通过自定义提供DataProvider
,并且该项目不使用注释。
资源的配置是:
<resources xmlns="https://api-platform.com/schema/metadata">
<resource class="App\Domain\Dto\ProductUpgradePrice">
<collectionOperations>
<collectionOperation name="get"/>
</collectionOperations>
<itemOperations>
<itemOperation name="get"/>
</itemOperations>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
实际的DTO是:
<?php declare(strict_types=1);
namespace App\Domain\Dto;
/** @psalm-immutable */
class ProductUpgradePrice
{
public function __construct(
public string $productId,
public int $regularPrice,
public int $upgradePrice
) {}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试时,GET /api/product_upgrade_prices
我得到:
没有为 App\Domain\Dto\ProductUpgradePrice 类型的资源定义标识符
这是有道理的。
文档提到使用注释,@ApiProperty
但正如我之前提到的,这个项目没有注释。(自从我发布问题以来,我提交了一个 PR 来更新文档,该问题已合并,所以希望未来的用户不会遇到同样的情况)
我尝试将其添加到资源配置中:
<property name="productId">
<attribute name="identifier">true</attribute>
</property>
Run Code Online (Sandbox Code Playgroud)
但得到了相同的结果。
在不使用注释的情况下如何配置它?