php class를 관리

· 17년 전 · 2015
추천: 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,703
16년 전 조회 2,463
16년 전 조회 2,081
16년 전 조회 2,260
16년 전 조회 2,481
16년 전 조회 1,761
16년 전 조회 2,636
16년 전 조회 2,527
16년 전 조회 4,823
16년 전 조회 1,605
16년 전 조회 1,339
16년 전 조회 2,295
16년 전 조회 2,250
16년 전 조회 1,809
16년 전 조회 2,365
16년 전 조회 2,580
16년 전 조회 1,675
16년 전 조회 2,038
16년 전 조회 2,221
16년 전 조회 1,313
16년 전 조회 2,007
16년 전 조회 1,688
16년 전 조회 2,187
16년 전 조회 1,601
16년 전 조회 2,496
16년 전 조회 2,179
16년 전 조회 6,189
16년 전 조회 2,194
16년 전 조회 3,980
16년 전 조회 1,731
16년 전 조회 2,018
16년 전 조회 2,378
16년 전 조회 2,895
17년 전 조회 2,604
17년 전 조회 3,035
17년 전 조회 3,272
17년 전 조회 3,289
17년 전 조회 2,095
17년 전 조회 1,820
17년 전 조회 1,687
17년 전 조회 2,009
17년 전 조회 1,497
17년 전 조회 2,248
17년 전 조회 2,022
17년 전 조회 1,877
17년 전 조회 1,573
17년 전 조회 2,449
17년 전 조회 3,520
17년 전 조회 2,419
17년 전 조회 2,016
17년 전 조회 1,802
17년 전 조회 2,320
17년 전 조회 4,999
17년 전 조회 1,717
17년 전 조회 2,457
17년 전 조회 2,418
17년 전 조회 2,689
17년 전 조회 2,413
17년 전 조회 4,733
17년 전 조회 3,231
17년 전 조회 3,143
17년 전 조회 1,858
17년 전 조회 1,518
17년 전 조회 4,248
17년 전 조회 1,916
17년 전 조회 1,915
17년 전 조회 2,398
17년 전 조회 2,164
17년 전 조회 1,798
17년 전 조회 4,216
17년 전 조회 2,044
17년 전 조회 3,383
17년 전 조회 3,307
17년 전 조회 1,298
17년 전 조회 2,117
17년 전 조회 1,869
17년 전 조회 2,131
17년 전 조회 2,934
17년 전 조회 3,293
17년 전 조회 3,493
17년 전 조회 3,613
17년 전 조회 1,706
17년 전 조회 1,702
17년 전 조회 2,510
17년 전 조회 2,259
17년 전 조회 2,546
17년 전 조회 3,095
17년 전 조회 3,569
17년 전 조회 2,645
17년 전 조회 1,919
17년 전 조회 3,501
17년 전 조회 3,349
17년 전 조회 3,313
17년 전 조회 4,200
17년 전 조회 2,835
17년 전 조회 2,700
17년 전 조회 2,949
17년 전 조회 3,188
17년 전 조회 2,898
17년 전 조회 1,744