Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

分類: 未分類

透過 composer 的 autoload 設定做 bootstrap

Posted on 2023 年 1 月 12 日2023 年 1 月 12 日 By 日落 在〈透過 composer 的 autoload 設定做 bootstrap〉中尚無留言

使用 symfony/polyfill-intl-idn 後發現有趣的事,不用特別去檢查 PHP extension 的 function 是否存在,只要 require symfony polyfill 以後,完全不需要進行任何設定就可以正常運作。

後來在 composer.json 看到 autoload 的寫法:

{
    "autoload": {
        "psr-4": { "Symfony\\Polyfill\\Intl\\Idn\\": "" },
        "files": [ "bootstrap.php" ]
    },
}

以前以為 autoload 只能挑其中一種方法使用,沒想到可以指定多種方法同時使用。

上面的設定方式,namespace 會在 class 使用時才 require 進來,而 bootstrap.php 則是在一開始就 require 並執行,polyfill 就在當下偵測並處理掉 extension functions。所以使用者 composer require 以後程式並不需要做任何修改。

Tags:PHP

Force umount all cifs volumes

Posted on 2023 年 1 月 8 日2023 年 1 月 8 日 By 日落 在〈Force umount all cifs volumes〉中尚無留言

sudo umount -a -t cifs -l

  • -l , --lazy:unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore.

reference:Force Unmount a CIFS Share in Linux

Tags:Linux

Set protected property on PHPUnit mock object

Posted on 2023 年 1 月 8 日2023 年 1 月 8 日 By 日落 在〈Set protected property on PHPUnit mock object〉中尚無留言

假設有個 class:

class Woker
{
    protected Queue $queue;

    public function run()
    {
        while (!$this->queue->isEmpty()) {
            $job = $this->queue->pop();
            // do something
        }
    }
}

用 PHPUnit 建立 stub 以後,必須使用 reflection 來自訂 $queue property:

$worker = $this->getMockBuilder(Worker::class)
    ->disableOriginalConstructor()
    ->getMock();

$queue = $this->createMock(Queue::class);
$queue->expected($this->atLeast(1))
    ->method('isEmpty')
    ->willReturn(true);

// PHP Reflection on $worker
$refProperty = new \ReflectionProperty($worker, 'queue');
$refProperty->setAccessible(true);
$refProperty->setValue($crawler, $queue);

這樣寫 test case 蠻髒的,有點想要換 test framework ….

Tags:PHP, PHPUnit

Kdenlive 影片縮時

Posted on 2023 年 1 月 5 日2023 年 1 月 5 日 By 日落 在〈Kdenlive 影片縮時〉中尚無留言

從專案的時間軸上,在要縮時 (調整速度) 的影片點滑鼠右鍵,並在選單中選擇「Change Speed」:

在媒體上點選滑鼠右鍵並選擇「Change Speed」

若要讓影片以二倍速度播放,則填入「200%」,以此類推:

右上方填寫影片要播放的速度倍率
Tags:分享

暫時停止更新 apt 套件

Posted on 2022 年 12 月 30 日2022 年 12 月 30 日 By 日落 在〈暫時停止更新 apt 套件〉中尚無留言

假設要讓 google-cloud-cli 套件維持在目前的版本、不更新,可以使用 apt-mark 鎖定版本:

apt-mark hold google-cloud-cli

若不再需要鎖定版本,則使用 unhold 解除鎖定:

apt-mark unhold google-cloud-cli
Tags:Linux, Ubuntu

文章分頁

上一頁 1 ... 23 24 25 ... 317 下一頁

其他

關於我  (About me)

小額贊助

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.