Phalcon Framework 2.0.8

MongoConnectionException: Failed to connect to: localhost:27017: Connection refused

/var/www/html/quebec_cinema/apps/rvcq/Module.php (134)
#0MongoClient->__construct()
/var/www/html/quebec_cinema/apps/rvcq/Module.php (134)
<?php
/**
 * @package Phalcon
 * @copyright Akufen Atelier Creatif
 * @author Nicholas Charbonneau <nicholas@akufen.ca>
 */
 
namespace Akufen\Frontend;
 
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
 
use Akufen\Backend\Helpers\Dispatcher as FrontentDispatcher;
use Akufen\Backend\Helpers\Translations;
/**
 * Module
 *
 * The module class is used to define the module that will
 * be instantiate according to the route matched by the router.
 *
 * @see ModuleDefinitionInterface
 */
class Module implements ModuleDefinitionInterface
{
  /**
   * Register the module's autoloader
   *
   * Used to configure the module's autoloader to register
   * all the namespaces used by the module.
   */
  public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null)
  {
    // Create new auto loader and register namespaces
    $loader = new Loader();
    $loader->registerNamespaces(array(
      'Akufen\Frontend\Controllers' => __DIR__ . '/controllers/',
      'Akufen\Frontend\Models' => __DIR__ . '/models/',
      'Akufen\Frontend\Helpers' => __DIR__ . '/helpers/',
      'Akufen\Frontend\Helpers\Categories' => __DIR__ . '/helpers/categories/',
      'Akufen\Frontend\Helpers\Navigations' => __DIR__ . '/helpers/navigation/',
      'Akufen\ZoneFestival\Models' => __DIR__ . '/models/',
      'Akufen\Backend\Models' => __DIR__ . '/../backend/models/',
      'Akufen\SocialMedias\Models' => __DIR__ . '/../../vendor/akufen/social-medias/src/Models/',
      'Hpatoio\Bitly' => __DIR__ . '/../../vendor/hpatoio/bitly-api/src/',
      'Guzzle' => __DIR__ . '/../../vendor/guzzle/guzzle/src/Guzzle/',
      'Symfony' => __DIR__ . '/../../vendor/symfony/event-dispatcher/Symfony/',
      'Symfony\Component\EventDispatcher' => __DIR__ . '/../../vendor/symfony/event-dispatcher/',
      'Detection' => __DIR__ . '/../../vendor/mobiledetect/mobiledetectlib/namespaced/Detection/',
      'Facebook' => __DIR__.'/../../vendor/facebook/php-sdk-v4/src/Facebook/'
    ));
 
    // Register namespaces
    $loader->register();
  }
 
  /**
   * Register the module's services
   *
   * Used to set the dispatcher & view objects before the execution
   * of the controller action.
   *
   * @param \Phalcon\DI $di The dependency injector.
   */
  public function registerServices(\Phalcon\DiInterface $di)
  {
    // Read configuration
    $config = include __DIR__ . "/config/config.php";
    
    // Registering a dispatcher
    $di->set('dispatcher', function() use ($di) {
      $dispatcher = new Dispatcher();
      $dispatcher->setDefaultNamespace("Akufen\Frontend\Controllers");
 
      $frontendDispatcher = new FrontentDispatcher();
 
      $eventsManager = $di->getShared('eventsManager');
      $eventsManager->attach('dispatch', $frontendDispatcher);
 
      $dispatcher->setEventsManager($eventsManager);
 
      return $dispatcher;
    });
 
    // Setting up the view component
    $di->set('view', function () use ($di) {
      $view = new View();
      $view->setViewsDir(__DIR__ . '/views/');
 
      //Create an events manager
          $eventsManager = $di->getShared('eventsManager'); 
 
         // Instantiate the Translation plugin
         $translations = new Translations();
 
         // Attach a listener for type "afterRenderView"
         $eventsManager->attach("view", $translations);
 
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
 
      return $view;
    });
  
    // Declare the zone festival mongo database
    $di->set('zone_festival', function() use($config) {
      //$zoneFestival = new \MongoClient("mongodb://{$config['database']['username']}:{$config['database']['password']}@{$config['database']['host']}:27017");
      $zoneFestival = new \MongoClient();
      return $zoneFestival->selectDb('zone_festival');
    });
 
    // Declare the zone festival mongo database
    $di->set('quebec_cinema', function() use($config) {
      //$quebecCinema = new \MongoClient("mongodb://{$config['database']['username']}:{$config['database']['password']}@{$config['database']['host']}:27017");
      $quebecCinema = new \MongoClient();
      return $quebecCinema->selectDb('quebec_cinema');
    });
 
    // Declare the medias mongo database
    $di->set('medias', function() use ($config) {
      //$medias = new \MongoClient("mongodb://{$config['database']['username']}:{$config['database']['password']}@{$config['database']['host']}:27017");
      $medias = new \MongoClient();
      return $medias->selectDb('medias');
    });
 
    // Create a connection to the desired database adapter
    switch($config['database']['adapter']) {
      // Configure mongodb
      case 'Mongo':      
        $di->set('mongo', function() use ($config) {
          //$mongo = new \MongoClient("mongodb://{$config['database']['username']}:{$config['database']['password']}@{$config['database']['host']}:27017");
          $mongo = new \MongoClient();
          return $mongo->selectDb((string)$config['database']['dbname']);
        }, true);
        break;
 
      default:
        throw new \Exception("Invalid database adapter");
    }
 
    // Make the collection manager available
    $di->set('collectionManager', function(){
      return new \Phalcon\Mvc\Collection\Manager();
    }, true);
 
    // Attach Config facebook
    $di->set('facebook', $config['facebook']);
 
    // Attach Config mailchim
    $di->set('mailchimp', $config['mailchimp']);
 
    // Attach Config bitly
    $di->set('bitly', $config['bitly']);
 
    //Attach reCaptcha config
    $di->set('recaptcha', $config['recaptcha']);
 
    // Attach environment config
    $di->set('env', function() use ($config) {
      return $config['env'];
    });
  }
}
#1Akufen\Frontend\Module->Akufen\Frontend\{closure}()
#2Phalcon\Di\Service->resolve(null, Object(Phalcon\Di\FactoryDefault))
#3Phalcon\Di->get(mongo, null)
#4Phalcon\Di->getShared(mongo)
#5Phalcon\Mvc\Collection\Manager->getConnection(Object(Akufen\Backend\Models\Mongo\ContentEntities))
#6Phalcon\Mvc\Collection->getConnection()
#7Phalcon\Mvc\Collection::findFirst(Array([0] => Array([nodes.route] => Array([0] => films, [1] => le-commerce-du-sexe))))
/var/www/html/quebec_cinema/apps/backend/helpers/Dispatcher.php (111)
<?php
/**
 * This file is part of the Akufen Backend module (http://akufen.ca)
 */
 
namespace Akufen\Backend\Helpers;
 
use Akufen\Backend\Models\Mongo\Contents;
use Akufen\Backend\Models\Mongo\ContentEntities;
use Akufen\Backend\Models\Mongo\ContentNodes;
use Akufen\Backend\Models\Mongo\CategoryEntities;
use Akufen\Backend\Models\Mongo\CategoryNodes;
 
/**
 * Dispatcher
 *
 * @package Helpers
 * @copyright Akufen Atelier Creatif
 * @author Nicholas Charbonneau <nicholas@akufen.ca>
 */
class Dispatcher 
{
  static $content;
 
  static $contentEntity;
 
  static $contentNode;
 
  static $routeArray;
 
  /**
   * controllersNamespace
   *
   * @var string
   * @access private
   */
  private $controllersNamespace = 'Akufen\\Frontend\\Controllers\\';
 
  /**
   * beforeExecuteRoute
   *
   * @var string
   * @access private
   */
  public function beforeDispatchLoop($event, $dispatcher)
  {
    // Attempt to match content from the route
    list($routeArray, $content, $contentEntity, $contentNode) = $this->matchContent($dispatcher);
 
    // Attempt to match content based method
    if($contentEntity) {
      // Find the name of the class
      $segments = explode('\\', get_class($contentEntity));
      $className = end($segments);
    
      // Find the slug of the group based on the type of content
      if($className == 'ContentEntities') {
        $slug = $contentEntity->getContent()->getSlug();
      } else $slug = $contentEntity->getCategoryGroup()->getSlug();
 
      // Create a frontend controller name string
      $controllerClass = $this->controllersNamespace .
        Strings::capitalizeFirst($slug) .
        'Controller';
 
      // Create a method name string
      $methodName = Strings::toFunctionName(str_replace(
          'phtml', '',
          $contentNode->getTemplate()
      ));
      static::$content = $content;
      static::$contentEntity = $contentEntity;
      static::$contentNode = $contentNode;
      
      // Attempt to match method for this controller
      $dispatcher->setControllerName($content->getSlug());
      $dispatcher->setActionName($methodName);
    }
 
    // Store dispatching information 
    static::$routeArray = $routeArray;
  }
  
  /**
   * matchContent
   *
   * @access public
   * @return void
   */
  public function matchContent($dispatcher)
  {
    // Instantiate content variables
    $content = null;
    $contentEntity = null;
    $contentNode = null;
 
    // Match the route from the router
    $matches = $dispatcher->getDI()->getRouter()->getMatches();
    $matches = ltrim(@$matches[0], '/');
    $matches = rtrim($matches, '/');
    $routeArray = explode('/', $matches);
 
    // Build array for root request
    if(empty($routeArray[0])) {
      $routeArray = array('');
    }
 
    // Attempt to match the route to a content entity
    $contentEntity = ContentEntities::findFirst(array(
      array("nodes.route" => $routeArray)
    ));
 
    // Attempt to match a category if no content exist
    if(!$contentEntity) {
      $contentEntity = CategoryEntities::findFirst(array(
        array('nodes.route' => $routeArray)
      ));
    }
 
    // Retreive the accessed node from the content entity
    if($contentEntity) {
      // Find the name of the class
      $segments = explode('\\', get_class($contentEntity));
            $className = end($segments);
 
            // Find the slug of the group based on the type of content
      if($className == 'ContentEntities') {
        $content = $contentEntity->getContent();
            } else $content = $contentEntity->getCategoryGroup();
 
      // Retreive nodes array
      $nodesArray = $contentEntity->getNodes();
 
      // Filter the content entity nodes to find the current one
      if(!$routeArray) $routeArray = array();
      list($node) = array_filter($nodesArray, function($array) use ($routeArray) {
        if(is_array($array['route'])) {
          $difference = array_diff($array['route'], $routeArray);
          if(empty($difference)) return true;
        } else if($array['route'] == $routeArray) {
          return true;
        }
        return false;
      });
    
      // Create node based on class name
      if($className == 'ContentEntities') {
        $contentNode = new ContentNodes();
      } else $contentNode = new CategoryNodes();
      $contentNode->fromData($node);
    }
 
    // Return matches data
    return array($routeArray, $content, $contentEntity, $contentNode);
  }
}
#8Akufen\Backend\Helpers\Dispatcher->matchContent(Object(Phalcon\Mvc\Dispatcher))
/var/www/html/quebec_cinema/apps/backend/helpers/Dispatcher.php (48)
<?php
/**
 * This file is part of the Akufen Backend module (http://akufen.ca)
 */
 
namespace Akufen\Backend\Helpers;
 
use Akufen\Backend\Models\Mongo\Contents;
use Akufen\Backend\Models\Mongo\ContentEntities;
use Akufen\Backend\Models\Mongo\ContentNodes;
use Akufen\Backend\Models\Mongo\CategoryEntities;
use Akufen\Backend\Models\Mongo\CategoryNodes;
 
/**
 * Dispatcher
 *
 * @package Helpers
 * @copyright Akufen Atelier Creatif
 * @author Nicholas Charbonneau <nicholas@akufen.ca>
 */
class Dispatcher 
{
  static $content;
 
  static $contentEntity;
 
  static $contentNode;
 
  static $routeArray;
 
  /**
   * controllersNamespace
   *
   * @var string
   * @access private
   */
  private $controllersNamespace = 'Akufen\\Frontend\\Controllers\\';
 
  /**
   * beforeExecuteRoute
   *
   * @var string
   * @access private
   */
  public function beforeDispatchLoop($event, $dispatcher)
  {
    // Attempt to match content from the route
    list($routeArray, $content, $contentEntity, $contentNode) = $this->matchContent($dispatcher);
 
    // Attempt to match content based method
    if($contentEntity) {
      // Find the name of the class
      $segments = explode('\\', get_class($contentEntity));
      $className = end($segments);
    
      // Find the slug of the group based on the type of content
      if($className == 'ContentEntities') {
        $slug = $contentEntity->getContent()->getSlug();
      } else $slug = $contentEntity->getCategoryGroup()->getSlug();
 
      // Create a frontend controller name string
      $controllerClass = $this->controllersNamespace .
        Strings::capitalizeFirst($slug) .
        'Controller';
 
      // Create a method name string
      $methodName = Strings::toFunctionName(str_replace(
          'phtml', '',
          $contentNode->getTemplate()
      ));
      static::$content = $content;
      static::$contentEntity = $contentEntity;
      static::$contentNode = $contentNode;
      
      // Attempt to match method for this controller
      $dispatcher->setControllerName($content->getSlug());
      $dispatcher->setActionName($methodName);
    }
 
    // Store dispatching information 
    static::$routeArray = $routeArray;
  }
  
  /**
   * matchContent
   *
   * @access public
   * @return void
   */
  public function matchContent($dispatcher)
  {
    // Instantiate content variables
    $content = null;
    $contentEntity = null;
    $contentNode = null;
 
    // Match the route from the router
    $matches = $dispatcher->getDI()->getRouter()->getMatches();
    $matches = ltrim(@$matches[0], '/');
    $matches = rtrim($matches, '/');
    $routeArray = explode('/', $matches);
 
    // Build array for root request
    if(empty($routeArray[0])) {
      $routeArray = array('');
    }
 
    // Attempt to match the route to a content entity
    $contentEntity = ContentEntities::findFirst(array(
      array("nodes.route" => $routeArray)
    ));
 
    // Attempt to match a category if no content exist
    if(!$contentEntity) {
      $contentEntity = CategoryEntities::findFirst(array(
        array('nodes.route' => $routeArray)
      ));
    }
 
    // Retreive the accessed node from the content entity
    if($contentEntity) {
      // Find the name of the class
      $segments = explode('\\', get_class($contentEntity));
            $className = end($segments);
 
            // Find the slug of the group based on the type of content
      if($className == 'ContentEntities') {
        $content = $contentEntity->getContent();
            } else $content = $contentEntity->getCategoryGroup();
 
      // Retreive nodes array
      $nodesArray = $contentEntity->getNodes();
 
      // Filter the content entity nodes to find the current one
      if(!$routeArray) $routeArray = array();
      list($node) = array_filter($nodesArray, function($array) use ($routeArray) {
        if(is_array($array['route'])) {
          $difference = array_diff($array['route'], $routeArray);
          if(empty($difference)) return true;
        } else if($array['route'] == $routeArray) {
          return true;
        }
        return false;
      });
    
      // Create node based on class name
      if($className == 'ContentEntities') {
        $contentNode = new ContentNodes();
      } else $contentNode = new CategoryNodes();
      $contentNode->fromData($node);
    }
 
    // Return matches data
    return array($routeArray, $content, $contentEntity, $contentNode);
  }
}
#9Akufen\Backend\Helpers\Dispatcher->beforeDispatchLoop(Object(Phalcon\Events\Event), Object(Phalcon\Mvc\Dispatcher), null)
#10Phalcon\Events\Manager->fireQueue(Array([0] => Object(Akufen\Backend\Helpers\Dispatcher)), Object(Phalcon\Events\Event))
#11Phalcon\Events\Manager->fire(dispatch:beforeDispatchLoop, Object(Phalcon\Mvc\Dispatcher))
#12Phalcon\Dispatcher->dispatch()
#13Phalcon\Mvc\Application->handle()
/var/www/html/quebec_cinema/public/index.php (149)
<?php
 
//ini_set('memory_limit', '-1');
 
use Phalcon\Loader;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Session\Adapter\Files as SessionAdapter;
 
switch($_SERVER['HTTP_HOST']) {
  case 'rvcq.com':
  case 'www.rvcq.com':
    header("Location: http://rvcq.quebeccinema.ca");
    break;
}
 
// Report all error
error_reporting(E_ALL);
 
// Set the Locale
setlocale(LC_ALL, 'en_CA.UTF8');
 
// Create a new debug listener
$debug = new Phalcon\Debug();
$debug->listen();
 
try {
  // Create a factory default dependency injector
  $di = new FactoryDefault();
 
  // Gather all the configuration files
  $di->set('config', function() {
    $files = glob('../config/*.php');
      $config = array();
    $files = is_array($files) ? $files : array();
    foreach($files as $file){
      $currentConfig = include $file;
      $currentConfig = is_array($currentConfig) ? $currentConfig : (array)$currentConfig;
      $config = array_merge_recursive($config, $currentConfig);
    }
    return $config;
  });
 
  // Retrieve configuration
  $config = $di->getConfig();
 
  // Create router
  $router = new Router();
  $router->setDefaultModule("frontend");
 
  // Create default frontend route
  $router->add("/:params", array(
    'module' => 'frontend',
    'controller' => 'index',
    'action' => 'index',
    'params' => 1
  ));
 
  // Create javascript language entry point
  $router->add("/js/translations.js", array(
    'module' => 'backend',
    'controller' => 'translationgroups',
    'action' => 'parseJavascript'
  ));
 
  // Load modules
  $modules = array();
  foreach($config['modules'] as $plugin) {
    $pluginName = explode('/', $plugin);
    $pluginName = end($pluginName);
  
    if($pluginName != "backend" && $pluginName != "social-medias") {
      $pluginName = "frontend";
    }
 
    $pluginPath = '..';
    if(substr($plugin,0,1) == '/') {
      $pluginPath .= $plugin;
    } else {
      $pluginPath = '../vendor/' . $plugin;
    }
 
    $routesFile = $pluginPath . '/config/routes.php';
    
    $routes = array();
 
    if(file_exists($routesFile)){
      $routes = (array) include $routesFile;
 
      foreach($routes as $permalink => $options) {
        $router->add((string) $permalink, (array) $options);
      }
    } 
 
    $namespace = ($pluginName == "social-medias")? 'SocialMedias' : ucfirst($pluginName);
    $pluginPath .= ($pluginName == "social-medias")? '/src' : '';
 
    $modules[$pluginName] = array(
      'className' => 'Akufen\\'. $namespace .'\\Module',
      'path' => $pluginPath.'/Module.php',
      'routes' => $routes
    );
  }
  // Configure the url resolver
  $di->set('url', function() {
       $url = new UrlResolver();
      $url->setBaseUri('/');
      return $url;
  });
 
  // Configure the session
  $di->set('session', function() {
    $session = new SessionAdapter();
    $session->start();
    return $session;
  });
 
  // Configure router
  $di->set('router', $router);
 
  $di->set('modules', function() use($modules){
    return $modules;
  });
 
    // Create a new application instance
    $application = new Application();
 
  // Assign the dependency injector
  $application->setDI($di);
 
  // Register the application's modules
  $application->registerModules($di->getModules());
 
  // Create new auto loader and register backend namespaces
  $loader = new Loader();
  $loader->registerNamespaces(array(
    'Akufen\Backend\Controllers' => __DIR__ . '/../apps/backend/controllers/',
    'Akufen\Backend\Models' => __DIR__ . '/../apps/backend/models/',
    'Akufen\Backend\Plugins' => __DIR__ . '/../apps/backend/plugins/',
    'Akufen\Backend\Helpers' => __DIR__ . '/../apps/backend/helpers/'
  ));
 
  // Register the loader
  $loader->register();
 
  // Handle the request
  echo $application->handle()->getContent();
 
} catch (Phalcon\Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
    echo $e->getMessage();
}
KeyValue
_url/films/le-commerce-du-sexe
KeyValue
REDIRECT_REDIRECT_UNIQUE_IDV3TxrCjQzKmSBSZLdGP6ZgAAAAA
REDIRECT_REDIRECT_STATUS200
REDIRECT_UNIQUE_IDV3TxrCjQzKmSBSZLdGP6ZgAAAAA
REDIRECT_STATUS200
UNIQUE_IDV3TxrCjQzKmSBSZLdGP6ZgAAAAA
HTTP_HOSTrvcq.quebeccinema.ca
HTTP_ACCEPT_ENCODINGx-gzip, gzip, deflate
HTTP_USER_AGENTCCBot/2.0 (http://commoncrawl.org/faq/)
HTTP_ACCEPT_LANGUAGEen-us,en-gb,en;q=0.7,*;q=0.3
HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
SERVER_SIGNATURE
SERVER_SOFTWAREApache/2.4.6 (CentOS) PHP/5.4.16
SERVER_NAMErvcq.quebeccinema.ca
SERVER_ADDR45.56.106.107
SERVER_PORT80
REMOTE_ADDR54.161.65.141
DOCUMENT_ROOT/var/www/html/quebec_cinema
REQUEST_SCHEMEhttp
CONTEXT_PREFIX
CONTEXT_DOCUMENT_ROOT/var/www/html/quebec_cinema
SERVER_ADMINnicholas@akufen.ca
SCRIPT_FILENAME/var/www/html/quebec_cinema/public/index.php
REMOTE_PORT37325
REDIRECT_QUERY_STRING_url=/films/le-commerce-du-sexe
REDIRECT_URL/public/films/le-commerce-du-sexe
GATEWAY_INTERFACECGI/1.1
SERVER_PROTOCOLHTTP/1.0
REQUEST_METHODGET
QUERY_STRING_url=/films/le-commerce-du-sexe
REQUEST_URI/films/le-commerce-du-sexe
SCRIPT_NAME/public/index.php
PHP_SELF/public/index.php
REQUEST_TIME_FLOAT1467281836.599
REQUEST_TIME1467281836
#Path
0/var/www/html/quebec_cinema/public/index.php
1/var/www/html/quebec_cinema/config/modules.php
2/var/www/html/quebec_cinema/apps/backend/config/routes.php
3/var/www/html/quebec_cinema/apps/rvcq/config/routes.php
4/var/www/html/quebec_cinema/apps/rvcq/Module.php
5/var/www/html/quebec_cinema/apps/rvcq/config/config.php
6/var/www/html/quebec_cinema/apps/backend/helpers/Translations.php
7/var/www/html/quebec_cinema/apps/backend/helpers/Dispatcher.php
8/var/www/html/quebec_cinema/apps/backend/models/Mongo/ContentEntities.php
9/var/www/html/quebec_cinema/apps/backend/models/Mongo/ModelBase.php
Memory
Usage786432