/** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter ./** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter .
/** * * * @author [x26]VOLAND */ abstract class CollectionFactory { /** * . * * @param string $type * @return mixed */ public static function create($type) { $ class = $type . 'Collection' ; self::__create_class($ class ); $obj = new $ class ($type); return $obj; } /** * $class * * @param string $class * @return void */ private static function __create_class($ class ) { if ( ! class_exists($ class )) { eval( 'class ' . $ class . ' extends Collection { }' ); } } } * This source code was highlighted with Source Code Highlighter .
/ ***コレクションクラス*どのコレクションが作成されるかに基づく基本的なユニバーサルタイプ。** @author [x26] VOLAND* /抽象 クラス CollectionはIteratorAggregate、ArrayAccess、Countableを実装します{/ ***このコレクションに保存されているアイテムのタイプ。* @var string* /private $ __タイプ;/ ***オブジェクトストレージ* @var配列* /private $ __ collection = array();// ------------------------------------------------ --------------------/ ***デザイナー。*このコレクションに保存される要素のタイプを指定します。** @param string $ type要素タイプ* @return void* /パブリック 関数 __construct($タイプ){$ this-> __ type = $ type;}// ------------------------------------------------ --------------------/ ***オブジェクトのタイプを確認します。* `foreign`タイプのオブジェクトをコレクションに追加しないようにします。** @param object $ objectチェックするオブジェクト* @return void* @throws例外* /プライベート 関数 __check_type(&$ object ){if (get_class($ object )!= $ this-> __ type){新しい例外をスロー ( 「オブジェクト型」 .. get_class($ object )。 ``タイプのオブジェクトのコレクションに追加できません '' 。 $ this-> __タイプ。 '' ' );}}// ------------------------------------------------ --------------------/ ***引数に渡されたオブジェクトをコレクションに追加します。** @param object(s)オブジェクト* @return mixedコレクション* /パブリック 関数 add(){$ args = func_get_args();foreach ($ args as $ object ){$ this-> __ check_type($ object );$ this-> __ collection [] = $ object ;}$ thisを 返します。}// ------------------------------------------------ --------------------/ ***引数から渡されたオブジェクトをコレクションから削除します。** @param object(s)オブジェクト* @return mixedコレクション* /パブリック 関数 remove(){$ args = func_get_args();foreach ($ args as $ object ){unset($ this-> __ collection [array_search($ object 、$ this-> __ collection)]);}$ thisを 返します。}// ------------------------------------------------ --------------------/ ***コレクションをクリーンアップします。** @return mixedコレクション* /パブリック 関数 clear(){$ this-> __ collection = array();$ thisを 返します。}// ------------------------------------------------ --------------------/ ***コレクションが空かどうかを調べます。** @return bool* /パブリック 関数 isEmpty(){空を返す ($ this-> __コレクション);}// ------------------------------------------------ --------------------/ *** IteratorAggregateインターフェースの実装* // ***イテレータオブジェクトを返します。** @return CollectionIterator* /パブリック 関数 getIterator(){新しい CollectionIteratorを返す ($ this-> __コレクション);}// ------------------------------------------------ --------------------/ *** ArrayAccessインターフェースの実装。* // ***コレクションの要素をオフセットに設定します** @param ineter $ offsetオフセット* @param mixed $ offsetオブジェクト* @return void* /public function offsetSet($ offset、$ object ){$ this-> __ check_type($ object );if ($ offset === NULL){$ offset = max(array_keys($ this-> __ collection))+ 1;}$ this-> __ collection [$ offset] = $ object ;}// ------------------------------------------------ --------------------/ ***指定されたキーを持つアイテムが存在するかどうかを調べます。** @param integer $ offsetキー* @return bool* /パブリック 関数 offsetExists($ offset){return isset($ this-> __ collection [$ offset]);}// ------------------------------------------------ --------------------/ *** $ offsetキーによって参照される要素を削除します。** @param integer $ offsetキー* @return void* /パブリック 関数 offsetUnset($ offset){設定解除($ this-> __コレクション[$オフセット]);}// ------------------------------------------------ --------------------/ ***キーでアイテムを返します。** @param integer $ offsetキー* @return mixed* /パブリック 関数 offsetGet($ offset){if (isset($ this-> __ collection [$ offset])=== FALSE){NULLを返します。}$ this-> __コレクション[$オフセット]を返します。}// ------------------------------------------------ --------------------/ *** Countableインターフェースの実装* // ***コレクション内の要素の数を返します。** @return integer* /パブリック 関数カウント(){return sizeof ($ this- > __コレクション);}}*このソースコードは、 ソースコードハイライターで強調表示されました。
<?phpクラス BookStore {関数 addBooks(BookCollection $ books){//実装}関数 addMagazines(MagazineCollection $ magazines){//実装}関数 addGoods(コレクション$グッズ){//コレクションのタイプが重要でない場合、//コレクションのベースタイプを指定できます}}クラス Book {var $ id;function Book($ id){$ this-> id = $ id;}}クラス Magazine {var $ id;function Magazine($ id){$ this-> id = $ id;}}//コレクションを作成します$ books = CollectionFactory :: create( 'Book' );echo get_class($本); // BookCollection//オブジェクトをコレクションに追加します。$ books-> add( new Book(1)、 new Book(2));$ books-> add( new Book(3))-> add( new Book(2));$本[] = 新しい本(5);エコー数($本); // 5...foreach ($本を $本として ){echo $ book-> id;} // 12345...$ books-> add( new Magazine(1)); //エラー(間違ったタイプ)...$ magazines = CollectionFactory :: create( 'Magazine' );$ magazines-> add( new Magazine(1));...$ bookStore = new BookStore();$ bookStore-> addBooks($ books); //大丈夫$ bookStore-> addBooks($雑誌); //エラー(間違ったタイプ)$ bookStore-> addMagazines($雑誌); //大丈夫$ bookStore-> addGoods($ books); //大丈夫$ bookStore-> addGoods($雑誌); //大丈夫?>*このソースコードは、 ソースコードハイライターで強調表示されました。
Source: https://habr.com/ru/post/J64840/More articles:著者は今日、投資家に何を提供していますか? デブリーフィングLinux上のZFS:ほとんど良いグーグルマップのサンダース大佐USBスティックに関するいくつかの考えFireFox 3.5.1は奇妙なことをしますGoogle Chrome OSには競合他社がありますか?プレビューKDE 4.3Macに切り替えるべきですか?MySQLテーブルエンジンの概要QRホテルAll Articles