php class를 관리

· 17년 전 · 2124
추천: 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,805
16년 전 조회 2,572
16년 전 조회 2,208
16년 전 조회 2,367
16년 전 조회 2,591
16년 전 조회 1,858
16년 전 조회 2,746
16년 전 조회 2,627
16년 전 조회 4,932
16년 전 조회 1,711
16년 전 조회 1,455
16년 전 조회 2,406
16년 전 조회 2,359
16년 전 조회 1,920
16년 전 조회 2,471
16년 전 조회 2,676
16년 전 조회 1,788
16년 전 조회 2,140
16년 전 조회 2,327
16년 전 조회 1,408
16년 전 조회 2,122
16년 전 조회 1,801
16년 전 조회 2,297
16년 전 조회 1,708
16년 전 조회 2,598
16년 전 조회 2,294
16년 전 조회 6,288
16년 전 조회 2,314
17년 전 조회 4,077
17년 전 조회 1,839
17년 전 조회 2,142
17년 전 조회 2,485
17년 전 조회 2,991
17년 전 조회 2,690
17년 전 조회 3,145
17년 전 조회 3,382
17년 전 조회 3,398
17년 전 조회 2,208
17년 전 조회 1,932
17년 전 조회 1,799
17년 전 조회 2,117
17년 전 조회 1,595
17년 전 조회 2,349
17년 전 조회 2,130
17년 전 조회 1,978
17년 전 조회 1,679
17년 전 조회 2,553
17년 전 조회 3,615
17년 전 조회 2,514
17년 전 조회 2,125
17년 전 조회 1,890
17년 전 조회 2,425
17년 전 조회 5,107
17년 전 조회 1,811
17년 전 조회 2,555
17년 전 조회 2,520
17년 전 조회 2,802
17년 전 조회 2,510
17년 전 조회 4,847
17년 전 조회 3,345
17년 전 조회 3,245
17년 전 조회 1,970
17년 전 조회 1,638
17년 전 조회 4,358
17년 전 조회 2,031
17년 전 조회 2,024
17년 전 조회 2,509
17년 전 조회 2,265
17년 전 조회 1,898
17년 전 조회 4,314
17년 전 조회 2,131
17년 전 조회 3,493
17년 전 조회 3,415
17년 전 조회 1,403
17년 전 조회 2,185
17년 전 조회 1,958
17년 전 조회 2,212
17년 전 조회 3,023
17년 전 조회 3,379
17년 전 조회 3,580
17년 전 조회 3,703
17년 전 조회 1,803
17년 전 조회 1,799
17년 전 조회 2,610
17년 전 조회 2,345
17년 전 조회 2,647
17년 전 조회 3,192
17년 전 조회 3,648
17년 전 조회 2,742
17년 전 조회 2,010
17년 전 조회 3,597
17년 전 조회 3,457
17년 전 조회 3,412
17년 전 조회 4,286
17년 전 조회 2,936
17년 전 조회 2,782
17년 전 조회 3,044
17년 전 조회 3,269
17년 전 조회 2,991
17년 전 조회 1,853