<?php namespace com\github\gooh\InterfaceDistiller; include __DIR__ . '/../src/autoload.php'; $reflector = new \ReflectionClass('ConcreteFoo'); $methodIterator = new Filters\RegexMethodIterator(new Filters\NoImplementedMethodsIterator(new Filters\NoInheritedMethodsIterator(new Filters\NoOldStyleConstructorIterator(new Filters\NoMagicMethodsIterator(new \ArrayIterator($reflector->getMethods()))), $reflector)), '(^get)'); $distillate = new Distillate(); $distillate->setInterfaceName('MyInterface'); $distillate->setExtendingInterfaces('Iterator, SeekableIterator'); foreach ($methodIterator as $method) { $distillate->addMethod($method); } $file = new \SplTempFileObject(-1); $writer = new Distillate\Writer($file); $writer->writeToFile($distillate); $file->rewind(); $file->fpassthru();
* Скрипт формирует файлы из существующих интерфейсов Phalcon * * * php scripts/gen-interfaces.php */ namespace com\github\gooh\InterfaceDistiller; include __DIR__ . '/InterfaceDistiller/autoload.php'; $version = \Phalcon\Version::get(); $versionPieces = explode(' ', $version); $phalconVersion = $versionPieces[0]; define('EXAMPLES_DIR', sprintf("%s/%s/%s", dirname(__DIR__), 'interfaces', $phalconVersion)); $phalconClasses = new \RegexIterator(new \ArrayIterator(get_declared_interfaces()), '/^Phalcon/'); foreach ($phalconClasses as $phalconClass) { $reflector = new \ReflectionClass($phalconClass); $distillate = new Distillate(); $distillate->setInterfaceName($phalconClass); $distillate->setExtendingInterfaces(implode(',\\', $reflector->getInterfaceNames())); $parentClass = $reflector->getParentClass(); if ($parentClass) { $distillate->addParentClass($reflector->getParentClass()->getName()); } $methodIterator = new \ArrayIterator($reflector->getMethods()); foreach ($methodIterator as $method) { $distillate->addMethod($method); } $consts = $reflector->getConstants(); $distillate->addConsts($consts); $fileName = sprintf('%s/%s.php', EXAMPLES_DIR, str_replace('\\', '/', $phalconClass)); $fileName = str_replace('/Phalcon/', '/', $fileName); $dirName = dirname($fileName);