WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Aspect-Oriented Programming Library fo PHP
Categories : PHP, PHP Classes, Aspect Oriented Programming Click here to Update Your Picture
Dmitry Sheiko
Date : Oct 14th 2005
Grade : 2 of 5 (graded 2 times)
Viewed : 4589
File : 4237.zip
Images : No Images for this code example.
Search : More code by Dmitry Sheiko
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

file:Sample.php
<?PHP
/*
When we are developing big complex projects Object-Oriented programming paradigm isn't able
to provide a clear structure of business logic components. Aspect-Oriented Programming
allows to separate business logic and through functionality (logging, caching, transaction control, etc).

AOP Library for PHP extends basic PHP capabilities using Aspect-Oriented constructions. You
can learn more about Aspect-Oriented Programming at http://en.wikipedia.org/wiki/Aspect-oriented_programming
*/
include("aop.lib.php");
$aspect1 = new Aspect();
$pc1 = $aspect1->pointcut("call Sample::Sample  or call Sample::Sample2");
$pc1->_before("print 'PreProcess<br />';");
$pc1->_after("print 'PostProcess<br />';");
$pc1->destroy();


Class
Sample {
    var
$aspect;
    function
Sample($aspect1) {
       
$this->aspect = &$aspect1;
       
Advice::_before($this->aspect);
        print
'Some business logic of Sample<br />';
       
Advice::_after($this->aspect);
    }
    function
Sample2() {
       
Advice::_before($this->aspect);
        print
'Some business logic of Sample2<br />';
       
Advice::_after($this->aspect);
    }
   
}

$Sample = new Sample(&$aspect1);
$Sample->Sample2();
?>



file:aop.lib.php
<?PHP
/*
* @package Aspect-Oriented Programming Library
* @author $Author: sheiko $ 
* @version $Id: oap.lib.php,v 1.0 2005/10/14 15:58:15 sheiko Exp $
* @since v.1.0
* @copyright (c) Dmitry Sheiko http://www.cmsdevelopment.com
*/

/**
* Aspect class, which declare an aspect
* @package Aspect-Oriented Programming Library
* @author $Author: sheiko $
*/
class Aspect {
   
    var
$pointcuts;
   
     
/**
    * Class constructor
    * @return object
    */     
   
function Aspect() {
       
$this->pointcuts = array("AAA");
        return
$this;
    }
   
   
/**
    * Add set of join points
    * @param string $CommandString special string in format "call MethodName1 or call MethodName2"
    * @return boolean
    */     
   
function pointcut($CommandString) {
        return new
Pointcut($CommandString, &$this->pointcuts);
    }

   
/**
    * Class destructor
    * @return boolean
    */         
   
function destroy() {
        unset(
$this);
    }
}

/**
* Pointcut class, which declare an pointcut of the aspect (http://en.wikipedia.org/wiki/Advice_in_aspect-oriented_programming)
* @package Aspect-Oriented Programming Library
* @author $Author: sheiko $
*/
class Pointcut extends Aspect {

    var
$Methods;
    var
$pointcuts;

     
/**
    * Class constructor
    * @return object
    */         
   
function Pointcut($CommandString, $pointcutsReference) {
       
$this->Methods = array();
       
$this->pointcuts = &$pointcutsReference;

       
// Validate Input Parameters
       
if(!is_string($CommandString)) trigger_error("CommandString parameter must be STRING", E_USER_ERROR);
       
       
// Parse CommandString
       
$this->Methods = split(" ", strtolower( preg_replace("/\s\s+/", " ", preg_replace("/(call\s|or\s)/is", "", trim($CommandString)))));
        if(!
$this->Methods) trigger_error("CommandString does not contain methods names", E_USER_ERROR);
        return
true;
    }

   
/**
    * Processing of start point
    * @param string $EvalCode
    * @return boolean
    */         
   
function _before($EvalCode) {
       
$this->__apply("_before", $EvalCode);
        return
true;
    }
   
/**
    * Processing of finish point
    * @param string $EvalCode
    * @return boolean
    */         
   
function _after($EvalCode) {
       
$this->__apply("_after", $EvalCode);
        return
true;
    }
       
   
/**
    * Private service method
    * @param string $Point (_before|_after)
    * @param string $EvalCode
    * @return boolean
    */         
   
   
function __apply($Point, $EvalCode) {
       
$Method = '';
       
// Validate Input Parameters
       
if(!$EvalCodetrigger_error("This function parameter is invalid. Value of the parameter has to satisfy the eval code syntax", E_USER_ERROR);
        if(!
$this->Methods) trigger_error("There is a need to define pointcut", E_USER_ERROR);
        foreach(
$this->Methods as $Method) {
           
$this->pointcuts[$Method][$Point] = $EvalCode;
        }
        return
true;
    }
   
     
/**
    * Class destructor
    * @return boolean
    */         
   
function destroy() {
        unset(
$this);
    }
   
}

/**
* Advice service function package (http://en.wikipedia.org/wiki/Advice_in_aspect-oriented_programming)
* @package Aspect-Oriented Programming Library
* @author $Author: sheiko $
*/

class Advice {
   
/**
    * Parent method name getting
    * @return boolean
    */     
   
function getMethodName() {
       
$backtrace = debug_backtrace();
        return
$backtrace[2]["class"]."::".$backtrace[2]["function"];
    }
   
/**
    * _Before process declaration
    * @param object $AspectObj
    * @return boolean
    */     
   
function _before($AspectObj) {
       
$MethodName = '';
        if (
gettype($AspectObj)!="object") trigger_error("This function parameter is invalid. Value of the parameter has to satisfy the Aspect object requirements", E_USER_ERROR);
        if(
$AspectObj->pointcuts [Advice::getMethodName()]["_before"]) {
           
$Result = @eval($AspectObj->pointcuts [Advice::getMethodName()]["_before"]." return true;" );
            if(!
$Result) _trigger::error("_before process of the applied Aspect contains incorrect eval code");
        }
        return
true;
    }
   
/**
    * _After process declaration
    * @param object $AspectObj
    * @return boolean
    */     
   
function _after($AspectObj) {
       
$MethodName = '';
        if (
gettype($AspectObj)!="object") trigger_error("This function parameter is invalid. Value of the parameter has to satisfy the Aspect object requirements", E_USER_ERROR);
        if(
$AspectObj->pointcuts [Advice::getMethodName()]["_after"]) {
           
$Result = @eval($AspectObj->pointcuts [Advice::getMethodName()]["_after"]." return true;" );
            if(!
$Result) _trigger::error("_after process of the applied Aspect contains incorrect eval code");
        }
        return
true;
    }
}

/**
* Trigger service function package
* @package Aspect-Oriented Programming Library
* @author $Author: sheiko $
*/
class _trigger {
   
/**
    * Error trigger
    * @param string $ErrorMessage
    * @return boolean
    */     
   
function error($ErrorMessage) {
       
$backtrace = debug_backtrace();
       
$index = 2;
        die(
"<b>AOP Error:</b> ".$ErrorMessage." in <b>".$backtrace[$index]["file"]."</b> on line <b>".$backtrace[$index]["line"]."</b>");
        return
true;
    }
}
?>



file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data.
Categories : PHP, Linux, PHP Classes
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
XML To Array
Categories : PHP, PHP Classes, XML, Arrays