php class를 관리

· 17년 전 · 1764
추천: 0 , 조회: 79
ㅇ php.net의 class관련 소스들을 응용해서 java의 패키지형식으로 소스를 관리하도록 만들어 봤습니다.
ㅇ php에서 작성한 class의 위치를 /lib/class로 설정하고
class밑의 디렉토리를 java 패키지 같이 설정하여 사용합니다.

ex) /lib/class/common/class.common.object.php
/lib/class/util/class.util.string.php
/lib/class/cont/class.cont.photo.php
ㅇ 생성되는 class는 각자의 성격에 맞는 폴더 아래에서 관리하는거죠!

/********** class.common.object.php ************/
class class_common_object
{
var $m_name = '';
function class_common_object($name)
{
$this->m_name =$name;
register_shutdown_function(array(&$this, '_class_common_object'));
}

function _class_common_object()
{
}

function getName() { return $this->m_name; }
}


/********** func.class.php ************/
function &func_classFactory($classfilename)
{

$classname = func_classInclude($classfilename);
if (!$classname) return;

$code = "return new {$classname}(";
if (func_num_args() > 1)
{
$params = array_slice(func_get_args(),1);
$c = count($params);
for($i=0;$i<$c;++$i)
{
if ($i>0) $code .= ',';
$code .= '$params['.$i.']';
}
}
$code .= ');';
$csObj = eval($code);
return $csObj;
}

function func_classInclude($classfilename)
{
$clsarr = explode(".", $classfilename);
$classname = str_replace(".","_",$classfilename);

for($i=1; $i<count($clsarr)-1; $i++) $filename .= "/" . $clsarr[$i];
$filename =$g_arConfig[CLASS_ROOT] . $filename . "/$classfilename.php";

if (!class_exists($classname))
{
if (file_exists($filename)) include_once($filename);
else
{
echo "\nCould not load library $filename \n";
return null;
}
}
return $classname;
}


/*********** SAMPLE.PHP ***********/
include "func.class.php";
$csObj = func_classFactory("class.common.object", "test");
echo $csObj->getName();

[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
16년 전 조회 1,445
16년 전 조회 2,207
16년 전 조회 1,841
16년 전 조회 1,999
16년 전 조회 2,202
16년 전 조회 1,497
16년 전 조회 2,333
16년 전 조회 2,272
16년 전 조회 4,558
16년 전 조회 1,319
16년 전 조회 1,075
16년 전 조회 2,038
16년 전 조회 2,003
16년 전 조회 1,532
16년 전 조회 2,060
16년 전 조회 2,298
16년 전 조회 1,412
16년 전 조회 1,762
16년 전 조회 1,941
16년 전 조회 1,040
16년 전 조회 1,721
16년 전 조회 1,430
16년 전 조회 1,929
16년 전 조회 1,342
16년 전 조회 2,229
16년 전 조회 1,915
16년 전 조회 5,889
16년 전 조회 1,939
16년 전 조회 3,711
16년 전 조회 1,492
16년 전 조회 1,786
16년 전 조회 2,092
16년 전 조회 2,634
16년 전 조회 2,337
16년 전 조회 2,774
16년 전 조회 3,016
16년 전 조회 3,036
16년 전 조회 1,846
16년 전 조회 1,565
16년 전 조회 1,439
16년 전 조회 1,751
16년 전 조회 1,227
16년 전 조회 1,990
16년 전 조회 1,760
16년 전 조회 1,633
17년 전 조회 1,316
17년 전 조회 2,192
17년 전 조회 3,258
17년 전 조회 2,183
17년 전 조회 1,765
17년 전 조회 1,536
17년 전 조회 2,068
17년 전 조회 4,757
17년 전 조회 1,437
17년 전 조회 2,172
17년 전 조회 2,153
17년 전 조회 2,425
17년 전 조회 2,173
17년 전 조회 4,457
17년 전 조회 2,953
17년 전 조회 2,892
17년 전 조회 1,622
17년 전 조회 1,267
17년 전 조회 3,970
17년 전 조회 1,639
17년 전 조회 1,635
17년 전 조회 2,139
17년 전 조회 1,907
17년 전 조회 1,523
17년 전 조회 3,945
17년 전 조회 1,773
17년 전 조회 3,159
17년 전 조회 3,025
17년 전 조회 1,059
17년 전 조회 1,874
17년 전 조회 1,620
17년 전 조회 1,869
17년 전 조회 2,663
17년 전 조회 3,053
17년 전 조회 3,241
17년 전 조회 3,351
17년 전 조회 1,486
17년 전 조회 1,440
17년 전 조회 2,281
17년 전 조회 2,004
17년 전 조회 2,313
17년 전 조회 2,840
17년 전 조회 3,286
17년 전 조회 2,381
17년 전 조회 1,657
17년 전 조회 3,228
17년 전 조회 3,090
17년 전 조회 3,071
17년 전 조회 3,940
17년 전 조회 2,610
17년 전 조회 2,430
17년 전 조회 2,682
17년 전 조회 2,920
17년 전 조회 2,637
17년 전 조회 1,480