Skip to content

Instantly share code, notes, and snippets.

@brzuchal
Last active January 15, 2017 12:48
Show Gist options
  • Select an option

  • Save brzuchal/f3f406187c9027badf55002d1d32b54f to your computer and use it in GitHub Desktop.

Select an option

Save brzuchal/f3f406187c9027badf55002d1d32b54f to your computer and use it in GitHub Desktop.
PHP Module
<?php
require 'module.php';
require 'doctrine-module.php';
$myClass = MyVendor\MyModulePackageBundle\Domain\MyClass();
echo $myClass::module; // MyVendor\MyModulePackageBundle
var_dump(file_exists('vendor+package:resources/config.yml')); // true
$driver = new Doctrine\DBAL\Driver\Mysql();
echo $driver::module; // Doctrine\DBAL
<?php
module MyVendor\MyModulePackageBundle // module declaration
{
const module = 'MyVendor\\MyModulePackageBundle'; // magic constant used like "::class"
const protocol = 'vendor+package'; // used for module stream wrapper for eg. "vendor+package:resources/config.yml"
requires Dcctrine\DBAL; // points required module to use
exports Domain\MyClass; // points exposed public api classes
public function __autoload(string $className) : void //
{
$fname = str_replace('\\', DIRECTORY_SEPARATOR, str_replace(self::module, '', $className)); // MyClass.php
$fpath = self::protocol . ':src' . DIRECTORY_SEPARATOR . $fname . '.php'; // vendor+package:src/Domain/MyClass.php
if (file_exists($fpath)) { // uses package stream wrapper so there is no need to know full real file path
require $fpath;
}
}
}
<?php
module MyVendor\MyModulePackageBundle;
namespace Domain; // at parse time this evolves into namespace MyVendor\MyModulePackageBundle\Domain\MyClass; namespace name
class MyClass { // this class is linked to module so there is possible to recognize it's access public or protected
}
services:
doctrine:
driver: Mysql...
<?php
module Doctrine\DBAL { // module declaration
const module = 'Doctrine\\DBAL'; // magic constant used like "::class"
const protocol = 'doctrine+dbal'; // used for module stream wrapper for eg. "doctrine+dbal:src/Driver/Mysql.php"
exports Connections;
exports Driver;
exports Driver\{
DrizzlePDOMySql, IBMDB2, Mysqli, OCI8, PDOIbm, PDOMySql, PDOOracle, PDOPgSql, PDOSqlite, PDOSqlsrv, SQLAnywhere, SQLSrv
}; // similar to group use statements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment