Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Object   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tls.gif     Base  trs.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Object.php


Vis: Sample code, tutorial

Object, 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();
    ?>

Skjul: Sådan vises komponenten

Object, Sådan vises komponenten

Sådan vises komponenten Object klassen

  • abstract class Object { ... }

Vis: PHP source code

Object, PHP source code

Den fulde PHP kildekode for Object klassen

<?php
/**
 * @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.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_COMMON_PATH.'/Reader.php');
require_once(
HTML_BASE_COMMON_PATH.'/Writer.php');
if (
defined('HTML_BASIC_UTIL_PATH')) {
    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');
}
//if (defined('HTML_BASIC_UTIL_PATH')) {
//    require_once(HTML_BASIC_UTIL_PATH.'/Message.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
 */

abstract class Object {
    
/**
     * @var String $html Debug info
     */
    
protected $html '';

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

    
/**
     * Constructor
     */
    
function __construct() {
        if (
defined('DEBUG_LEVEL_SHOW_INFO') && 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($msg__FILE____LINE__);
                    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 {
            die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\nlevel: $level msg=$msg");
//            $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:
     *   $object = new Link("Finn Rasmussen","http://finnrasmussen.dk");
     *   $element = new Element();   
     *   $element->addHtml($object);
     * 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
     */
    
abstract public 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;
//    }

    /**
     * Return the html
     * <code>
     * Usage:
     *   print $someClass; // instanciated
     * </code>
     * @return String The complete info for the class in html
     */
    
public final function __toString() {
        return 
$this->getHtml();
    }
    
    
/**
     * 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
     */
    
public 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
     */
    
public 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
     */
    
public static 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
//     */
//    public static function stop($message='', $file='', $line='') {
//        if (defined('HTML_BASIC_UTIL_PATH')) {
//            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;
//    }
//    
}
?>

Vis: HTML source code

Object, HTML source code

Den fulde HTML kildekode for Object klassen

<?
<ul><li>abstract class Object { ... }</li></ul>

?>

Vis: Class methods

Object, Class methods

Her er 'klasse metoderne' for Object klassen:

  • getHtml
  • __construct
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Object, Object vars

Her er 'objekt variable' for Object klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze3) 1.11
blank.gif