PHP code example of cr0 / interceptor-php

1. Go to this page and download the library: Download cr0/interceptor-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cr0 / interceptor-php example snippets

 php

use SeuNamespace\Customer;  
class AspectExample {     
    public function beforeGetName(Customer $subject, string $name){ 
        echo "Calling before GetName Method";            
        // Executa antes do método getName() e retorna um array com parametros      alterados        
        return [             "Nome substituido"         
        ];     
    }      
    public function aroundGetName(Customer $subject, string $name) : string     {  
        echo "Calling around GetName Method";       
        // Substitui o método getName() e retorna um valor personalizado         
        return "Teste 123";     
    }      
    public function afterGetName(Customer $subject, $out)     { 
        echo "Calling after GetName Method";            
        // Executa após o método getName()         
        echo $out;         
        return $out;     
    } 
}