[php] 간단 Properties class test 5.0 이상에서 > 팁앤테크

본문 바로가기
사이트 내 전체검색

팁앤테크

[php] 간단 Properties class test 5.0 이상에서

페이지 정보

profile_image
작성자 론이
댓글 0건 조회 95,163회 작성일 11-06-07 05:25

본문

<?
/********************
* 
* Properties class
*
* Date : 2010.
*
* @author
*
* desc :
* map 자료구조 형태의 프로퍼티를 관리하는 class
*
*/


class Properties
{
private $list = null; // 프로퍼티를 담을 배열

/*******************
* 생성자
* arg[0] : 타입 - Properties class type 이어야 한다. */
public function __construct(Properties $defaultProperties=null)
{
if ($defaultProperties)
{
$this->list = $defaultProperties->getList();
}
}


/*******************
* property 값을 리턴한다.
* arg[0] : list의 key */
public function getProperty($key)
{
if (is_array($this->list) && $key)
return $this->list[$key];
else
return "";
}


/*******************
* property 값을 리턴한다.
* arg[0] : list의 key */
public function setProperty($key, $value)
{
$this->list[$key] = $value;
}


/*******************
* property 값을 배열형태로 받는다.
* arg[0] : property 배열 */
public function setList($list)
{
$this->list = $list;
}


/*******************
* property 배열을 리턴한다.
* */
public function getList()
{
return $this->list;
}
}


/*
$p = new Properties();
$p->setProperty('apple', '사과');

$props = new Properties($p);
echo $props->getProperty('apple')."<br/>";
var_dump($props->getList());


result:
>> 사과
>> array(1) { ["apple"]=> string(6) "사과" }
*/


class Item
{
public $name = "";
public $price = 0;
protected $spec = null;

public function __construct($name, $price)
{
$this->name = $name;
$this->price = $price;
}

public function getSpec()
{
return $this->spec;
}

public function setSpec( Properties $props )
{
$this->spec= $props;
//echo get_class($this->props);
}

}



$p = new Properties();
$p->setProperty('width', '400');
$p->setProperty('height', '700');
$p->setProperty('forecolor', 'silver');
$p->setProperty('backcolor', 'black');

$item = new Item('iphone', 300000);
$item->setSpec($p);

echo $item->getSpec()->getProperty('forecolor');
/*
result:
>> silver
*/
?>

댓글목록

등록된 댓글이 없습니다.

Total 829건 13 페이지
  • RSS
팁앤테크 목록
번호 제목 글쓴이 조회 날짜
529 제로 65464 07-20
528 제로 100449 07-13
527 제로 63431 07-12
526 허깨비 93647 07-06
525 제로 69842 07-06
524 제로 110257 07-02
523 제로 62415 06-30
522 제로 133856 06-29
521 제로 109699 06-29
520 제로 86533 06-28
519 제로 91802 06-17
518 제로 98343 06-15
517 제로 73930 06-10
열람중 론이 95164 06-07
515 론이 103070 06-07
514 제로 88022 06-06
513 제로 92758 06-04
512 제로 102334 06-02
511 제로 103304 06-01
510 제로 75849 06-01
509 제로 70958 05-30
508 제로 83654 05-30
507 제로 85158 05-30
506 제로 83684 05-30
505 제로 79121 05-30

검색


사이트 정보

株式会社YHPLUS / 대표 : ZERO
〒140-0011 東京都品川区東大井2-5-9-203
050-5470-4714
오픈카카오톡 (YHPLUS) :
https://open.kakao.com/o/slfDj15d

접속자집계

오늘
23,540
어제
37,399
최대
552,140
전체
16,167,194
Copyright (c) 株式会社YHPLUS. All rights reserved.