Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Model-Driven Migration im PHP-Umfeld

Model-Driven Migration im PHP-Umfeld

Slides of my lecture at the University of Applied Sciences Osnabrück at November 25th, 2015.

Martin Helmich

November 25, 2015
Tweet

More Decks by Martin Helmich

Other Decks in Programming

Transcript

  1. Model-Driven Migration im
    PHP-Umfeld
    Martin Helmich
    Mittwald CM Service GmbH & Co. KG
    Hochschule Osnabrück – Fakultät für Ingenieurwissenschaften und Informatik
    25. November 2015

    View Slide

  2. Martin Helmich
    Softwarearchitekt bei Mittwald CM Service
    2011 Fachinformatiker Anwendungsentwicklung
    2012 B.A. Wirtschaftinformatik, FH Vechta
    2015 M.Sc. Informatik, HS Osnabrück

    View Slide

  3. View Slide

  4. Altsystem ?
    Zielarchitektur
    ?

    View Slide

  5. Microservices
    Monolithische
    Applikation
    Komponenten Microservices
    Lewis und Fowler, 2014: Microservices (http://martinfowler.com/articles/microservices.html)
    Newman, 2015: Building Microservices, O‘Reilly-Verlag, Sebastopol

    View Slide

  6. CC BY-SA 3.0, Photones
    https://commons.wikimedia.org/wiki/File:Heureka_(Plastik).jpg

    View Slide

  7. Grafen

    View Slide

  8. Graphen
    Knoten
    Knoten
    Knoten

    View Slide

  9. View Slide

  10. View Slide

  11. Alice
    Bob
    Carol
    Dave
    „Finde alle Freunde von Alice“
    MATCH (alice{name:“Alice“})-[:FRIEND_OF]-(f)
    RETURN f

    View Slide

  12. Alice
    Bob
    Carol
    Dave
    „Finde alle Freunde von
    Freunden von Alice“
    MATCH (alice{name:“Alice“})
    -[:FRIEND_OF]-(f)
    -[:FRIEND_OF]-(foaf)
    RETURN foaf

    View Slide

  13. Alice
    Bob
    Carol
    Dave
    „Finde alle, die Alice über
    höchstens 5 Ecken kennt“
    MATCH (alice{name:“Alice“})
    -[:FRIEND_OF*1..5]-(f)
    RETURN f

    View Slide

  14. namespace HSOS;
    use MW\SuperFoo;
    class FooClass extends SuperFoo {
    // ...
    }
    class
    name=FooClass
    abstract=false
    final=false
    ...
    extends
    name=SuperFoo
    stmts
    namespace
    name=HSOS
    uses
    name=MW\SuperFoo
    stmts

    View Slide

  15. MATCH (class:Stmt_Class)-[:SUB_NAME]->(className)
    OPTIONAL MATCH (namespace:Stmt_Namespace)-[:SUB|HAS*]->(class),
    (namespace)-[:SUB_NAME]->(namespaceName)
    OPTIONAL MATCH (class)-[:SUB_EXTENDS]->(parentName)
    OPTIONAL MATCH (class)-[:SUB_IMPLEMENTS]->()-[:HAS]->(interfaceName)
    RETURN namespaceName.allParts, className.allParts, parentName.allParts,
    collect(interfaceName.allParts)
    „Ermittle aus den AST‘s aller importierten Dateien alle
    deklarierten PHP-Klassen und ihre Vererbungshierarchie“

    View Slide

  16. class
    name=Mw\Example\Car
    file
    name=src/Mw/Example/Car.php
    type
    name=Mw\Example\Car
    class
    name=Mw\Example\Wheel
    file
    name=src/Mw/Example/Wheel.php
    type
    name=Mw\Example\Wheel
    interface
    name=Mw\Example\Vehicle
    type
    name=Mw\Example\Vehicle
    file
    name=src/Mw/Example/Vehicle.php
    package
    name=mw/example
    CONTAINS_FILE
    DEFINED_IN DEFINED_IN
    DEFINED_IN
    IS IS IS
    property
    name=wheels
    visibility=private

    View Slide

  17. Typisierung in PHP
    – oder –
    „Warum ich PHP hasse“

    View Slide

  18. function test($a)
    {
    echo "Hallo" . $a;
    }
    Welchen Typ hat $a?

    View Slide

  19. if ($userInput > 5) {
    $a = $userInput;
    } else {
    $a = FALSE;
    }
    Welchen Typ hat $a?

    View Slide

  20. if (class_exists($userInput)) {
    $instance = new $userInput();
    } else {
    $instance = NULL;
    }
    Welchen Typ hat $a?

    View Slide

  21. MethodCall
    Variable
    String
    value=myObj
    String
    value=getFoo
    Collection
    IntegerScalar
    value=5
    $a = $myObj->getFoo(5);
    Assignment
    Variable
    String
    value=a
    value

    View Slide

  22. View Slide

  23. Monolithische
    Applikation

    View Slide

  24. Monolithische
    Applikation
    Microservice

    View Slide

  25. Monolithische
    Applikation
    Microservice
    Webservice
    (REST, AMQP, …)

    View Slide

  26. „Für jeden statischen Methodenaufruf einer Klasse aus einer
    anderen Klasse heraus, generiere eine USES-Beziehung zwischen
    den beiden Klassen“
    MATCH (name:Name)<-[:SUB {type: "class"}]-(call:Expr_StaticCall)
    <-[:SUB|HAS*]-(:Stmt_ClassMethod)
    <-[:HAS]-()
    <-[:SUB {type: "stmts"}]-(:Stmt_Class)
    <-[:DEFINED_IN]-(c:Class)
    WHERE call.class <> "parent" AND name.fullName IS NOT NULL
    MATCH (t:Type {name: name.fullName})
    MERGE (c)-[:USES]->(t)

    View Slide

  27. „Besteht eine USES-Beziehung zwischen zwei Klassen aus
    verschiedenen Paketen, erstelle eine DEPENDS_ON-Beziehung
    zwischen diesen beiden Paketen“
    MATCH (p1:Package)-[:CONTAINS_FILE]->(:File)
    -[:HAS|SUB*]->()
    <-[:DEFINED_IN]-(user)
    -[:USES]->(:Type)
    -[:IS]->(usee)
    -[:DEFINED_IN]->()
    <-[:HAS|SUB*]-(:File)
    <-[:CONTAINS_FILE]-(p2:Package)
    WHERE (user:Class OR user:Interface OR user:Trait) AND
    (usee:Class OR usee:Interface OR usee:Trait) AND
    p1 <> p2
    MERGE (p1)-[:DEPENDS_ON]->(p2)

    View Slide

  28. „Finde alle Pakete, die von Paket A abhängig sind“
    MATCH (p:Package {name: "A"})<-[:DEPENDS_ON]-(dependent)
    RETURN dependent

    View Slide

  29. View Slide

  30. Monolithische
    Applikation
    Microservice
    Webservice
    (REST, AMQP, …)

    View Slide

  31. View Slide

  32. Das Ergebnis
    https://github.com/mittwald/flow-metamorph
    https://github.com/martin-helmich/graphpizer-server
    https://github.com/martin-helmich/graphpizer-cli

    View Slide

  33. Abschlussarbeiten
    https://karriere.mittwald.de/berufseinsteiger/studenten.html

    View Slide