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
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
Mobile Dev World

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 : 5439
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;
    }
}
?>



Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP
The GTV.class allows you to extract a value between any HTML tag or between any TEXT on a web page.
Categories : PHP, PHP Classes, Regexps
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
Simple and fast user authentication
Categories : PHP, PHP Classes, Authentication
shopping cart class with add/edit/delete product functionality.
Categories : PHP, PHP Classes, Ecommerce
POP3 Class
Categories : PHP Classes, PHP, Email
MySQL Connection/Query Class
Categories : Databases, MySQL, PHP, PHP Classes
Simple class for accessing databases like MSSql Server, Oracle etc by Raju
Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle
Array Insertion
Categories : PHP, PHP Classes, Arrays
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
Generate HTML Calendar of a month of year
Categories : PHP, Calendar, PHP Classes