php class를 관리

· 17년 전 · 1813
추천: 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,491
16년 전 조회 2,253
16년 전 조회 1,879
16년 전 조회 2,042
16년 전 조회 2,260
16년 전 조회 1,550
16년 전 조회 2,379
16년 전 조회 2,322
16년 전 조회 4,599
16년 전 조회 1,368
16년 전 조회 1,123
16년 전 조회 2,076
16년 전 조회 2,047
16년 전 조회 1,583
16년 전 조회 2,115
16년 전 조회 2,352
16년 전 조회 1,463
16년 전 조회 1,804
16년 전 조회 1,993
16년 전 조회 1,081
16년 전 조회 1,766
16년 전 조회 1,471
16년 전 조회 1,975
16년 전 조회 1,388
16년 전 조회 2,279
16년 전 조회 1,962
16년 전 조회 5,938
16년 전 조회 1,985
16년 전 조회 3,753
16년 전 조회 1,539
16년 전 조회 1,823
16년 전 조회 2,137
16년 전 조회 2,681
16년 전 조회 2,381
16년 전 조회 2,822
16년 전 조회 3,057
16년 전 조회 3,080
16년 전 조회 1,887
16년 전 조회 1,607
16년 전 조회 1,475
16년 전 조회 1,793
16년 전 조회 1,273
16년 전 조회 2,037
16년 전 조회 1,811
17년 전 조회 1,679
17년 전 조회 1,366
17년 전 조회 2,234
17년 전 조회 3,302
17년 전 조회 2,223
17년 전 조회 1,814
17년 전 조회 1,580
17년 전 조회 2,110
17년 전 조회 4,796
17년 전 조회 1,486
17년 전 조회 2,214
17년 전 조회 2,188
17년 전 조회 2,468
17년 전 조회 2,211
17년 전 조회 4,505
17년 전 조회 3,000
17년 전 조회 2,940
17년 전 조회 1,661
17년 전 조회 1,305
17년 전 조회 4,023
17년 전 조회 1,685
17년 전 조회 1,685
17년 전 조회 2,182
17년 전 조회 1,955
17년 전 조회 1,577
17년 전 조회 3,984
17년 전 조회 1,821
17년 전 조회 3,203
17년 전 조회 3,076
17년 전 조회 1,106
17년 전 조회 1,912
17년 전 조회 1,675
17년 전 조회 1,922
17년 전 조회 2,704
17년 전 조회 3,102
17년 전 조회 3,281
17년 전 조회 3,394
17년 전 조회 1,533
17년 전 조회 1,491
17년 전 조회 2,316
17년 전 조회 2,044
17년 전 조회 2,362
17년 전 조회 2,882
17년 전 조회 3,332
17년 전 조회 2,428
17년 전 조회 1,695
17년 전 조회 3,279
17년 전 조회 3,135
17년 전 조회 3,114
17년 전 조회 3,981
17년 전 조회 2,655
17년 전 조회 2,473
17년 전 조회 2,720
17년 전 조회 2,965
17년 전 조회 2,678
17년 전 조회 1,512