php class를 관리

· 17년 전 · 1829
추천: 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,507
16년 전 조회 2,276
16년 전 조회 1,902
16년 전 조회 2,058
16년 전 조회 2,287
16년 전 조회 1,569
16년 전 조회 2,413
16년 전 조회 2,342
16년 전 조회 4,616
16년 전 조회 1,391
16년 전 조회 1,142
16년 전 조회 2,097
16년 전 조회 2,070
16년 전 조회 1,604
16년 전 조회 2,142
16년 전 조회 2,369
16년 전 조회 1,482
16년 전 조회 1,833
16년 전 조회 2,012
16년 전 조회 1,108
16년 전 조회 1,788
16년 전 조회 1,495
16년 전 조회 1,999
16년 전 조회 1,410
16년 전 조회 2,298
16년 전 조회 1,989
16년 전 조회 5,970
16년 전 조회 2,005
16년 전 조회 3,781
16년 전 조회 1,554
16년 전 조회 1,841
16년 전 조회 2,167
16년 전 조회 2,706
16년 전 조회 2,404
16년 전 조회 2,838
16년 전 조회 3,083
16년 전 조회 3,104
16년 전 조회 1,903
16년 전 조회 1,632
16년 전 조회 1,493
16년 전 조회 1,812
16년 전 조회 1,295
16년 전 조회 2,063
16년 전 조회 1,833
17년 전 조회 1,700
17년 전 조회 1,386
17년 전 조회 2,265
17년 전 조회 3,324
17년 전 조회 2,243
17년 전 조회 1,830
17년 전 조회 1,601
17년 전 조회 2,135
17년 전 조회 4,815
17년 전 조회 1,509
17년 전 조회 2,247
17년 전 조회 2,223
17년 전 조회 2,500
17년 전 조회 2,233
17년 전 조회 4,535
17년 전 조회 3,029
17년 전 조회 2,960
17년 전 조회 1,680
17년 전 조회 1,325
17년 전 조회 4,053
17년 전 조회 1,712
17년 전 조회 1,713
17년 전 조회 2,213
17년 전 조회 1,974
17년 전 조회 1,599
17년 전 조회 4,020
17년 전 조회 1,850
17년 전 조회 3,218
17년 전 조회 3,109
17년 전 조회 1,125
17년 전 조회 1,942
17년 전 조회 1,700
17년 전 조회 1,946
17년 전 조회 2,733
17년 전 조회 3,119
17년 전 조회 3,312
17년 전 조회 3,424
17년 전 조회 1,556
17년 전 조회 1,517
17년 전 조회 2,340
17년 전 조회 2,073
17년 전 조회 2,381
17년 전 조회 2,909
17년 전 조회 3,361
17년 전 조회 2,461
17년 전 조회 1,732
17년 전 조회 3,303
17년 전 조회 3,160
17년 전 조회 3,138
17년 전 조회 4,013
17년 전 조회 2,674
17년 전 조회 2,494
17년 전 조회 2,744
17년 전 조회 2,987
17년 전 조회 2,699
17년 전 조회 1,542