public function index02Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $autoLoader = new \Zend\Loader\StandardAutoloader(array("autoregister_zf" => true, "namespaces" => array("Database" => LIB_PATH . "/Database", "Art" => LIB_PATH . "/Art"), "prefixes" => array("Mail" => LIB_PATH . "/Mail"))); $autoLoader->register(); $student = new \Database\Student(); $teacher = new \Database\Teacher(); $people = new \Database\basetada\People(); $sontung_m = new \Art\Singer(); $sender = new \Mail_Sender(); $google_sender = new \Mail_google_sender(); return false; }
public function __construct($options = array()) { // require autoloader $loader = new \Zend\Loader\StandardAutoloader(); $loader->register(); // this might look goofy, but this is setting up the // registry for dependency injection into the client $registry = new \Zend\Tool\Framework\Registry\FrameworkRegistry(); $registry->setClient($this); // NOTE: at this moment, $this->_registry should contain the registry object if ($options) { $this->setOptions($options); } }
public function indexAction() { /*$autloader = new \Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));*/ $autloader = new \Zend\Loader\StandardAutoloader(array('autoregister_zf' => true, 'namespaces' => array('Database' => LIBRARY_PATH . '/../../../Database'), 'prefixes' => array('Mail' => LIBRARY_PATH . '/../../../Mail'))); // $autloader->registerNamespace('Database', LIBRARY_PATH.'/../../../Database'); // $autloader->registerPrefix('Mail', LIBRARY_PATH.'/../../../Mail'); $autloader->register(); $student = new \Database\Student(); $teacher = new \Database\Teacher(); $worker = new \Database\Oracle\Worker(); $sender = new \Mail_Sender(); /** zf 1.x*/ $a_mail = new \Mail_Abc_A(); return false; }
public function checkEntities($force = false) { if (!is_dir($this->entityFolder . 'Entity') || $force) { $this->prepareFolder($force); $this->configure(); // custom datatypes (not mapped for reverse engineering) $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $driver = new RestDriver($this->em->getConnection()->getSchemaManager()); $driver->setNamespace($this->namespace); $driver->setBiDirecionalEntities(true); $this->em->getConfiguration()->setMetadataDriverImpl($driver); $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($this->em); $cmf->setEntityManager($this->em); $metadata = $cmf->getAllMetadata(); $this->EntityGenerator($metadata); } $autoLoader = new \Zend\Loader\StandardAutoloader(array('namespaces' => array('Entity' => $this->entityFolder . DIRECTORY_SEPARATOR . $this->namespace), 'fallback_autoloader' => true)); $autoLoader->register(); }
/** * Constructor * * Initialize application. Potentially initializes include_paths, PHP * settings, and bootstrap class. * * @param string $environment * @param string|array|\Zend\Config\Config $options String path to configuration file, or array/\Zend\Config\Config of configuration options * @throws \Zend\Application\Exception When invalid options are provided * @return void */ public function __construct($environment, $options = null) { $this->_environment = (string) $environment; /** * @todo Make this configurable? */ require_once __DIR__ . '/../Loader/StandardAutoloader.php'; $autoloader = new \Zend\Loader\StandardAutoloader(); $autoloader->register(); $this->setAutoloader($autoloader); if (null !== $options) { if (is_string($options)) { $options = $this->_loadConfig($options); } elseif ($options instanceof \Zend\Config\Config) { $options = $options->toArray(); } elseif (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options provided; must be location of config file, a config object, or an array'); } $this->setOptions($options); } }
public static function get_instance() { if (self::$instance == null) { // Инициализируем автолоадер. Он ищет сначала в каталоге приложения, если класса нет и есть такой же с префиксом k_ в ядре, содает класс обертку с запрашиваемым именем и наследует ее от найденного в ядре класса spl_autoload_register(function ($class) { $is_zend = substr($class, 0, 5) == 'Zend\\'; if ($is_zend) { if (application::$zend_icluded) { return; } include_once PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zend/Loader/StandardAutoloader.php'; $loader = new Zend\Loader\StandardAutoloader(); $loader->registerNamespace('Zend', PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zend'); $loader->register(); if ($class !== 'Zend\\Loader\\StandardAutoloader') { $loader->autoload($class); } } else { $is_kernel = substr($class, 0, 2) == 'k_'; $fn = str_replace('_', '/', $is_kernel ? preg_replace('/^k\\_/', '', $class) : $class) . '.php'; if (!$is_kernel && file_exists(PATH_ROOT . '/' . DIR_APPLICATION . '/' . $fn)) { require_once PATH_ROOT . '/' . DIR_APPLICATION . '/' . $fn; } else { if (!$is_kernel && defined('DIR_ZLIBRARY') && file_exists(PATH_ROOT . '/' . DIR_ZLIBRARY . '/' . $fn)) { require_once PATH_ROOT . '/' . DIR_ZLIBRARY . '/' . $fn; } else { if (file_exists(PATH_ROOT . '/' . DIR_LIBRARY . '/' . $fn)) { require_once PATH_ROOT . '/' . DIR_LIBRARY . '/' . $fn; if (!$is_kernel && class_exists('k_' . $class)) { eval('class ' . $class . ' extends k_' . $class . ' {};'); } } else { if (class_exists('common') && method_exists('common', 'autoload')) { common::autoload($class); } } } } } }); // Экземпляр приложения создается не из текущего класса, а из класса, который находится в папке приложения application::$instance = new application(); } return application::$instance; }
<?php ini_set('display_error', 1); date_default_timezone_set('Asia/Shanghai'); define('APPLICATION_PATH', dirname(__FILE__)); chdir(APPLICATION_PATH); define('CONFIG_PATH', APPLICATION_PATH . '/config/'); // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } // Composer autoloading $zf2Path = "/Users/liujin834/work/library/zf2-git/library"; $westdcCorePath = "/Users/liujin834/work/westdc/westdc-core/Westdc"; include $zf2Path . '/Zend/Loader/StandardAutoloader.php'; // Register Auto Loader $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true, 'namespaces' => array('Westdc' => $westdcCorePath), 'fallback_autoloader' => true)); // Register with spl_autoload: $loader->register();
/** * _runTool() - This is where the magic happens, dispatch Zend_Tool * * @return void */ protected function _runTool() { $configOptions = array(); if (isset($this->_configFile) && $this->_configFile) { $configOptions['configOptions']['configFilepath'] = $this->_configFile; } if (isset($this->_storageDirectory) && $this->_storageDirectory) { $configOptions['storageOptions']['directory'] = $this->_storageDirectory; } // ensure that zf.php loads the Zend_Tool_Project features $configOptions['classesToLoad'] = 'Zend\\Tool\\Project\\Provider\\Manifest'; $autoloader = new Zend\Loader\StandardAutoloader(); $autoloader->setFallbackAutoloader(true); $autoloader->register(); $console = new Zend\Tool\Framework\Client\Console\Console($configOptions); $console->dispatch(); return null; }
<?php use Zend\EventManager\EventManager; define('ZF2_PATH', getenv('ZF2_PATH') ? getenv('ZF2_PATH') : realpath(__DIR__ . '/library/Zend')); require_once ZF2_PATH . '/Loader/StandardAutoloader.php'; $autoLoader = new Zend\Loader\StandardAutoloader(); // register our StandardAutoloader with the SPL autoloader $autoLoader->register(); // register the Zend namespace $autoLoader->registerNamespace('Zend', ZF2_PATH); class ValidatePost { public function validate($event) { $data = $event->getParams(); if (!isset($data['title']) or !isset($data['slug'])) { throw new \InvalidArgumentException('Need a title and a slug!'); } return $data; } } class SlugifyPost { public function slugify($event) { $data = $event->getParams(); $event->setParam('slug', strtolower(str_replace(' ', '-', $data['title']))); return $data; } } class Post
<pre> <?php use Br\Gov\Filter\Acentuacao; define('DS', DIRECTORY_SEPARATOR); define('PS', PATH_SEPARATOR); set_include_path(get_include_path() . PS . '/home/brainfork/zend-framework/zf2/library'); require_once 'Zend' . DS . 'Loader' . DS . 'StandardAutoloader.php'; $autoloader = new Zend\Loader\StandardAutoloader(); $autoloader->register(); $autoloader->registerNamespace('Br', __DIR__ . DS . '../library' . DS . 'Br'); $a = new Acentuacao(); $f = $a->filter('Cinqüênta pássaros se vão e caçoam da àguia. Pão-de-ló e café!'); Zend\Debug::dump($f);
protected function _init($env) { $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); $appConfigFileResource = $profile->search('applicationConfigFile'); if ($appConfigFileResource == false) { throw new \Zend\Tool\Project\Exception('A project with an application config file is required to use this provider.'); } $appConfigFilePath = $appConfigFileResource->getPath(); $this->_config = new \Zend\Config\Ini($appConfigFilePath, $env); require_once 'Zend/Loader/StandardAutoloader.php'; $autoloader = new \Zend\Loader\StandardAutoloader(); $autoloader->registerNamespace('Akrabat', realpath(__DIR__ . '/../')); $autoloader->register(); }
* * SOGoAccountsManager is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with SOGoAccountsManager. If not, see <http://www.gnu.org/licenses/>. */ set_include_path(ini_get('include_path') . PATH_SEPARATOR . dirname(dirname(__FILE__)) . '/library' . PATH_SEPARATOR . dirname(dirname(__FILE__)) . '/application'); require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); require 'Zend/Loader/StandardAutoloader.php'; $zendAutoloader = new \Zend\Loader\StandardAutoloader(); $zendAutoloader->setFallbackAutoloader(true); $zendAutoloader->register(); $app = new \Slim\Slim(); $app->config(include 'config.php'); $app->add(new \Slim\Middleware\ContentTypes()); $app->add(new \SOGoAccountsManager\Middleware\SOGoSession()); $app->add(new \SOGoAccountsManager\Middleware\SOGoConfiguration()); $app->add(new \SOGoAccountsManager\Middleware\JsonExceptions()); $app->get('/checkAuth', function () use($app) { $className = '\\SOGoAccountsManager\\Authentication'; $auth = new $className($app); $auth->check(); }); // Accounts routes $app->get('/accounts', function () use($app) { $className = $app->config('informationsStore.namespace') . '\\Accounts'; $accounts = new $className($app);
/** * bootstrap modules */ protected function initModules() { // app $app = $this->app; // di container $container = $app->getContainer(); // navigation $navigation = array(); // view paths $viewModules = array(); // loader $loader = new \Zend\Loader\StandardAutoloader(); // for each module foreach ($this->modules as $module) { require_once $this->modulePath . '/' . $module . "/Module.php"; $m = "\\{$module}\\Module"; $m = new $m(); // autoloader if (method_exists($m, 'getAutoloaderConfig')) { $cfg = $m->getAutoloaderConfig(); // register module namespace foreach ($cfg as $key => $value) { $loader->registerNamespace($key, $value); } // register namespaces $loader->register(); } // routes if (method_exists($m, 'getRouterConfig')) { $cfg = $m->getRouterConfig(); // load routes foreach ($cfg as $value) { foreach (glob($value . "/*.php") as $filename) { require_once $filename; } } } // views if (method_exists($m, 'getViewConfig')) { $cfg = $m->getViewConfig(); // get view paths foreach ($cfg as $key => $value) { // get module view path // store path in app to register it with template engine $viewModules[$key] = $value; } } // navigation if (method_exists($m, 'getNavigationConfig')) { // get navigation config $cfg = $m->getNavigationConfig(); // merge navigation recursiv $navigation = array_merge_recursive($navigation, $cfg); } // middleware if (method_exists($m, 'getMiddlewareConfig')) { $cfg = $m->getMiddlewareConfig(); // load routes foreach ($cfg as $value) { foreach (glob($value . "/*.php") as $filename) { require_once $filename; } } } } // save view modules $container->viewModules = $viewModules; // save navigation $container->navigation = $navigation; }