php class를 관리

· 17년 전 · 1784
추천: 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,468
16년 전 조회 2,227
16년 전 조회 1,858
16년 전 조회 2,019
16년 전 조회 2,225
16년 전 조회 1,520
16년 전 조회 2,348
16년 전 조회 2,288
16년 전 조회 4,576
16년 전 조회 1,334
16년 전 조회 1,089
16년 전 조회 2,053
16년 전 조회 2,018
16년 전 조회 1,551
16년 전 조회 2,078
16년 전 조회 2,321
16년 전 조회 1,429
16년 전 조회 1,783
16년 전 조회 1,967
16년 전 조회 1,059
16년 전 조회 1,741
16년 전 조회 1,446
16년 전 조회 1,945
16년 전 조회 1,358
16년 전 조회 2,249
16년 전 조회 1,933
16년 전 조회 5,910
16년 전 조회 1,957
16년 전 조회 3,727
16년 전 조회 1,511
16년 전 조회 1,801
16년 전 조회 2,110
16년 전 조회 2,646
16년 전 조회 2,357
16년 전 조회 2,788
16년 전 조회 3,034
16년 전 조회 3,053
16년 전 조회 1,866
16년 전 조회 1,585
16년 전 조회 1,457
16년 전 조회 1,770
16년 전 조회 1,245
16년 전 조회 2,012
16년 전 조회 1,774
16년 전 조회 1,651
17년 전 조회 1,330
17년 전 조회 2,207
17년 전 조회 3,274
17년 전 조회 2,206
17년 전 조회 1,785
17년 전 조회 1,554
17년 전 조회 2,086
17년 전 조회 4,776
17년 전 조회 1,461
17년 전 조회 2,192
17년 전 조회 2,168
17년 전 조회 2,440
17년 전 조회 2,189
17년 전 조회 4,472
17년 전 조회 2,971
17년 전 조회 2,914
17년 전 조회 1,638
17년 전 조회 1,287
17년 전 조회 3,992
17년 전 조회 1,658
17년 전 조회 1,655
17년 전 조회 2,154
17년 전 조회 1,928
17년 전 조회 1,539
17년 전 조회 3,959
17년 전 조회 1,792
17년 전 조회 3,172
17년 전 조회 3,041
17년 전 조회 1,080
17년 전 조회 1,887
17년 전 조회 1,638
17년 전 조회 1,888
17년 전 조회 2,678
17년 전 조회 3,067
17년 전 조회 3,258
17년 전 조회 3,365
17년 전 조회 1,505
17년 전 조회 1,457
17년 전 조회 2,293
17년 전 조회 2,020
17년 전 조회 2,326
17년 전 조회 2,855
17년 전 조회 3,302
17년 전 조회 2,404
17년 전 조회 1,676
17년 전 조회 3,251
17년 전 조회 3,113
17년 전 조회 3,088
17년 전 조회 3,956
17년 전 조회 2,634
17년 전 조회 2,449
17년 전 조회 2,692
17년 전 조회 2,931
17년 전 조회 2,653
17년 전 조회 1,493