php class를 관리

· 17년 전 · 2194
추천: 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,885
16년 전 조회 2,651
16년 전 조회 2,280
16년 전 조회 2,440
16년 전 조회 2,674
16년 전 조회 1,934
16년 전 조회 2,827
16년 전 조회 2,713
16년 전 조회 5,010
16년 전 조회 1,803
16년 전 조회 1,538
16년 전 조회 2,484
16년 전 조회 2,432
16년 전 조회 2,011
16년 전 조회 2,550
16년 전 조회 2,746
16년 전 조회 1,852
16년 전 조회 2,233
16년 전 조회 2,409
16년 전 조회 1,488
16년 전 조회 2,196
16년 전 조회 1,879
16년 전 조회 2,375
16년 전 조회 1,776
16년 전 조회 2,676
16년 전 조회 2,372
16년 전 조회 6,356
17년 전 조회 2,374
17년 전 조회 4,136
17년 전 조회 1,900
17년 전 조회 2,200
17년 전 조회 2,552
17년 전 조회 3,070
17년 전 조회 2,767
17년 전 조회 3,200
17년 전 조회 3,445
17년 전 조회 3,471
17년 전 조회 2,278
17년 전 조회 1,989
17년 전 조회 1,865
17년 전 조회 2,189
17년 전 조회 1,665
17년 전 조회 2,424
17년 전 조회 2,201
17년 전 조회 2,045
17년 전 조회 1,742
17년 전 조회 2,620
17년 전 조회 3,696
17년 전 조회 2,579
17년 전 조회 2,195
17년 전 조회 1,962
17년 전 조회 2,491
17년 전 조회 5,187
17년 전 조회 1,885
17년 전 조회 2,629
17년 전 조회 2,591
17년 전 조회 2,871
17년 전 조회 2,585
17년 전 조회 4,919
17년 전 조회 3,413
17년 전 조회 3,321
17년 전 조회 2,042
17년 전 조회 1,707
17년 전 조회 4,432
17년 전 조회 2,095
17년 전 조회 2,101
17년 전 조회 2,587
17년 전 조회 2,339
17년 전 조회 1,972
17년 전 조회 4,378
17년 전 조회 2,205
17년 전 조회 3,564
17년 전 조회 3,484
17년 전 조회 1,477
17년 전 조회 2,256
17년 전 조회 2,035
17년 전 조회 2,285
17년 전 조회 3,092
17년 전 조회 3,452
17년 전 조회 3,659
17년 전 조회 3,777
17년 전 조회 1,869
17년 전 조회 1,871
17년 전 조회 2,677
17년 전 조회 2,424
17년 전 조회 2,705
17년 전 조회 3,254
17년 전 조회 3,713
17년 전 조회 2,796
17년 전 조회 2,071
17년 전 조회 3,641
17년 전 조회 3,509
17년 전 조회 3,470
17년 전 조회 4,346
17년 전 조회 2,998
17년 전 조회 2,844
17년 전 조회 3,104
17년 전 조회 3,321
17년 전 조회 3,048
17년 전 조회 1,907