php class를 관리

· 17년 전 · 1958
추천: 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,638
16년 전 조회 2,398
16년 전 조회 2,020
16년 전 조회 2,191
16년 전 조회 2,415
16년 전 조회 1,690
16년 전 조회 2,577
16년 전 조회 2,463
16년 전 조회 4,752
16년 전 조회 1,529
16년 전 조회 1,272
16년 전 조회 2,229
16년 전 조회 2,191
16년 전 조회 1,738
16년 전 조회 2,307
16년 전 조회 2,507
16년 전 조회 1,612
16년 전 조회 1,972
16년 전 조회 2,141
16년 전 조회 1,231
16년 전 조회 1,941
16년 전 조회 1,621
16년 전 조회 2,117
16년 전 조회 1,537
16년 전 조회 2,441
16년 전 조회 2,107
16년 전 조회 6,139
16년 전 조회 2,125
16년 전 조회 3,914
16년 전 조회 1,669
16년 전 조회 1,962
16년 전 조회 2,307
16년 전 조회 2,833
16년 전 조회 2,531
16년 전 조회 2,967
17년 전 조회 3,214
17년 전 조회 3,230
17년 전 조회 2,029
17년 전 조회 1,748
17년 전 조회 1,615
17년 전 조회 1,948
17년 전 조회 1,428
17년 전 조회 2,186
17년 전 조회 1,959
17년 전 조회 1,810
17년 전 조회 1,517
17년 전 조회 2,389
17년 전 조회 3,452
17년 전 조회 2,357
17년 전 조회 1,959
17년 전 조회 1,731
17년 전 조회 2,255
17년 전 조회 4,945
17년 전 조회 1,665
17년 전 조회 2,403
17년 전 조회 2,359
17년 전 조회 2,638
17년 전 조회 2,351
17년 전 조회 4,674
17년 전 조회 3,171
17년 전 조회 3,087
17년 전 조회 1,795
17년 전 조회 1,449
17년 전 조회 4,184
17년 전 조회 1,854
17년 전 조회 1,855
17년 전 조회 2,334
17년 전 조회 2,096
17년 전 조회 1,732
17년 전 조회 4,154
17년 전 조회 1,979
17년 전 조회 3,316
17년 전 조회 3,247
17년 전 조회 1,239
17년 전 조회 2,056
17년 전 조회 1,813
17년 전 조회 2,060
17년 전 조회 2,878
17년 전 조회 3,243
17년 전 조회 3,446
17년 전 조회 3,547
17년 전 조회 1,653
17년 전 조회 1,643
17년 전 조회 2,447
17년 전 조회 2,208
17년 전 조회 2,492
17년 전 조회 3,029
17년 전 조회 3,510
17년 전 조회 2,592
17년 전 조회 1,867
17년 전 조회 3,448
17년 전 조회 3,293
17년 전 조회 3,259
17년 전 조회 4,135
17년 전 조회 2,782
17년 전 조회 2,644
17년 전 조회 2,885
17년 전 조회 3,127
17년 전 조회 2,842
17년 전 조회 1,682