STOP
Have you work before with Object Oriented Programming ?
Have you used O.O. modeling techniques ?
Are you using namespaces or functions prefixes ("("mylib.php", "function mylib_dosomething() { ... }")") for your PHP files ?
Don't jump to U.M.L., so fast. U.M.L. is to make a documentation,
of whats in your head.
You have to think first, what are you going to do with website,
and later, document and model how your new website is going to work.
U.M.L. is a wonderful tool, but, if the design in your mind is a mess,
then, you'll have a mess in your documentation.
You have a working website, and want to replace it.
There are two main methods.
(1) Start from Scratch:
If you have experience with O.O., and you can forget about your old site, leave it working,
and start a new web site from "scratch" using O.O., or some of the existing frameworks for this.
(2) Refactor
Or, you want to maintain your current website, and migrate to O.O.,
step by step. ? Its also know as "Refactoring".
You may start by thinking that your main program or main php file is a big object (program) file, and each library file are also objects.
Example:
Lets suppouse you have several php files. Some files are the main files for a page. Some files are included and even repeated in page files. Others, are "library" files with only functions.
<?php
// "indexfuncs1.php"
// this is an auxiliary file for "index.php",
// and has some free procedural code.
echo "indexfuncs1.php: dosomething()";
?>
<?php
// "funcslib.php"
// this is an library file,
// and has only functions and constants,
define ("ANYCONST", "Hello World");
function HelloWorld()
{
echo ANYCONST;
}
?>
<?php
// "index.php"
// only declarations, doesn't do anything, by itself
//include("funcslib.php");
//require("funcslib.php");
//require_once("funcslib.php");
include_once("funcslib.php");
// this code is in other file, and its executed
include("indexfuncs1.php");
echo "index.php: Hello World";
HelloWorld();
// this code is in other file, and its executed
include("indexfuncs1.php");
?>
And start to turn them into this:
<?php
// "indexfuncs1.php"
// this is an auxiliary file for "index.php",
// and has some free procedural code.
function indexfuncs1_dosomething()
{
echo "indexfuncs1.php: dosomething()";
}
?>
<?php
// "funcslib.php"
// this is an library file,
// and has only functions and constants,
define ("funcslib_ANYCONST", "Hello World");
function funcslib_HelloWorld()
{
echo funcslib_ANYCONST;
}
?>
<?php
// "index.php"
// only declarations, doesn't do anything, by itself
//include("funcslib.php");
//require("funcslib.php");
//require_once("funcslib.php");
include_once("funcslib.php");
function index_main()
{
// this code is in other file, and its executed
indexfuncs1_dosomething();
echo "index.php: Hello World";
funcslib_HelloWorld();
// this code is in other file, and its executed
indexfuncs1_dosomething();
}
?>
And there is no O.O., yet. Because, its an intermediate step.
Lets start by transform each web page into a single class, without inheritance, without parent classes.
<?php
// "indexfuncs1.php"
// this is an auxiliary file for "index.php",
// and the free procedural code have become a class.
class indexfuncs1 {
function dosomething()
{
echo "indexfuncs1.php: dosomething()";
} // function dosomething()
} // class IndexPage
?>
<?php
// "index.php"
// only declarations, doesn't do anything, by itself
//include("funcslib.php");
//require("funcslib.php");
//require_once("funcslib.php");
include_once("funcslib.php");
class IndexPage {
function main()
{
$myAux = new indexfuncs1();
// this code is in other file, and its executed
$myAux->dosomething();
echo "index.php: Hello World";
funcslib_HelloWorld();
// this code is in other file, and its executed
$myAux->dosomething();
} // function main()
} // class IndexPage
function index_main()
{
$myPage = new IndexPage();
$myPage->main();
} // function index_main(...)
// --> the only allowed global procedural code:
index_main();
?>
(More to come).