php class를 관리

· 16년 전 · 1753
추천: 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,433
16년 전 조회 2,187
16년 전 조회 1,827
16년 전 조회 1,982
16년 전 조회 2,192
16년 전 조회 1,479
16년 전 조회 2,315
16년 전 조회 2,265
16년 전 조회 4,541
16년 전 조회 1,306
16년 전 조회 1,059
16년 전 조회 2,017
16년 전 조회 1,989
16년 전 조회 1,521
16년 전 조회 2,048
16년 전 조회 2,284
16년 전 조회 1,400
16년 전 조회 1,742
16년 전 조회 1,929
16년 전 조회 1,022
16년 전 조회 1,704
16년 전 조회 1,415
16년 전 조회 1,916
16년 전 조회 1,333
16년 전 조회 2,215
16년 전 조회 1,902
16년 전 조회 5,879
16년 전 조회 1,927
16년 전 조회 3,693
16년 전 조회 1,477
16년 전 조회 1,764
16년 전 조회 2,079
16년 전 조회 2,621
16년 전 조회 2,317
16년 전 조회 2,759
16년 전 조회 3,003
16년 전 조회 3,021
16년 전 조회 1,828
16년 전 조회 1,552
16년 전 조회 1,423
16년 전 조회 1,737
16년 전 조회 1,216
16년 전 조회 1,974
16년 전 조회 1,747
16년 전 조회 1,619
16년 전 조회 1,307
16년 전 조회 2,181
16년 전 조회 3,240
16년 전 조회 2,173
16년 전 조회 1,754
16년 전 조회 1,520
17년 전 조회 2,053
17년 전 조회 4,741
17년 전 조회 1,426
17년 전 조회 2,161
17년 전 조회 2,139
17년 전 조회 2,412
17년 전 조회 2,162
17년 전 조회 4,445
17년 전 조회 2,943
17년 전 조회 2,879
17년 전 조회 1,612
17년 전 조회 1,253
17년 전 조회 3,957
17년 전 조회 1,631
17년 전 조회 1,622
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,230
17년 전 조회 3,338
17년 전 조회 1,472
17년 전 조회 1,428
17년 전 조회 2,264
17년 전 조회 1,988
17년 전 조회 2,301
17년 전 조회 2,827
17년 전 조회 3,277
17년 전 조회 2,374
17년 전 조회 1,646
17년 전 조회 3,217
17년 전 조회 3,081
17년 전 조회 3,057
17년 전 조회 3,926
17년 전 조회 2,600
17년 전 조회 2,421
17년 전 조회 2,669
17년 전 조회 2,908
17년 전 조회 2,625
17년 전 조회 1,467