php class를 관리

· 17년 전 · 2018
추천: 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,710
16년 전 조회 2,467
16년 전 조회 2,090
16년 전 조회 2,266
16년 전 조회 2,486
16년 전 조회 1,765
16년 전 조회 2,640
16년 전 조회 2,532
16년 전 조회 4,831
16년 전 조회 1,610
16년 전 조회 1,345
16년 전 조회 2,302
16년 전 조회 2,256
16년 전 조회 1,815
16년 전 조회 2,369
16년 전 조회 2,585
16년 전 조회 1,681
16년 전 조회 2,047
16년 전 조회 2,225
16년 전 조회 1,316
16년 전 조회 2,011
16년 전 조회 1,693
16년 전 조회 2,194
16년 전 조회 1,605
16년 전 조회 2,503
16년 전 조회 2,181
16년 전 조회 6,190
16년 전 조회 2,203
16년 전 조회 3,984
16년 전 조회 1,735
16년 전 조회 2,027
16년 전 조회 2,381
17년 전 조회 2,901
17년 전 조회 2,610
17년 전 조회 3,039
17년 전 조회 3,275
17년 전 조회 3,298
17년 전 조회 2,100
17년 전 조회 1,826
17년 전 조회 1,692
17년 전 조회 2,013
17년 전 조회 1,501
17년 전 조회 2,255
17년 전 조회 2,030
17년 전 조회 1,887
17년 전 조회 1,579
17년 전 조회 2,454
17년 전 조회 3,522
17년 전 조회 2,426
17년 전 조회 2,019
17년 전 조회 1,809
17년 전 조회 2,322
17년 전 조회 5,009
17년 전 조회 1,719
17년 전 조회 2,461
17년 전 조회 2,423
17년 전 조회 2,694
17년 전 조회 2,419
17년 전 조회 4,738
17년 전 조회 3,234
17년 전 조회 3,147
17년 전 조회 1,862
17년 전 조회 1,524
17년 전 조회 4,253
17년 전 조회 1,921
17년 전 조회 1,919
17년 전 조회 2,406
17년 전 조회 2,167
17년 전 조회 1,802
17년 전 조회 4,219
17년 전 조회 2,045
17년 전 조회 3,386
17년 전 조회 3,310
17년 전 조회 1,306
17년 전 조회 2,121
17년 전 조회 1,875
17년 전 조회 2,134
17년 전 조회 2,935
17년 전 조회 3,297
17년 전 조회 3,502
17년 전 조회 3,618
17년 전 조회 1,708
17년 전 조회 1,706
17년 전 조회 2,514
17년 전 조회 2,261
17년 전 조회 2,549
17년 전 조회 3,104
17년 전 조회 3,572
17년 전 조회 2,646
17년 전 조회 1,923
17년 전 조회 3,505
17년 전 조회 3,354
17년 전 조회 3,322
17년 전 조회 4,206
17년 전 조회 2,840
17년 전 조회 2,704
17년 전 조회 2,952
17년 전 조회 3,190
17년 전 조회 2,904
17년 전 조회 1,748