2017 © Pedro Peláez
 

composer-plugin autoload

image

zanphp/autoload

  • Wednesday, July 19, 2017
  • by zanphp
  • Repository
  • 6 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

autoload

composer 插件, 模拟静态初值化

<?php

interface StaticInitializer
{
    public static function __static();
}

!! 注意,静态初值化的须类必须经过composer加载., (*1)

类加载时, public static function __static() 方法会自动执行, 必须无参数, 必须为静态方法, (*2)

自行require、include功能失效;, (*3)

使用

composer.json 引入 zanphp/autoload package, (*4)

{
  "require": {
    "zanphp/autoload": "dev-master"
  }
}

可选接口实现

<?php

namespace  ZanPHP\Autoload\Tests;

class StaticTest
{
    public static function __static()
    {
        echo __CLASS__ . " initialized\n";
    }
}

或者显示实现接口;, (*5)

<?php

namespace  ZanPHP\Autoload\Tests;

use Composer\Autoload\StaticInitializer;

class StaticInterfaceTest implements StaticInitializer
{
    public static function __static()
    {
        echo __CLASS__ . " initialized\n";
    }
}

test

<?php

require __DIR__ . "/vendor/autoload.php";


class_exists(\ZanPHP\Autoload\Tests\StaticTest::class, true);

class_exists(\ZanPHP\Autoload\Tests\StaticInterfaceTest::class, true);

output

ZanPHP\Autoload\Tests\StaticTest initialized
ZanPHP\Autoload\Tests\StaticInterfaceTest initialized

The Versions

19/07 2017

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.6
  • composer-plugin-api 1.1.0