php class를 관리

· 17년 전 · 1757
추천: 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,440
16년 전 조회 2,194
16년 전 조회 1,836
16년 전 조회 1,992
16년 전 조회 2,200
16년 전 조회 1,493
16년 전 조회 2,328
16년 전 조회 2,268
16년 전 조회 4,552
16년 전 조회 1,315
16년 전 조회 1,071
16년 전 조회 2,032
16년 전 조회 1,996
16년 전 조회 1,530
16년 전 조회 2,056
16년 전 조회 2,291
16년 전 조회 1,408
16년 전 조회 1,756
16년 전 조회 1,937
16년 전 조회 1,031
16년 전 조회 1,713
16년 전 조회 1,427
16년 전 조회 1,922
16년 전 조회 1,339
16년 전 조회 2,223
16년 전 조회 1,911
16년 전 조회 5,885
16년 전 조회 1,933
16년 전 조회 3,703
16년 전 조회 1,487
16년 전 조회 1,775
16년 전 조회 2,086
16년 전 조회 2,627
16년 전 조회 2,328
16년 전 조회 2,768
16년 전 조회 3,010
16년 전 조회 3,033
16년 전 조회 1,841
16년 전 조회 1,562
16년 전 조회 1,431
16년 전 조회 1,745
16년 전 조회 1,221
16년 전 조회 1,985
16년 전 조회 1,753
16년 전 조회 1,627
17년 전 조회 1,312
17년 전 조회 2,191
17년 전 조회 3,252
17년 전 조회 2,180
17년 전 조회 1,758
17년 전 조회 1,531
17년 전 조회 2,061
17년 전 조회 4,751
17년 전 조회 1,433
17년 전 조회 2,166
17년 전 조회 2,151
17년 전 조회 2,422
17년 전 조회 2,170
17년 전 조회 4,456
17년 전 조회 2,949
17년 전 조회 2,888
17년 전 조회 1,617
17년 전 조회 1,260
17년 전 조회 3,965
17년 전 조회 1,636
17년 전 조회 1,633
17년 전 조회 2,133
17년 전 조회 1,904
17년 전 조회 1,520
17년 전 조회 3,938
17년 전 조회 1,773
17년 전 조회 3,155
17년 전 조회 3,022
17년 전 조회 1,055
17년 전 조회 1,869
17년 전 조회 1,613
17년 전 조회 1,864
17년 전 조회 2,658
17년 전 조회 3,041
17년 전 조회 3,238
17년 전 조회 3,347
17년 전 조회 1,481
17년 전 조회 1,436
17년 전 조회 2,276
17년 전 조회 2,002
17년 전 조회 2,309
17년 전 조회 2,835
17년 전 조회 3,283
17년 전 조회 2,378
17년 전 조회 1,651
17년 전 조회 3,226
17년 전 조회 3,085
17년 전 조회 3,064
17년 전 조회 3,935
17년 전 조회 2,608
17년 전 조회 2,429
17년 전 조회 2,677
17년 전 조회 2,915
17년 전 조회 2,633
17년 전 조회 1,473