2017 © Pedro PelĂĄez
 

library my-extensions

Simple Class Libraries

image

falkm/my-extensions

Simple Class Libraries

  • Sunday, September 18, 2016
  • by falkmueller
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

myExtensions

simple PHP Classes

Install over composer

composer.json, (*1)

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/falkmueller/myExtensions.git"
        }
    ],
    "require": {
        "falkm/myExtensions": "dev-develop"
    }
}

mydb

PHP PDO MySql database wrapper

Use

Create Connection, (*2)

    $db = new \myExtensions\mydb("localhost", "test", "root", "");

Insert Statement with Parameter, (*3)

    $statement = $db->createQuery("INSERT INTO testtbl (test) values (:name)", array(":name" => "falk"));
    $statement->execute();

Select Statement with multible parameter, (*4)

    $statement = $db->createQuery("SELECT * FROM testtbl where test in (:name)", array(":name" => array("falk3", "falk2")));
    print_r($statement->fetchAll());

myEntity

first, set global myDb-Instance for Entity-Model, (*5)

\myExtensions\myEntity::$db = $db;

create entitys, (*6)

class user extends \myExtensions\myEntity {


    protected static $_table = "user";

    public static function fields(){
        return array(
            "id" => array('type' => 'integer', 'primary' => true, 'autoincrement' => true),
            "name" => array('type' => 'string', "default" => ""),
            "password" => array('type' => 'string', "default" => ""),
        );
    }
}

work with entity, (*7)

    $user1 = \app\entity\user::selectOne(array("id" => 1));
    $new = new \app\entity\user(array("id" => 1, "name" => "mueller"));
    if($new->exists()){
        echo "exists";
    } else {
        $new->insert();
    }

    $new->name = "falk";
    $new->update();

    echo json_encode($a->toArray());

myHook

    use myExtensions\myHook;

    $hooks = myHook::Instance();

    /* add a filter */
    $hooks->addFilter("testfilter", function($value){ return "filter-".$value;});

    /* call a filter */
    echo $hooks->filter("testfilter", 1);//filter-1
    echo "<br/>";

    /* add middleware (callable, anonymouse function) */
    $hooks->addMiddleware("m", function($res, $next){ 
        $res .= " M1-before "; 
        $res = $next($res);
        $res .= " M1-after ";

        return $res;

    });

    class x {

        static function y ($res, callable $next,$z1, $z2){
            $res .= " M2-bevore ";
            $res = $next($res);   
            $res .= " M2-after ";

            return $res;
        }

        public function call_me($z1, $z2, $res = ''){
            $res .= " core ";
            return $res;
        }

    }

    * add middleware (callable, static function)*/
    $hooks->addMiddleware("m", "x::y");

    * call middleware (callable, object function)*/
    $x = new x();
    $res = $hooks->middleware("m", array($x, "call_me"),"", 1, 2);

    echo $res; //M1-before M2-bevore core M2-after M1-after

mySession

    echo \myExtensions\mySession::Instance()->get("name", "default");
    \myExtensions\mySession::Instance()->put("name", "falk");
    echo \myExtensions\mySession::Instance()->get("name");

myTemplate

    $t = new \myExtensions\myTemplate();
    $t->addFunction("testfunction", function($value){ return "TestFunction: {$value}"; });
    $t->setSetting("dir", __dir__.'/templates/');

    echo $t->render("index.phtml", array("name" => "myExtension"));

templates/index.phtml, (*8)

    extend("layout.phtml");?>

    <?php $this->startBlock("content", "APPEND") ?>
        Dies ist ein Test: <?php echo $this->name ?><br/>
        <?php echo $this->testfunction("value"); ?>
    <?php $this->endBlock("content") ?>

templates/layout.phtml, (*9)

    <html>
        <header>

        </header>
        <body>
            HEADER

            <div>
                <?php $this->startBlock("content") ?>
                Dies ist der Content
                <?php $this->endBlock("content") ?>
            </div>

            <?php $this->insert("footer.phtml"); ?>
        </body>
    </html>

The Versions

18/09 2016

dev-develop

dev-develop http://falk-m.de/

Simple Class Libraries

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

by Falk MĂŒller

hook php session

30/08 2016

1.0.0

1.0.0.0 http://falk-m.de/

Simple Class Libraries

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

by Falk MĂŒller

hook php session