4 Advanced Features

You have already seen how class type hinting and access control give you more control over a class’s interface. In this chapter I will delve deeper into PHP’s object-oriented features. This chapter will cover several subjects: Static methods and properties: Accessing data and functionality through classes rather than objects Abstract classes and interfaces: Separating design from implementation Traits: Sharing implementation between class hierarchies Error handling: Introducing exceptions Final classes and methods: Limiting inheritance Interceptor methods: Automating delegation Destructor methods: Cleaning up after your objects Cloning objects: Making object copies Resolving objects to strings: Creating a summary method Callbacks: Adding functionality to components with anonymous functions and classes Static Methods and Properties All of the examples in the previous chapter worked with objects....

July 17, 2024 · 37 min · Matt Zandstra

1 PHP: Design and Management

In July 2004, PHP 5.0 was released. This version introduced a suite of radical enhancements, notably improved support for object-oriented programming. This sparked significant interest in objects and design within the PHP community, continuing a trend that began with PHP 4, which first made object-oriented programming with PHP a serious reality. In this chapter, I examine some of the needs that coding with objects can address, briefly summarizing aspects of the evolution of patterns and related practices....

July 17, 2024 · 5 min · Matt Zandstra

クラスに関する基本的な事項のまとめ

クラスの定義とインスタンスの生成 PHP <?php class Dog extends Animal { // クラスプロパティ public static $species = 'Canis lupus familiaris'; // プロパティ public $name; public $breed; // コンストラクタ public function __construct($name, $breed) { $this->name = $name; $this->breed = $breed; } // メソッド public function bark() { echo "Woof!"; } public static function staticMethod() { echo "Static method"; } } // インスタンスを作成 $buddy = new Dog("Buddy", "Golden Retriever"); // 引数がないときは()を省略可 $buddy->bark(); echo Dog::$species; // 注意:$が必要! Dog::staticMethod(); Python class Dog(Animal): # クラス属性 species = "Canis lupus familiaris" # コンストラクタ def __init__(self, name, breed): self....

July 3, 2024 · 3 min · Don

Filamentを使ったLaravelアプリの開発

FilamentについてLLMに聞くと以下のような回答が返ってきました。なかなか良さそうなので早速試してみます。 Filamentは、Laravel アプリケーションのためのオープンソースの管理パネル作成フレームワークです。簡単に言うと、Filament を使うと、わずか数行のコードで、美しく、機能的な管理パネルを構築できます。 Filamentを使うと以下のようなメリットがあります: 迅速な開発: Filament は、事前構築されたコンポーネントとテンプレートを提供することで、開発時間を大幅に短縮します。 美しいデザイン: Filament は、洗練された UI と UX を提供し、ユーザーエクスペリエンスを向上させます。 カスタマイズ性: Filament は、豊富なカスタマイズオプションを提供し、アプリケーションのニーズに合わせて管理パネルを調整できます。 強力な機能: Filament は、ユーザー管理、認証、アクセス制御、データテーブル、フォーム、ファイルアップロードなど、管理パネルに不可欠な機能をすべて備えています。 コミュニティサポート: Filament は、活発なコミュニティサポートがあり、質問や問題解決の支援を受けることができます。 プロジェクト作成とFilamentインストール 新しいLaravelプロジェクトを以下のように作成します。 composer create-project laravel/laravel companydb cd companydb .envのDB設定を書き換えます。 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=companydb DB_USERNAME=root DB_PASSWORD=xxxx mysqlにcompanydbデータベースを新規作成し、migrationコマンドを実行します。 php artisan migrate filament DOCSに従ってFilamentのインストールをします。 composer require filament/filament:"^3.2" -W php artisan filament:install --panels php artisan make:filament-user ブラウザでhttp://127.0.0.1:8000/admin/にアクセスすれば作成したユーザとパスワードでログインできます。 ログインすると以下のような画面が表示されます。 データベースモデルを作成する Model::unguard()を追加 AppServiceProvider.phpにModel::unguard()を追加します。 /** * Bootstrap any application services. */ public function boot(): void { Model::unguard(); } Blueprintを使ってモデルを作成する モデルの作成はBlueprintというツールを使って行います。まず以下のようにインストールし、draft....

June 25, 2024 · 1 min · Don