Download the PHP package spindle/types without Composer

On this page you can find all versions of the php package spindle/types. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package types

spindle/types

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License

PHPにより強い型付けを提供する基底クラス群です。

基本の型

Spindle\Types\Enum

Enumを継承すると列挙型になります。インスタンスは、クラスに定義したconstのいずれかの値であることを型から保証することができます。

Spindle\Types\TypedObject

TypedObjectを継承すると、プロパティの型を固定化したクラスを作ることができます。複雑なデータをより確実に扱うことができます。Domain Driven Designにおける"Entity"や"ValueObject"の実装に使えます。

型はschema()というstaticメソッドで定義します。 schemaは配列を返す必要があり、その配列はプロパティ名 => 型, デフォルト値,を繰り返したものになります。デフォルト値は省略でき、その場合はnullがセットされます。

型として指定できる値には以下のものがあります。

__get()__set()をfinalで固定化してしまうため、TypedObjectを継承するとクラスが持つ能力を一部奪うことになります。全てのクラスをTypedObjectから派生させて作るような設計は推奨しません。

TypedObjectはforeachに対応しています。(IteratorAggregate) TypedObjectはcount()関数で要素数を数えることができます。(Countable)

TypedObjectはcheckErrors()というメソッドを実装することを推奨します。これは、型だけではチェックしきれないバリデーションを行うためのメソッドです。 デフォルト実装ではすべてのプロパティがnot nullであることをチェックします。

TypedObject::$preventExtensions

TypedObjectはデフォルト状態ではschema()で定義されていないプロパティへの代入・参照を拒否します。これはプロパティのtypoを発見しやすくする効果がありますが、不便に感じることもあるでしょう。

TypedObject::$preventExtensionsをfalseにすると、未定義のプロパティを拒否せず、自動で拡張するようになります。(デフォルトはtrue)

なお、拡張したプロパティは自動的にmixed(型検査しない)として扱われます。

TypedObject::$casting

TypedObjectはプロパティに代入時、schemaと型が違えば例外を発生させます。 しかしPHPの標準的な挙動のように、違う型を代入しようとしたら型キャストを行ってほしい場合もあるでしょう。例えばデータベースから取り出した文字列からオブジェクトを復元したい場合などです。

TypedObject::$castingをtrueにすると、型が違う代入をしようとしても、なるべくキャストを行おうとします。

PDO::FETCH_CLASSとの組み合わせ

DBからSELECTしてきた結果をTypedObjectへ流し込むことができます。PDOの標準機能として、直接クラスをnewして流し込むPDO::FETCH_CLASSというモードがあるので、これを使うとよいでしょう。 通常、PDOから渡ってくるデータはstring型ですので、$castingオプションを有効にしておいてください。

注意点として、PDO::FETCH_CLASSは通常のオブジェクト初期化と挙動が違い、 先にセッターを実行してから、コンストラクタを起動 します。TypedObjectはコンストラクタでオブジェクトを初期化しているため、この挙動ではうまく動作しません。

PDO::FETCH_CLASSを用いる場合、必ずPDO::FETCH_PROPS_LATEを同時に指定してください。 このオプションを指定すると、コンストラクタが先に起動するようになり、正常に動作します。

TypedObjectの継承

TypedObjectで作られたクラスを継承する場合、親クラスのschemaは自動的には引き継がれません。extendメソッドを使って明示的に拡張する必要があります。

Spindle\Types\ConstObject

ConstObjectはTypedObjectを変更不可のオブジェクトにするDecoratorです。

Spindle\Types\Collection

array()からいくつか制限を追加した配列です。

Spindle\Types\ConstCollection

Collectionを読み取り専用にするDecoratorです。

Polyfill

PHPは5.4や5.5から使えるようになった標準インターフェースがいくつか存在します。 それらをPHP5.3においても使えるようにする目的で、Polyfillを用意しています。

DateTime implements DateTimeInterfaceなどの状態を保証するため、独自の名前空間上に配置しています。

Spindle\Types\Polyfill\JsonSerializable

JsonSerializableインターフェース(PHP5.4以降)に相当します。

Spindle\Types\Polyfill\DateTimeInterface

DateTimeInterfaceインターフェース(PHP5.5以降)に相当します。

Spindle\Types\Polyfill\DateTime

DateTimeInterfaceをimplementsしたDateTimeです。

Spindle\Types\Polyfill\DateTimeImmutable

DateTimeImmutable(PHP5.5以降)に相当します。状態を変更することができず、modifyやsetTimestampなどのメソッドを作用させると、別のインスタンスを返します。

License

spindle/typesの著作権は放棄するものとします。 利用に際して制限はありませんし、作者への連絡や著作権表示なども必要ありません。 スニペット的にコードをコピーして使っても問題ありません。

ライセンスの原文

CC0-1.0 (No Rights Reserved)


All versions of types with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spindle/types contains the following files

Loading the files please wait ....