PECL: Der PHP-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

    Notes on slide 1

    Theme created by Sakari Koivunen and Henrik Omma Released under the LGPL license.

    1 Favorite

    PECL: Der PHP-Sprachbaukasten - Presentation Transcript

    1. Willkommen!
        • PECL
        • Der PHP-Sprachbaukasten
        • Sebastian Bergmann
        • http://sebastian-bergmann.de/
        • 22. Mai 2007
    2. Wer ich bin
      • Sebastian Bergmann
      • Diplom-Informatiker
      • Mitarbeit im PHP-Projekt seit 2000
      • Autor, Berater, Trainer
      • Entwickler bei eZ Systems AS
    3. Wer sind Sie?
      • Ihre PHP-Erfahrungen
        • 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. VLD (Vulcan Logic Disassembler)
      • Disassembler für PHP-Bytecode
        • alias vld=&quot;php -dvld.active=1 -dvld.execute=0&quot;
      • Interessant für Entwickler von PHP-Erweiterungen wie Bytecode-Optimierern oder Xdebug
    12. ext/parsekit
      • Erlaubt Lesezugriff auf Op-Arrays (PHP-Bytecode)
      • Zwei Funktionen
        • parsekit_compile_string()
        • parsekit_compile_file()
      • Rückgabewert: Mehrdimensionales Array
      • Kann genutzt werden, um eine Quelltextdatei
        • zu analysieren oder
        • auf Syntaxfehler zu überprüfen
    13. ext/parse_tree
      • Liefert den Ableitungsbaum (englisch: 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
    14. 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
    15. 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.
    16. Exkurs (vom Exkurs): AOP New Object Join Point Method Call Join Point
    17. 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 () {} } ?>
    18. Exkurs: AspectPHP PHPAspect
    19. 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)
    20. 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 ); ?>
    21. 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
    22. 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 () ); } }
    23. 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);' ); }
    24. ext/intercept
      • “Abfangen” von Funktionsaufrufen
      • Erlaubt die Ausführung von Code vor und nach der Ausführung einer aufgerufenen Funktion
        • Erlaubt die AOP-Advices before und after, aber nicht around.
    25. ext/intercept <?php function foo () { print &quot;foo() &quot; ; } function before () { print &quot;before advice &quot; ; } function after () { print &quot;after advice &quot; ; } intercept_add ( 'foo' , 'before' , PRE_INTERCEPT ); intercept_add ( 'foo' , 'after' , POST_INTERCEPT ); foo ();
    26. Ende
      • Vielen Dank für Ihr Interesse!
      • Das Präsentationsmaterial wird in Kürze unter http://sebastian-bergmann.de/talks/ verfügbar sein.
    27. 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, 3 years ago

    custom

    2451 views, 1 favs, 1 embeds more stats

    More info about this document

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

    Go to text version

    • Total Views 2451
      • 2449 on SlideShare
      • 2 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds
    • 2 views on http://sebastian-bergmann.de

    more

    All embeds
    • 2 views on http://sebastian-bergmann.de

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

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

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories