Object
Object Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Object   Login nu   Login
Object
 ««« Se kilde koden
Object
Object Basic Base  Component Db Db-basket Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
Object
Object
Object Index
 
Tilbage

Navn : Object.php


Sample code, tutorial

Sådan benyttes komponenten Object klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Object.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Object
    ::display($param1, $param2, $param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object
    = new Object($param1, $param2, $param3, ...);
    print
    $object->getHtml();
    ?>

Parent html

Sådan vises komponenten Object klassen

ERROR, Object->getHtml() *** ABSTRACT *** You MUST implement this

PHP source code

Den fulde PHP kildekode for Object klassen

<?
/**
* @package base
* @see HTML_BASE_COMMON_PATH.'/Object.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Reader.php');
require_once(
HTML_BASE_COMMON_PATH.'/Writer.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.php');
if (
defined('HTML_CACHE_UTIL_PATH')) {
    require_once(
HTML_CACHE_UTIL_PATH.'/Cache.php');
}
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
* The base class for all other classes
* You must extend this class and write your own getHtml() method
* <code>
* Usage:
*    class Demo extends Object {
*       function Demo() { $this->Object(); }      // Constructor
*       function getHtml() { return 'Hey Demo'; } // Abstract
*    }
* </code>
* @package base
*/

if (!defined('__CLASS__')) {
    
define('__CLASS__','Unknown __CLASS__');
}
class
Object {
    
/**
     * @var String $html Debug info
     */
    
var $html = '';

    
/**
     * @var String $sql The SQL
     */
    
var $sql  = '';

    
/**
     * Constructor
     */
    
function Object() {
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
            
$this->html .= "<!-- DEBUG: ".$this->getClassName()." -->\r\n";
        }
    }

    
/**
     * Returns the name of the instanciated class or the parameter if supplied
     * <code>
     * Usage:
     *    print $parent->getClassName();
     *    print $parent->getClassName(__CLASS__);
     * </code>
     * @static
     * @param  String $class The class name
     * @return String The name of the class
     */
    
function getClassName($class='') {
        
$classname = __CLASS__;
        if (!empty(
$this)) {
            if (
$class!='') {
                
$classname = $class;        
            } else {
                
$classname = ucfirst(get_class($this));
            }        
        }
        return
$classname;        
    }

    
/**
     * Get the formatted message and debug level and Log to file ?
     * @param int $level The debug level. ALL, QUERY, USER, DEBUG, INFO, WARN, ERROR, FATAL, EMAIL or NONE
     * @param String $msg The message to log
     * @return String The message in question
     */
    
function getMsg($level,$msg) {
        
$html = '';
        if (
defined('HTML_LOG_UTIL_PATH')) {
            switch (
$level) {
                case
LOG_LEVEL_DEBUG:
                    if (
$level & LOG_LEVEL) {
                        
$html .= "<!-- ";
                    }
                    break;
                case
LOG_LEVEL_ALL:
                case
LOG_LEVEL_QUERY:
                case
LOG_LEVEL_USER:
                case
LOG_LEVEL_INFO:
                case
LOG_LEVEL_WARN:
                case
LOG_LEVEL_ERROR:
                case
LOG_LEVEL_FATAL:
                case
LOG_LEVEL_EMAIL:
                case
LOG_LEVEL_NONE:
                    
// Known Log Levels
                    
break;
                default:
                    
$msg .= "Class: ".$this->getClassName()."<br />\r\n"."->getMsg(), Unknown LOG_LEVEL found, level=".$level;
                    
Log::fatal(__FILE__,__LINE__,$msg);
                    die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n$msg");
                    break;
            }
            if (
$level & LOG_LEVEL) {
                
$html .= Log::getLevelName($level).', '.$msg;
            }
            switch (
$level) {
                case
LOG_LEVEL_DEBUG:                   // TODO timestamp and log to file
                    
if ($level & LOG_LEVEL) {
                        
$html .= " -->\r\n"; // 2008-03-13 added \r\n because of ../doc/*
                    
}
                    break;
                case
LOG_LEVEL_FATAL:
                    
$msg .= "Class: ".$this->getClassName()."<br />\r\nObject->getMsg(), FATAL error, cannot continue, sorry";
                    if (
$level & LOG_LEVEL) {
                        die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".$msg); // STOP
                    
} else {
                        
$html .= "<br />\r\n".$msg;  // continue ??
                    
}
                    break;
                default:
                    if (
$level & LOG_LEVEL) {
                        
$html .=  "<br />\r\n";
                    }
                    break;
            }
        } else {
            
$html .= "<!-- $level, $msg -->\r\n";
        }
        return
$html;
    }

    
/**
     * Add the current html to the Cache object
     * If the cache is disabled, just print the html
     * <code>
     * Usage:
     *   $element = new Element();   
     *   $element->addHtml();
     * Or
     *   $element = new Element();   
     *   $element->addHtml($object->getHtml());
     * </code>
     * @param String $html Use other html than fetched from $element->getHtml()
     */
    
function addHtml($html='') {
        if (
defined('HTML_CACHE_UTIL_PATH')) {
            if (
$html!='') {
                
Cache::add($html);
            } else {
                
Cache::add($this->getHtml());
            }
        } else {
            
/**
             * The Cache object is not available
             */
            
if ($html!='') {
                print
$html;
            } else {
                print
$this->getHtml();
            }
        }
    }

    
/**
     * Returns the html for the element
     * @abstract
     * @return String The complete html
     */
    
function getHtml() {
        
$html = '';
        
$msg = $this->getClassName()."->getHtml() ***   ABSTRACT  ***  You MUST implement this";
        if (
defined('HTML_LOG_UTIL_PATH')) {
            
$html .= $this->getMsg(LOG_LEVEL_ERROR, $msg);
        } else {
            return
'File: '.__FILE__.' Line:'.__LINE__." $msg";
        }
        return
$html;
    }

    
/**
     * Returns the information for this class
     * <code>
     * Usage:
     *   print Link::toString('Link'); // static or
     *   print Link->toString();       // instanciated
     * </code>
     * @param  String $path   The path to the source files
     * @param  String $class  The name of a valid class name or $this
     * @return String The complete info for the class in html
     */
    
function toString($path='',$class='') {
        if (
$class!='') {
            
// require_once($path.'/'.$class);  ???
            
$me = new $class();
        } else {
            
$me = ucfirst($this->getClassName()); // Must be used for v 4.x
        
}
        
$html  = '';
        
$html .= $me."<br />\r\n";
        if (
file_exists(HTML_BASE_COMMON_PATH.'/'.$me.'.php')) {
            
// Problem with ob_xxx ??
            //$source = ShowSouce(HTML_BASE_COMMON_PATH, $me.'.php');
            //$html .= $source->getHtml();
        
}

        
// TODO, add more class info, like methods, class members
        // TODO, may be also, show the phpdoc ?? remember to scramble (md5)
        
return $html;
    }
    
    
/**
     * Returns the name of the cache file name
     * If empty name, create a cache file name
     * @param  String $path The Path, Where to store the cache files
     * @return String The path/name of the cache file
     */
    
function getCacheFileName($path='') {
        return
Writer::getCacheFileName($path, $this->getClassName());
    }
    
    
/**
     * Save the cache file
     * @param  String $content The html content to save as cache file
     * @param  String $path    The Path, Where to store the cache files
     * @return boolean True on succes, false if failure
     */
    
function save($content, $path) {
        return
Writer::save($content, $this->getCacheFileName($path), $this->getClassName());
    }
    
    
/**
     * Read the content of the specified filename
     * <code>
     * Usage:
     *    $object = new Object();
     *    $content = $object->content($filename);
     * Or
     *    $content = Object::content($filename);
     * </code>
     * @static
     * @param  String $filename The filename to read
     * @return String The content or empty
     */
    
function content($filename) {
        return
Reader::content($filename);
    }

    
/**
     * Stop the program and dump the messages and the cache
     * Note: The content is not cached
     * <code>
     * Usage:
     *    Object::stop($message, __FILE__, __LINE__);
     * </code>
     * @param  String $message The message to show
     * @param  String $line    The Filename where the user stopped
     * @param  String $file    The Line to stop
     */
    
function stop($message='', $file='', $line='') {
        if (
$message != '') {
            
Message::add($message, $file, $line);
        }
        
Message::display();
        
/**
         * The Cache system
         * Save the cached content and print the cached content
         */
        
if (defined('HTML_CACHE_UTIL_PATH')) {
            print
Cache::content();
        } else {
            
// Ok, Ignore cache
        
}
        exit;
    }
    
}
?>

HTML source code

Den fulde HTML kildekode for Object klassen

<?
ERROR
, Object->getHtml() ***   ABSTRACT  ***  You MUST implement this<br />

?>

Class methods

Her er 'klasse metoderne' for Object klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • stop

Object vars

Her er 'objekt variable' for Object klassen:

  • html =>
  • sql =>

Object

Vis denne side på danmark

Vis denne side på Germany

Vis denne side på England

Vis denne side på France

Vis denne side på Italy

Vis denne side på Norge

Vis denne side på Sverige

Vis denne side på USA


 
Object
Object Copyright @ 1999-2009 www.Finn-Rasmussen.com Powered by myPHP Version 1.10
Object