Pages

2023年4月27日木曜日

[CakePHP4] Controller から コマンドを実行する方法

$commandRunner = new CommandRunner(new Application(ROOT . DS . 'config'), 'cake');
$commandRunner->run([
    'bin' . DS . 'cake',
    'command_name',
    'param1',
    'param2,
]);

上記は

$ bin/cake command_name param1 param2

と同等。

2023年3月6日月曜日

[PHP Code Sniffer] The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line

エラー内容

ERROR | [x] The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line

) と { は同一行に書きなさい!!


修正前

public function sampleFunc(

    int $bookId,

    string $bookName

): ?BookEntity

{

  // ...

}


修正後

public function sampleFunc(

    int $bookId,

    string $bookName

): ?BookEntity {

  // ...

}

2022年4月21日木曜日

[Windows] Tera Term などを使わずにクリックしたらトンネル接続開始にする方法

 今回参考にしたサイト


トンネル接続する

まずは Windows の PowerShell だけを使ってトンネル接続をします。

> ssh [username]@[from_host] -i [secret_file_path] -L [from_port]:[to_host]:[to_port]

例:
ポート:2022 の場合は fhost.com サーバー経由で thost.com サーバーに ポート:22 で接続したいという場合。

fhost.com の 接続アカウントは
host: fhost.com
username: user
key_file: C:\Users\user\.ssh\id_rda.pem

> ssh user@fhost.com -i C:\Users\user\.ssh\id_rda.pem
 -L 2022:thost.com:22

鍵ファイルがユーザーディレクトリ以下(もしくはユーザーを限定的に設定)でなければ警告が出てうまく接続できないので、それについて困ったらこちらを参考にしてください。

PowerShell で sshすると UNPROTECTED PRIVATE KEY FILE

ショートカットを作成

好きなところでショートカットを新規作成する


"項目の場所を入力してください(T)" に以下を入力する。


%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "ssh user@fhost.com -i C:\Users\user\.ssh\id_rda.pem -L 2022:thost.com:22"

"次へ" をクリックするとショートカットの名前を確認されるので好きな名前を入力する。


"完了" をクリックして完了。

2022年3月15日火曜日

[Laravel] Windowsにはcronが無いので、タスク スケジューラにscheduleを設定する

Windowsにはcronが無いので、タスク スケジューラに設定するんですが、単純に設定するとコマンドプロンプトのウィンドウが一分毎に立ち上がって文字入力の邪魔をする。。

なので、もうVBSファイルからコマンドプロンプトを実行するようにしてこれを回避。

ついでにPHPのバージョン変更もするように。


手順

  1. VBSファイルを作成
  2. タスク スケジューラに設定

VBSファイルを作成

VPSファイルはどこに置いても大丈夫です。
ただのテキストファイルなのでメモ帳で作成可能です。
拡張子は .vbs

記載内容はこちら

Set ws = CreateObject("Wscript.Shell") 
ws.run "cmd /k set PATH=D:\app\php-8.0.14-nts-Win32-vs16-x64;%PATH% & cd D:\prjects\sample & php artisan schedule:run", 0, false

記載内容の説明
ws.run で 3つのパラメータを指定しています。

1つ目 実行するコマンド
2つ目 ウィンドウオプション 0=表示しない
3つ目 同期指定 false=非同期

つまり 1つ目のコマンドは非表示で勝手に実行しといてくださいって感じです。

run メソッドについて詳しくはこちら

コマンドは & 区切りで複数実行できますので、今回は
  1. PATH の更新
  2. ディレクトリの移動
  3. scheduleの実行
をやっています。


2021年10月28日木曜日

CakePHP4 Validation:: add() rule で利用できる値一覧

notBlank

alphaNumeric

notAlphaNumeric

asciiAlphaNumeric

notAsciiAlphaNumeric

lengthBetween

creditCard

numElements

comparison

compareWith

compareFields

containsNonAlphaNumeric

custom

date

datetime

iso8601

time

localizedTime

boolean

truthy

falsey

decimal

email

equalTo

extension

ip

minLength

maxLength

minLengthBytes

maxLengthBytes

money

multiple

numeric

naturalNumber

range

url

inList

uuid

luhn

mimeType

getFilename

fileSize

uploadError

uploadedFile

imageSize

imageWidth

imageHeight

geoCoordinate

latitude

longitude

ascii

utf8

isInteger

isArray

isScalar

hexColor

iban

Followers