2017 © Pedro Peláez
 

library legacy-adapter

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

image

jced-artem/legacy-adapter

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

  • Thursday, December 1, 2016
  • by jced_artem
  • Repository
  • 3 Watchers
  • 8 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

legacy-adapter

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor., (*1)

Install

composer require jced-artem/legacy-adapter

Example

<?php
// legacy_lib.php

include("settings.inc.php");
require("functions.php");
require_once("database.connection.php");

define('SOME_CONST', 'value');

$var1 = funcName(CONST_2);

function get_Var2A($param1, $param2) {
    return functionFromAnotherInclude($param2, $param1);
}

class myClass
{
    var $data = '';
    function getData() {
        global $var1;
        // do somethig
        return get_Var2A($var1, SOME_CONST);
    }
}

include_once("specialCode.php");

function needThis() {
    $obj = new myClass();
    return unknownFunctionFromInclude() + $obj->getData();
}
$var2 = needThis();
printr('{"param":' . $var2 . '; "var": ' . $var1 . '}');

You can use this legacy file anywhere simply:, (*2)

class MyLib extends LegacyAbstractAdapter
{
    /**
     * Configure flyweight
     */
    protected function configure()
    {
        $this
            ->setLegacyFile('legacy_lib.php')
            ->setLegacyPath('/path/to/includes')
        ;
    }
}

$myLib = new MyLib();

// global vars
$var1 = $myLib->var1;
$var2 = $myLib->var2;

// set value
$myLib->var1 = 'some new value';

// get global functions
$res1 = $myLib->get_Var2A($param1, $param2);
$res2 = $myLib->needThis();

// get printr result
$content = $myLib->getFlyweight()->getContent();

or, (*3)

class MyLib extends LegacyAbstractAdapter
{
    /**
     * Configure flyweight
     */
    protected function configure()
    {
        $this
            ->setLegacyFile('legacy_lib.php')
            ->setLegacyPath('/path/to/includes')
        ;
    }

    // override
    public function needThis()
    {
        return 'dummy value';
    }

    // decorate
    public function get_Var2A($param1, $param2)
    {
        return '<font>' . $this->getFlyweight()->call('get_Var2A', [$param1, $param2]); . '</font>';
    }

    // and more
}

Methods available in flyweight

getContent() - get echo/print/etc after include file, (*4)

get($name) - get variable from file, (*5)

hasVariable($name) - check if variable exists, (*6)

set($name, $value) - set variable value, (*7)

hasFunction($name) - check if function exists, (*8)

call($name, array $parameters = []) - call function, (*9)

hasClassDeclared($className) - check if class exists, (*10)

innerClassGetConstant($className, $constantName) - get constsnt from class, (*11)

innerClassGetInstance($className) - get instance of class which was declared in file, (*12)

innerClassCallStatic($className, $methodName, array $parameters = []) - call static function of class declared in file, (*13)

getFunctionNamesList() - list of all function, (*14)

getVariableNamesList() - list of all variables, (*15)

getClassNamesList() - list of all classes, (*16)

Weakness

  1. Singleton-like. You can't create 2 objects because you can't include file 2 times;
  2. Global functions and classes are still global;
  3. Performance can be 2 times lower then native usage include();

The Versions

01/12 2016

dev-master

9999999-dev https://github.com/jced-artem

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight

01/12 2016

1.0.4

1.0.4.0 https://github.com/jced-artem

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight

01/12 2016

1.0.3

1.0.3.0 https://github.com/jced-artem

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight

01/12 2016

1.0.2

1.0.2.0 https://github.com/jced-artem

Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight

01/12 2016

1.0.1

1.0.1.0 https://github.com/jced-artem

Flyweight-adapter to use legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight

01/12 2016

1.0.0

1.0.0.0 https://github.com/jced-artem

Flyweight-adapter to use legacy code in modern frameworks with lazy refactor.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

  • php >=5.6.0

by Artem Jced

wrapper adapter legacy include require refactoring garbage flyweight