PHP and its community has evolved really fast in the last few years to allow for professional architectures and solutions. However, there are thousands of existing PHP applications which have not evolved in the meantime and are now crippled and unmaintainable because of that. These applications represent a real threat to the competitiveness of the business that relies on them.
The best approach in terms of business to solve this problem is progressive rewrite. Symfony2 and its modular architecture make it possible. This talk will cover the main technical difficulties of the progressive approach when rewriting legacy PHP applications using Symfony2
2. The
need
for
progressive
rewrite
The
technical
challenges
faced
Theodo
Evolu=on
12/10/2012
2
THEODO
3. Total
rewrite
is
dangerous
for
the
business
Downsides
of
progressive
rewrite
• New
developments
are
invisible
un0l
the
new
version
is
finished
• You
need
twice
more
developers:
one
team
to
maintain
the
old
applica0on,
while
the
second
team
is
wri0ng
the
new
version
• The
probability
of
forgeDng
features
during
the
rewrite
is
high
12/10/2012
3
THEODO
4. Progressive
rewrite
is
a
very
difficult
technical
challenge
The
challenge
of
progressive
rewrite
• It
might
be
hard
to
make
the
hos0ng
system
evolve
• You
have
to
work
with
hard-‐to-‐read
code
• The
exis0ng
«
spageJhi
code
»
has
to
be
separated
into
independent
pieces
12/10/2012
4
THEODO
5. Progressive rewrite is harder but more profitable
Graphical
comparison
Functionalities
Functionalities
Evolu=on
Time Time
• No new features for months • Only 1 app to maintain
• 2 apps to maintain • Lower regression risks
• Unbeatable time-to-market
12/10/2012
5
THEODO
6. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
6
THEODO
7. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
7
THEODO
8. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
8
THEODO
9. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
9
THEODO
10. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
10
THEODO
11. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
11
THEODO
12. Decoupling
is
a
major
aspect
of
progressive
rewrite
Rewrite
strategy
12/10/2012
12
THEODO
13. The
need
for
progressive
rewrite
The
technical
challenges
faced
Theodo
Evolu=on
12/10/2012
13
THEODO
14. System
comptability
The
challenge
of
progressive
rewrite
• Symfony2
requires:
• PHP
5.3.2
• Sqlite3,
JSON,
ctype
• date.0mezone
set
in
php.ini
• php
app/check.php
• Blueprint:
hJps://github.com/devstructure/blueprint
12/10/2012
14
THEODO
15. Unexpected
regressions
The
challenge
of
progressive
rewrite
• By
defini0on,
spagheD
code
is
deeply
coupled.
Improving
one
part
can
break
another
• Need
for
func0onal
tes0ng
on
the
most
cri0cal
scenarios
• Mink:
hJps://github.com/Behat/Mink
12/10/2012
15
THEODO
16. Proxying
the
rou=ng
The
challenge
of
progressive
rewrite
• The
beauty
of
PHP:
some
apps
have
simply
no
rou0ng!
• Host
the
new
app
next
to
the
old
app,
with
clear
URL
differences,
and
proxy
at
the
server
level
• Subdomain:
v2.myapp.com
• Subfolder:
www.myapp.com/v2/
• If
you
want
to
keep
the
rou0ng:
create
a
catchall
route
with
Symfony2
12/10/2012
16
THEODO
17. Sharing
the
layout
The
challenge
of
progressive
rewrite
• The
rewrite
needs
to
be
transparent
for
the
app
users:
both
old
and
new
apps
must
use
the
same
layout
• Copy-‐pas0ng
the
layout
is
not
a
solu0on:
use
ESIs
with
a
compa0ble
Reverse-‐Proxy
<esi:include
src="{{
path('theodoevolution_layoutrenderer_legacylayout_top')
}
}"
/>
{%
block
body
%}{%
endblock
%}
<esi:include
src="{{
path('theodoevolution_layoutrenderer_legacylayout_bottom'
)
}}"
/>
12/10/2012
17
THEODO
18. Sharing
the
session
The
challenge
of
progressive
rewrite
• You
might
want
to
access
some
common
infos
for
your
user
• Both
apps
must
be
hosted
on
the
same
domain
to
make
it
easier
• With
Symfony2,
add
a
listener
on
the
kernel.request
event
that
triggers
a
transformer:
the
session
is
converted
from
plain
array
to
the
Symfony2
format
12/10/2012
18
THEODO
20. What
you
usually
find
The
challenge
of
progressive
rewrite
12/10/2012
20
THEODO
21. You
need
to
create
the
dream
API
and
slowly
start
using
it
The
challenge
of
progressive
rewrite
A
A P
P I
A
I P
I
A
P
I
A
P
I A
A P
P
I
I
12/10/2012
21
THEODO
22. You
need
to
create
the
dream
API
and
slowly
start
using
it
The
challenge
of
progressive
rewrite
A
A P
P I
A
I P
I
A
P
I
A
P
I A
A P
P
I
I
12/10/2012
22
THEODO
23. You
need
to
create
the
dream
API
and
slowly
start
using
it
The
challenge
of
progressive
rewrite
A
A P
P I
A
I P
I
A
P
I
A
P
I A
A P
P
I
I
12/10/2012
23
THEODO
24. You
need
to
create
the
dream
API
and
slowly
start
using
it
The
challenge
of
progressive
rewrite
A
A P
P I
A
I P
I
A
P
I
A
P
I A
A P
P
I
I
12/10/2012
24
THEODO
25. This
is
called
«
Facade
PaUern
»
The
challenge
of
progressive
rewrite
Wikipedia
A
facade
is
an
object
that
provides
a
simplified
interface
to
a
larger
body
of
code,
such
as
a
class
library.
A
facade
can:
• make
a
so_ware
library
easier
to
use,
understand
and
test,
since
the
facade
has
convenient
methods
for
common
tasks;
• make
the
library
more
readable,
for
the
same
reason;
• reduce
dependencies
of
outside
code
on
the
inner
workings
of
a
library,
since
most
code
uses
the
facade,
thus
allowing
more
flexibility
in
developing
the
system;
• wrap
a
poorly
designed
collec0on
of
APIs
with
a
single
well-‐
designed
API
(as
per
task
needs).
12/10/2012
25
THEODO
26. Symfony2
Service
Container
The
challenge
of
progressive
rewrite
• With
Symfony2,
the
new
API
of
the
Facade
PaJern
is
a
service
• Create
a
service
for
every
module
you
iden0fied…
and
start
using
them!
12/10/2012
26
THEODO
27. Changing
the
model
The
challenge
of
progressive
rewrite
• The
database
is
a
converging
point.
Making
two
models
co-‐exist
is
really
hard
• One
solu0on
is
NoSQL.
The
flexibility
of
a
DB
like
MongoDB
makes
it
easier.
• Use
/**
@MongoDBPreLoad
*/
from
the
Doctrine
ODM
• No
miracle
solu0on…
YET!
J
12/10/2012
27
THEODO
28. Final
step:
cleaning
the
old
code
The
challenge
of
progressive
rewrite
12/10/2012
28
THEODO
29. The
need
for
progressive
rewrite
The
technical
challenges
faced
Theodo
Evolu=on
12/10/2012
29
THEODO
30. Theodo
Evolu=on
Our
strategy
with
progressive
rewrite
• The
Theodo
team
consists
as
of
today
of
18
excellent
web
devs
• Every
technical
solu0on
for
progressive
rewrite
in
Symfony2
is
bundled
in
Theodo
Evolu0on
• Two
R&D
engineers
are
now
working
full-‐0me
on
finding
new
solu0ons
• Goal:
make
Theodo
Evolu0on
an
out-‐of-‐the-‐box
solu0on
12/10/2012
30
THEODO