php class를 관리

· 17년 전 · 1939
추천: 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,616
16년 전 조회 2,379
16년 전 조회 2,004
16년 전 조회 2,175
16년 전 조회 2,398
16년 전 조회 1,672
16년 전 조회 2,555
16년 전 조회 2,442
16년 전 조회 4,740
16년 전 조회 1,510
16년 전 조회 1,254
16년 전 조회 2,206
16년 전 조회 2,175
16년 전 조회 1,718
16년 전 조회 2,284
16년 전 조회 2,489
16년 전 조회 1,594
16년 전 조회 1,952
16년 전 조회 2,125
16년 전 조회 1,207
16년 전 조회 1,922
16년 전 조회 1,602
16년 전 조회 2,101
16년 전 조회 1,521
16년 전 조회 2,427
16년 전 조회 2,092
16년 전 조회 6,112
16년 전 조회 2,111
16년 전 조회 3,893
16년 전 조회 1,651
16년 전 조회 1,947
16년 전 조회 2,288
16년 전 조회 2,814
16년 전 조회 2,517
16년 전 조회 2,952
16년 전 조회 3,195
16년 전 조회 3,215
17년 전 조회 2,007
17년 전 조회 1,732
17년 전 조회 1,600
17년 전 조회 1,931
17년 전 조회 1,414
17년 전 조회 2,166
17년 전 조회 1,938
17년 전 조회 1,795
17년 전 조회 1,499
17년 전 조회 2,375
17년 전 조회 3,435
17년 전 조회 2,338
17년 전 조회 1,940
17년 전 조회 1,717
17년 전 조회 2,243
17년 전 조회 4,927
17년 전 조회 1,650
17년 전 조회 2,380
17년 전 조회 2,340
17년 전 조회 2,618
17년 전 조회 2,338
17년 전 조회 4,659
17년 전 조회 3,153
17년 전 조회 3,070
17년 전 조회 1,782
17년 전 조회 1,433
17년 전 조회 4,164
17년 전 조회 1,838
17년 전 조회 1,836
17년 전 조회 2,316
17년 전 조회 2,081
17년 전 조회 1,711
17년 전 조회 4,132
17년 전 조회 1,961
17년 전 조회 3,302
17년 전 조회 3,233
17년 전 조회 1,223
17년 전 조회 2,041
17년 전 조회 1,797
17년 전 조회 2,038
17년 전 조회 2,860
17년 전 조회 3,221
17년 전 조회 3,433
17년 전 조회 3,530
17년 전 조회 1,639
17년 전 조회 1,626
17년 전 조회 2,429
17년 전 조회 2,186
17년 전 조회 2,475
17년 전 조회 3,010
17년 전 조회 3,488
17년 전 조회 2,570
17년 전 조회 1,844
17년 전 조회 3,425
17년 전 조회 3,274
17년 전 조회 3,249
17년 전 조회 4,122
17년 전 조회 2,759
17년 전 조회 2,624
17년 전 조회 2,868
17년 전 조회 3,116
17년 전 조회 2,828
17년 전 조회 1,665