php class를 관리

· 17년 전 · 1979
추천: 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,661
16년 전 조회 2,420
16년 전 조회 2,038
16년 전 조회 2,216
16년 전 조회 2,439
16년 전 조회 1,707
16년 전 조회 2,596
16년 전 조회 2,482
16년 전 조회 4,771
16년 전 조회 1,552
16년 전 조회 1,294
16년 전 조회 2,253
16년 전 조회 2,219
16년 전 조회 1,761
16년 전 조회 2,332
16년 전 조회 2,536
16년 전 조회 1,631
16년 전 조회 1,992
16년 전 조회 2,163
16년 전 조회 1,254
16년 전 조회 1,962
16년 전 조회 1,643
16년 전 조회 2,139
16년 전 조회 1,560
16년 전 조회 2,459
16년 전 조회 2,126
16년 전 조회 6,158
16년 전 조회 2,150
16년 전 조회 3,934
16년 전 조회 1,692
16년 전 조회 1,988
16년 전 조회 2,329
16년 전 조회 2,855
16년 전 조회 2,558
17년 전 조회 2,989
17년 전 조회 3,235
17년 전 조회 3,253
17년 전 조회 2,047
17년 전 조회 1,773
17년 전 조회 1,637
17년 전 조회 1,967
17년 전 조회 1,452
17년 전 조회 2,203
17년 전 조회 1,979
17년 전 조회 1,827
17년 전 조회 1,532
17년 전 조회 2,415
17년 전 조회 3,475
17년 전 조회 2,376
17년 전 조회 1,980
17년 전 조회 1,752
17년 전 조회 2,275
17년 전 조회 4,963
17년 전 조회 1,685
17년 전 조회 2,425
17년 전 조회 2,376
17년 전 조회 2,657
17년 전 조회 2,374
17년 전 조회 4,695
17년 전 조회 3,188
17년 전 조회 3,106
17년 전 조회 1,819
17년 전 조회 1,474
17년 전 조회 4,204
17년 전 조회 1,877
17년 전 조회 1,880
17년 전 조회 2,357
17년 전 조회 2,123
17년 전 조회 1,758
17년 전 조회 4,177
17년 전 조회 1,997
17년 전 조회 3,344
17년 전 조회 3,268
17년 전 조회 1,263
17년 전 조회 2,075
17년 전 조회 1,839
17년 전 조회 2,086
17년 전 조회 2,899
17년 전 조회 3,263
17년 전 조회 3,467
17년 전 조회 3,577
17년 전 조회 1,672
17년 전 조회 1,670
17년 전 조회 2,472
17년 전 조회 2,224
17년 전 조회 2,516
17년 전 조회 3,052
17년 전 조회 3,533
17년 전 조회 2,614
17년 전 조회 1,889
17년 전 조회 3,468
17년 전 조회 3,314
17년 전 조회 3,280
17년 전 조회 4,162
17년 전 조회 2,797
17년 전 조회 2,664
17년 전 조회 2,916
17년 전 조회 3,152
17년 전 조회 2,859
17년 전 조회 1,703