php class를 관리

· 16년 전 · 1751
추천: 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,432
16년 전 조회 2,186
16년 전 조회 1,827
16년 전 조회 1,981
16년 전 조회 2,192
16년 전 조회 1,478
16년 전 조회 2,314
16년 전 조회 2,264
16년 전 조회 4,540
16년 전 조회 1,306
16년 전 조회 1,058
16년 전 조회 2,017
16년 전 조회 1,988
16년 전 조회 1,520
16년 전 조회 2,048
16년 전 조회 2,284
16년 전 조회 1,400
16년 전 조회 1,740
16년 전 조회 1,929
16년 전 조회 1,022
16년 전 조회 1,703
16년 전 조회 1,414
16년 전 조회 1,916
16년 전 조회 1,333
16년 전 조회 2,213
16년 전 조회 1,902
16년 전 조회 5,879
16년 전 조회 1,927
16년 전 조회 3,693
16년 전 조회 1,476
16년 전 조회 1,764
16년 전 조회 2,079
16년 전 조회 2,621
16년 전 조회 2,317
16년 전 조회 2,759
16년 전 조회 3,002
16년 전 조회 3,021
16년 전 조회 1,826
16년 전 조회 1,552
16년 전 조회 1,422
16년 전 조회 1,736
16년 전 조회 1,216
16년 전 조회 1,974
16년 전 조회 1,746
16년 전 조회 1,619
16년 전 조회 1,307
16년 전 조회 2,180
16년 전 조회 3,240
16년 전 조회 2,172
16년 전 조회 1,752
16년 전 조회 1,519
17년 전 조회 2,053
17년 전 조회 4,740
17년 전 조회 1,424
17년 전 조회 2,161
17년 전 조회 2,139
17년 전 조회 2,412
17년 전 조회 2,162
17년 전 조회 4,445
17년 전 조회 2,943
17년 전 조회 2,879
17년 전 조회 1,610
17년 전 조회 1,252
17년 전 조회 3,956
17년 전 조회 1,630
17년 전 조회 1,621
17년 전 조회 2,123
17년 전 조회 1,894
17년 전 조회 1,508
17년 전 조회 3,927
17년 전 조회 1,765
17년 전 조회 3,139
17년 전 조회 3,018
17년 전 조회 1,050
17년 전 조회 1,860
17년 전 조회 1,605
17년 전 조회 1,861
17년 전 조회 2,652
17년 전 조회 3,034
17년 전 조회 3,229
17년 전 조회 3,337
17년 전 조회 1,472
17년 전 조회 1,428
17년 전 조회 2,264
17년 전 조회 1,988
17년 전 조회 2,301
17년 전 조회 2,827
17년 전 조회 3,276
17년 전 조회 2,374
17년 전 조회 1,645
17년 전 조회 3,216
17년 전 조회 3,080
17년 전 조회 3,056
17년 전 조회 3,925
17년 전 조회 2,599
17년 전 조회 2,420
17년 전 조회 2,668
17년 전 조회 2,907
17년 전 조회 2,622
17년 전 조회 1,466