php class를 관리

· 17년 전 · 2032
추천: 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,719
16년 전 조회 2,476
16년 전 조회 2,101
16년 전 조회 2,273
16년 전 조회 2,500
16년 전 조회 1,774
16년 전 조회 2,649
16년 전 조회 2,541
16년 전 조회 4,839
16년 전 조회 1,618
16년 전 조회 1,357
16년 전 조회 2,311
16년 전 조회 2,266
16년 전 조회 1,827
16년 전 조회 2,383
16년 전 조회 2,594
16년 전 조회 1,695
16년 전 조회 2,055
16년 전 조회 2,234
16년 전 조회 1,326
16년 전 조회 2,020
16년 전 조회 1,697
16년 전 조회 2,203
16년 전 조회 1,618
16년 전 조회 2,520
16년 전 조회 2,191
16년 전 조회 6,202
16년 전 조회 2,214
16년 전 조회 3,994
16년 전 조회 1,749
16년 전 조회 2,038
16년 전 조회 2,397
17년 전 조회 2,914
17년 전 조회 2,618
17년 전 조회 3,055
17년 전 조회 3,288
17년 전 조회 3,313
17년 전 조회 2,111
17년 전 조회 1,835
17년 전 조회 1,702
17년 전 조회 2,027
17년 전 조회 1,508
17년 전 조회 2,266
17년 전 조회 2,040
17년 전 조회 1,896
17년 전 조회 1,594
17년 전 조회 2,461
17년 전 조회 3,531
17년 전 조회 2,431
17년 전 조회 2,033
17년 전 조회 1,817
17년 전 조회 2,336
17년 전 조회 5,018
17년 전 조회 1,728
17년 전 조회 2,469
17년 전 조회 2,433
17년 전 조회 2,710
17년 전 조회 2,436
17년 전 조회 4,747
17년 전 조회 3,245
17년 전 조회 3,159
17년 전 조회 1,871
17년 전 조회 1,532
17년 전 조회 4,262
17년 전 조회 1,928
17년 전 조회 1,930
17년 전 조회 2,419
17년 전 조회 2,177
17년 전 조회 1,812
17년 전 조회 4,224
17년 전 조회 2,053
17년 전 조회 3,391
17년 전 조회 3,318
17년 전 조회 1,316
17년 전 조회 2,129
17년 전 조회 1,885
17년 전 조회 2,142
17년 전 조회 2,942
17년 전 조회 3,308
17년 전 조회 3,508
17년 전 조회 3,624
17년 전 조회 1,719
17년 전 조회 1,715
17년 전 조회 2,524
17년 전 조회 2,266
17년 전 조회 2,557
17년 전 조회 3,115
17년 전 조회 3,580
17년 전 조회 2,658
17년 전 조회 1,925
17년 전 조회 3,510
17년 전 조회 3,356
17년 전 조회 3,326
17년 전 조회 4,211
17년 전 조회 2,846
17년 전 조회 2,708
17년 전 조회 2,963
17년 전 조회 3,196
17년 전 조회 2,909
17년 전 조회 1,759