php class를 관리

· 17년 전 · 1806
추천: 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,489
16년 전 조회 2,248
16년 전 조회 1,869
16년 전 조회 2,038
16년 전 조회 2,250
16년 전 조회 1,547
16년 전 조회 2,371
16년 전 조회 2,314
16년 전 조회 4,596
16년 전 조회 1,364
16년 전 조회 1,116
16년 전 조회 2,073
16년 전 조회 2,042
16년 전 조회 1,582
16년 전 조회 2,108
16년 전 조회 2,345
16년 전 조회 1,456
16년 전 조회 1,800
16년 전 조회 1,987
16년 전 조회 1,076
16년 전 조회 1,756
16년 전 조회 1,464
16년 전 조회 1,971
16년 전 조회 1,382
16년 전 조회 2,272
16년 전 조회 1,961
16년 전 조회 5,932
16년 전 조회 1,981
16년 전 조회 3,749
16년 전 조회 1,537
16년 전 조회 1,819
16년 전 조회 2,133
16년 전 조회 2,677
16년 전 조회 2,375
16년 전 조회 2,811
16년 전 조회 3,051
16년 전 조회 3,078
16년 전 조회 1,884
16년 전 조회 1,601
16년 전 조회 1,471
16년 전 조회 1,789
16년 전 조회 1,268
16년 전 조회 2,034
16년 전 조회 1,803
17년 전 조회 1,671
17년 전 조회 1,357
17년 전 조회 2,231
17년 전 조회 3,292
17년 전 조회 2,217
17년 전 조회 1,806
17년 전 조회 1,571
17년 전 조회 2,101
17년 전 조회 4,790
17년 전 조회 1,481
17년 전 조회 2,211
17년 전 조회 2,184
17년 전 조회 2,463
17년 전 조회 2,208
17년 전 조회 4,495
17년 전 조회 2,996
17년 전 조회 2,935
17년 전 조회 1,655
17년 전 조회 1,300
17년 전 조회 4,019
17년 전 조회 1,681
17년 전 조회 1,679
17년 전 조회 2,175
17년 전 조회 1,952
17년 전 조회 1,570
17년 전 조회 3,980
17년 전 조회 1,819
17년 전 조회 3,200
17년 전 조회 3,068
17년 전 조회 1,101
17년 전 조회 1,910
17년 전 조회 1,669
17년 전 조회 1,918
17년 전 조회 2,698
17년 전 조회 3,097
17년 전 조회 3,276
17년 전 조회 3,389
17년 전 조회 1,530
17년 전 조회 1,488
17년 전 조회 2,315
17년 전 조회 2,042
17년 전 조회 2,360
17년 전 조회 2,878
17년 전 조회 3,329
17년 전 조회 2,427
17년 전 조회 1,694
17년 전 조회 3,274
17년 전 조회 3,130
17년 전 조회 3,109
17년 전 조회 3,978
17년 전 조회 2,650
17년 전 조회 2,468
17년 전 조회 2,718
17년 전 조회 2,961
17년 전 조회 2,674
17년 전 조회 1,507