php class를 관리

· 17년 전 · 1844
추천: 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,516
16년 전 조회 2,282
16년 전 조회 1,910
16년 전 조회 2,068
16년 전 조회 2,290
16년 전 조회 1,578
16년 전 조회 2,436
16년 전 조회 2,352
16년 전 조회 4,627
16년 전 조회 1,408
16년 전 조회 1,147
16년 전 조회 2,105
16년 전 조회 2,081
16년 전 조회 1,618
16년 전 조회 2,157
16년 전 조회 2,382
16년 전 조회 1,493
16년 전 조회 1,847
16년 전 조회 2,027
16년 전 조회 1,114
16년 전 조회 1,808
16년 전 조회 1,501
16년 전 조회 2,014
16년 전 조회 1,423
16년 전 조회 2,311
16년 전 조회 1,995
16년 전 조회 5,987
16년 전 조회 2,016
16년 전 조회 3,793
16년 전 조회 1,561
16년 전 조회 1,850
16년 전 조회 2,194
16년 전 조회 2,718
16년 전 조회 2,416
16년 전 조회 2,852
16년 전 조회 3,101
16년 전 조회 3,114
16년 전 조회 1,918
16년 전 조회 1,645
16년 전 조회 1,508
16년 전 조회 1,822
16년 전 조회 1,308
16년 전 조회 2,068
17년 전 조회 1,842
17년 전 조회 1,708
17년 전 조회 1,400
17년 전 조회 2,278
17년 전 조회 3,337
17년 전 조회 2,250
17년 전 조회 1,845
17년 전 조회 1,615
17년 전 조회 2,151
17년 전 조회 4,828
17년 전 조회 1,527
17년 전 조회 2,267
17년 전 조회 2,240
17년 전 조회 2,516
17년 전 조회 2,242
17년 전 조회 4,553
17년 전 조회 3,048
17년 전 조회 2,974
17년 전 조회 1,690
17년 전 조회 1,339
17년 전 조회 4,076
17년 전 조회 1,728
17년 전 조회 1,727
17년 전 조회 2,225
17년 전 조회 1,978
17년 전 조회 1,614
17년 전 조회 4,037
17년 전 조회 1,867
17년 전 조회 3,225
17년 전 조회 3,116
17년 전 조회 1,132
17년 전 조회 1,954
17년 전 조회 1,703
17년 전 조회 1,955
17년 전 조회 2,752
17년 전 조회 3,130
17년 전 조회 3,327
17년 전 조회 3,439
17년 전 조회 1,563
17년 전 조회 1,528
17년 전 조회 2,354
17년 전 조회 2,087
17년 전 조회 2,389
17년 전 조회 2,917
17년 전 조회 3,375
17년 전 조회 2,473
17년 전 조회 1,750
17년 전 조회 3,318
17년 전 조회 3,176
17년 전 조회 3,150
17년 전 조회 4,029
17년 전 조회 2,684
17년 전 조회 2,507
17년 전 조회 2,762
17년 전 조회 3,002
17년 전 조회 2,722
17년 전 조회 1,551