PECL: Ein Griff in den Sprachbaukasten

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    PECL: Ein Griff in den Sprachbaukasten - Presentation Transcript

    1. PECL Der PHP-Sprachbaukasten Sebastian Bergmann http://sebastian-bergmann.de/
    2. Wer ich bin
      • Sebastian Bergmann
      • Diplom-Informatiker
      • Mitarbeit im PHP-Projekt seit 2000
      • Autor, Berater, Coach, Trainer
      • Entwickler bei eZ Systems AS
    3. Wer sind Sie?
      • Ihre Erfahrungen mit
        • PHP 5?
        • PECL?
        • Meta-Programmierung?
        • AOP?
    4. Spracherweiterungen für PHP
      • PECL enthält Erweiterungen, die
        • den PHP-Interpreter um Funktionalität erweitern oder
        • die „Eingriffe“ in den PHP-Interpreter sowie Zugriff auf PHP-Bytecode erlauben
          • Operator
          • VLD
          • Parsekit
          • Parse Tree
          • Runkit
          • Intercept
    5. ext/operator
      • Überladen von Operatoren
      • C++ bietet beispielsweise die Möglichkeit, Operatoren wie +, -, * und / zu überladen
      • Der Programmierer kann so für jede Klasse entscheiden, welche Semantik diese Operatoren für die Objekte der Klasse haben sollen
      • Ziel des Überladens der Operatoren ist eine Verbesserung der Lesbarkeit des Quelltextes
    6. ext/operator
      • +
      • -
      • *
      • /
      • %
      • <<
      • >>
      • .
      • .=
      • |
      • &
      • ^
      • ~
      • !
      • ++
      • --
      • +=
      • -=
      • *=
      • /=
      • %=
      • <<=
      • >>=
      • |=
      • &=
      • ^=
      • ~=
      • ===
      • !==
      • ==
      • !=
      • <
      • <=
      • >
      • >=
    7. ext/operator <?php class Fraction { public $numerator ; public $denominator ; public function __construct ( $n , $d = 1 ) { $this -> numerator = $n ; $this -> denominator = $d ; } } ?>
    8. ext/operator <?php class Fraction { // ... public function __toString () { return $this -> numerator . '/' . $this -> denominator ; } } ?>
    9. ext/operator <?php class Fraction { // ... public function __add ( Fraction $fraction ) { return new Fraction ( $this -> numerator * $fraction -> denominator + $fraction -> numerator * $this -> denominator , $this -> denominator * $fraction -> denominator ); } } ?>
    10. ext/operator <?php require_once 'Fraction.php' ; $a = new Fraction ( 2 , 3 ); $b = new Fraction ( 4 , 2 ); print $a + $b ; ?> 16/6
    11. ext/parse_tree
      • Liefert den Ableitungsbaum ( parse tree ) für PHP-Quelltext
      • Der Baum wird
        • als XML-Dokument erzeugt,
        • kann transformiert werden und
        • wieder als PHP-Quelltext gespeichert werden
      • Anwendungsfälle
        • Analyse und Refactoring von PHP-Quelltexten
        • Erweiterung der Syntax von PHP
    12. Exkurs: AspectPHP
      • Aspektorientierte Erweiterung von PHP nach dem Vorbild von AspectJ
      • Projekt im Google Summer of Code 2006
        • Parse Tree ist ein „Nebenprodukt“ dieses Projektes
    13. Exkurs (vom Exkurs): AOP
      • Neues Modularisationskonzept
        • Quantification
          • Führe Code C aus, wenn während der Ausführung von Programm P ein Ereignis E auftritt
        • Obliviousness
          • Programm P stellt keine Hooks oä. zur Verfügung, um beim Eintreten von Ereignis E zusätzlichen Code ausführen zu können
      • Funktionalität, die sonst über den gesamten Quelltext verstreut wäre, kann so in einem Aspekt gekapselt werden
    14. Exkurs (vom Exkurs): AOP New Object Join Point Method Call Join Point
    15. Exkurs: AspectPHP <?php aspect Singleton { public $instances = array (); pointcut newObject : new( SomeClass ( * )); around newObject { $className = $thisJoinPoint -> getClassName (); if (! isset ( $thisAspect -> instances [ $className ])) { $thisAspect -> instances [ $className ] = proceed (); } return $thisAspect -> instances [ $className ]; } private function SomeClass :: __clone () {} } ?>
    16. Exkurs: AspectPHP PHPAspect
    17. ext/runkit
      • Erlaubt das Ersetzen, Umbenennen und Löschen von Klassen, Methoden und Funktionen
      • Definition von zusätzlichen superglobalen Variablen
      • Ausführung von Code in einer isolierten Umgebung (Sandbox)
    18. ext/runkit <?php class Calculator {} $calculator = new Calculator ; runkit_method_add ( 'Calculator' , 'add' , '$a, $b' , 'return $a + $b;' , RUNKIT_ACC_PUBLIC ); print $calculator -> add ( 23 , 42 ); ?>
    19. Exkurs: GAP
      • G eneric A spects for P HP
        • Generisches Join-Point-Modell für PHP
          • Framework für Pointcut-Systeme
        • Aspekt-Generizität
      • Advice = “Normale” PHP-Methode
        • $joinPoint-Objekt innerhalb dieser Methode
        • Das mitgelieferte Pointcut-System nutzt Annotationen, um Advice-Code an Join-Points zu binden
    20. Exkurs: GAP <?php /* @pointcut allMethodCalls : method(* *->*(..)); * @after allMethodCalls : LoggingAspect->log(); */ class LoggingAspect { public function log ( $joinPoint ) { printf ( &quot;%s->%s() called %s->%s() &quot; , $joinPoint -> getSource ()-> getDeclaringClass () -> getName (), $joinPoint -> getSource ()-> getName (), $joinPoint -> getTarget ()-> getDeclaringClass () -> getName (), $joinPoint -> getTarget ()-> getName () ); } }
    21. ext/runkit weaveMethodJoinPoint ( ReflectionMethod $method ) { runkit_method_rename ( $method -> getDeclaringClass ()-> getName (), $method -> getName (), '__GAP_' . $method -> getName () ); runkit_method_add ( $method -> getDeclaringClass ()-> getName (), $method -> getName (), self :: generateMethodParameters ( $method ), 'return GAP_Dispatcher::getInstance() ->methodCall(new GAP_JoinPoint_Method);' ); }
    22. Ende
      • Vielen Dank für Ihr Interesse!
      • Das Präsentationsmaterial wird in Kürze unter http://sebastian-bergmann.de/talks/ verfügbar sein
    23. License
      • This presentation material is published under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported license.
      • You are free:
        • to Share – to copy, distribute and transmit the work.
      • Under the following conditions:
        • Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
        • Noncommercial. You may not use this work for commercial purposes.
        • No Derivative Works. You may not alter, transform, or build upon this work.
      • For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
      • Any of the above conditions can be waived if you get permission from the copyright holder.
      • Nothing in this license impairs or restricts the author's moral rights.

    + Sebastian BergmannSebastian Bergmann, 2 years ago

    custom

    1647 views, 0 favs, 3 embeds more stats

    Wie flexibel der Sprachkern von PHP, die Zend Engin more

    More Info

    CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

    Go to text version
    • Total Views 1647
      • 1579 on SlideShare
      • 68 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds
    • 62 views on http://sebastian-bergmann.de
    • 4 views on http://www.planet-php.net
    • 2 views on http://www.planet-php.org

    more

    All embeds
    • 62 views on http://sebastian-bergmann.de
    • 4 views on http://www.planet-php.net
    • 2 views on http://www.planet-php.org

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as innappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel

    Categories