php class를 관리

· 17년 전 · 2024
추천: 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,717
16년 전 조회 2,470
16년 전 조회 2,095
16년 전 조회 2,269
16년 전 조회 2,490
16년 전 조회 1,769
16년 전 조회 2,645
16년 전 조회 2,537
16년 전 조회 4,835
16년 전 조회 1,613
16년 전 조회 1,350
16년 전 조회 2,308
16년 전 조회 2,262
16년 전 조회 1,823
16년 전 조회 2,374
16년 전 조회 2,589
16년 전 조회 1,684
16년 전 조회 2,053
16년 전 조회 2,230
16년 전 조회 1,319
16년 전 조회 2,016
16년 전 조회 1,693
16년 전 조회 2,199
16년 전 조회 1,611
16년 전 조회 2,513
16년 전 조회 2,186
16년 전 조회 6,195
16년 전 조회 2,207
16년 전 조회 3,989
16년 전 조회 1,742
16년 전 조회 2,032
16년 전 조회 2,386
17년 전 조회 2,906
17년 전 조회 2,613
17년 전 조회 3,047
17년 전 조회 3,281
17년 전 조회 3,305
17년 전 조회 2,104
17년 전 조회 1,828
17년 전 조회 1,697
17년 전 조회 2,020
17년 전 조회 1,501
17년 전 조회 2,260
17년 전 조회 2,032
17년 전 조회 1,891
17년 전 조회 1,587
17년 전 조회 2,457
17년 전 조회 3,526
17년 전 조회 2,428
17년 전 조회 2,025
17년 전 조회 1,813
17년 전 조회 2,329
17년 전 조회 5,013
17년 전 조회 1,724
17년 전 조회 2,464
17년 전 조회 2,427
17년 전 조회 2,703
17년 전 조회 2,425
17년 전 조회 4,740
17년 전 조회 3,241
17년 전 조회 3,152
17년 전 조회 1,867
17년 전 조회 1,527
17년 전 조회 4,254
17년 전 조회 1,926
17년 전 조회 1,923
17년 전 조회 2,411
17년 전 조회 2,173
17년 전 조회 1,805
17년 전 조회 4,221
17년 전 조회 2,049
17년 전 조회 3,386
17년 전 조회 3,314
17년 전 조회 1,311
17년 전 조회 2,124
17년 전 조회 1,883
17년 전 조회 2,138
17년 전 조회 2,938
17년 전 조회 3,302
17년 전 조회 3,504
17년 전 조회 3,620
17년 전 조회 1,711
17년 전 조회 1,709
17년 전 조회 2,518
17년 전 조회 2,264
17년 전 조회 2,554
17년 전 조회 3,108
17년 전 조회 3,576
17년 전 조회 2,654
17년 전 조회 1,923
17년 전 조회 3,505
17년 전 조회 3,355
17년 전 조회 3,324
17년 전 조회 4,207
17년 전 조회 2,843
17년 전 조회 2,705
17년 전 조회 2,957
17년 전 조회 3,192
17년 전 조회 2,906
17년 전 조회 1,754