#!/usr/bin/php registerDirs([ ROOT_PATH.config::get( 'dirs/controllersDir' ), ROOT_PATH.config::get( 'dirs/librariesDir' ), ROOT_PATH.config::get( 'dirs/modelsDir' ), ])->register(); $loader->registerNamespaces([ 'lib' => ROOT_PATH.config::get( 'dirs/librariesDir' ), 'models' => ROOT_PATH.config::get( 'dirs/modelsDir' ), ])->register(); /////////////////////////////////////////////////////////////////////////// // Using the CLI factory default services container $di = new \Phalcon\DI\FactoryDefault\CLI(); /////////////////////////////////////////////////////////////////////////// // cache $di->set( 'cache', function() { $cache = new \Phalcon\Cache\Frontend\Data([ 'lifetime' => 60, ]); return new \Phalcon\Cache\Backend\Memcache( $cache, [ 'host' => '127.0.0.1', 'port' => 11211, ] ); }, true ); /////////////////////////////////////////////////////////////////////////// // i18n $di->set( 'i18n', function() { return new \Phalcon\Translate\Adapter\NativeArray([ 'content' => require( ROOT_PATH.config::get( 'dirs/messagesDir' ).'ru.php' ) ]); }, true ); /////////////////////////////////////////////////////////////////////////// // database $di->set( 'db', function() { $config = [ 'host' => config::get('global#database/server'), 'username' => config::get('global#database/user'), 'password' => config::get('global#database/passwd'), 'dbname' => config::get('global#database/db'), 'schema' => 'public', ]; $database = new \Phalcon\Db\Adapter\Pdo\Postgresql( $config ); return $database; }, true ); /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //Set a models manager $di->set('modelsManager', function() { return new \Phalcon\Mvc\Model\Manager(); }); //ServiceExcel $di->set( 'ServiceExcel', function() { return new \ServiceExcel(); }, true ); // MyMailer $di->set( 'MyMailer', function() { return new \myMailer(); }, true ); //UTMParser $di->set( 'UTMParser', function() { return new \UTMParser(); }, true ); //a_parser $di->set( 'a_parser', function() { return new \AparserService(); }, true ); //Use the memory meta-data adapter or other $di->set('modelsMetadata', new \Phalcon\Mvc\Model\MetaData\Memory()); /////////////////////////////////////////////////////////////////////////// // common $di->set( 'common', function() { return new \common(); }, true ); //rds $di->set( 'rds', function() { return new \rds(); }, true ); // session $di->set('session', function() { $session = new Phalcon\Session\Adapter\Files(); $session->start(); return $session; }, true ); //exelphp $di->set( 'exelphp', function() { return new \exelphp(); }, true ); /////////////////////////////////////////////////////////////////////////// // flash $di->set( 'flash', function() { return new \Phalcon\Flash\Session(); }, true ); ///////////////////////////////////////////////////////ф-з//////////////////// // cookies $di->set( 'cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); //Set a models manager $di->set('modelsManager', function() { return new \Phalcon\Mvc\Model\Manager(); }); // Create a console application $console = new \Phalcon\CLI\Console(); $console->setDI($di); /////////////////////////////////////////////////////////////////////////// // Process the console arguments $arguments = [ 'task' => null, 'action' => null, 'params' => null, ]; if( count($argv)>1 ) { foreach( $argv as $k => $arg ) { if( strlen($arg)>0 ) { if( $k == 1 ) { $current_task = null; $current_action = null; @list( $current_task, $current_action, ) = explode( ':', $arg ); $arguments['task'] = trim( $current_task ); $arguments['action'] = trim( $current_action ); } elseif( $k >= 2 && substr($arg, 0, 2)=='--' ) { $temp_arg = ltrim( trim( $arg ), '-' ); list( $temp_arg_key, $temp_arg_value ) = explode( '=', $temp_arg ); $arguments['params'][ trim($temp_arg_key) ] = trim( $temp_arg_value ); } } } define( 'CURRENT_TASK', $arguments['task'] ); define( 'CURRENT_ACTION', $arguments['action'] ); } else { throw new \Phalcon\Exception( 'Use "php ./www-tasks/index.php :"' ); } /////////////////////////////////////////////////////////////////////////// // handle incoming arguments $console->handle( $arguments ); /////////////////////////////////////////////////////////////////////////// } catch (\Phalcon\Exception $e) { echo( '[ERROR] '.$e->getMessage(). "\n\n" ); exit( 255 ); } catch (\PDOException $e) { echo( '[ERROR] '.$e->getMessage(). "\n\n" ); exit( 255 ); } catch (\Exception $e) { echo( '[ERROR] '.$e->getMessage(). "\n\n" ); exit( 255 ); }