php class를 관리

· 17년 전 · 1823
추천: 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,497
16년 전 조회 2,267
16년 전 조회 1,893
16년 전 조회 2,052
16년 전 조회 2,279
16년 전 조회 1,562
16년 전 조회 2,391
16년 전 조회 2,335
16년 전 조회 4,610
16년 전 조회 1,379
16년 전 조회 1,131
16년 전 조회 2,088
16년 전 조회 2,065
16년 전 조회 1,597
16년 전 조회 2,132
16년 전 조회 2,364
16년 전 조회 1,475
16년 전 조회 1,819
16년 전 조회 2,004
16년 전 조회 1,099
16년 전 조회 1,778
16년 전 조회 1,482
16년 전 조회 1,989
16년 전 조회 1,401
16년 전 조회 2,292
16년 전 조회 1,978
16년 전 조회 5,957
16년 전 조회 1,998
16년 전 조회 3,769
16년 전 조회 1,548
16년 전 조회 1,832
16년 전 조회 2,147
16년 전 조회 2,694
16년 전 조회 2,391
16년 전 조회 2,828
16년 전 조회 3,075
16년 전 조회 3,095
16년 전 조회 1,895
16년 전 조회 1,619
16년 전 조회 1,486
16년 전 조회 1,806
16년 전 조회 1,284
16년 전 조회 2,051
16년 전 조회 1,824
17년 전 조회 1,691
17년 전 조회 1,378
17년 전 조회 2,254
17년 전 조회 3,314
17년 전 조회 2,234
17년 전 조회 1,824
17년 전 조회 1,592
17년 전 조회 2,124
17년 전 조회 4,805
17년 전 조회 1,497
17년 전 조회 2,234
17년 전 조회 2,198
17년 전 조회 2,485
17년 전 조회 2,225
17년 전 조회 4,516
17년 전 조회 3,019
17년 전 조회 2,957
17년 전 조회 1,674
17년 전 조회 1,318
17년 전 조회 4,042
17년 전 조회 1,696
17년 전 조회 1,702
17년 전 조회 2,200
17년 전 조회 1,965
17년 전 조회 1,590
17년 전 조회 4,007
17년 전 조회 1,837
17년 전 조회 3,211
17년 전 조회 3,099
17년 전 조회 1,120
17년 전 조회 1,934
17년 전 조회 1,688
17년 전 조회 1,936
17년 전 조회 2,718
17년 전 조회 3,112
17년 전 조회 3,296
17년 전 조회 3,414
17년 전 조회 1,543
17년 전 조회 1,503
17년 전 조회 2,326
17년 전 조회 2,059
17년 전 조회 2,373
17년 전 조회 2,898
17년 전 조회 3,351
17년 전 조회 2,447
17년 전 조회 1,713
17년 전 조회 3,293
17년 전 조회 3,150
17년 전 조회 3,132
17년 전 조회 3,994
17년 전 조회 2,665
17년 전 조회 2,483
17년 전 조회 2,733
17년 전 조회 2,977
17년 전 조회 2,692
17년 전 조회 1,524