コード例 #1
0
 public static function init()
 {
     if (self::$_started) {
         return;
     }
     $redirection_conf = sfConfig::get('app_redirection_databases', null);
     if ($redirection_conf === null) {
         return;
     }
     //Iterate over the databases configurations.
     foreach ($redirection_conf as $dbName => $dbOptions) {
         //Check if there are any slaves servers configured.
         if ($dbOptions['slaves'] === null) {
             continue;
         }
         foreach ($dbOptions['slaves'] as &$slave) {
             foreach ($slave as &$param) {
                 $param = sfConfigHandler::replaceConstants($param);
             }
             #Symfony uses 'username' but Propel expects 'user'.
             $slave['user'] = $slave['username'];
             unset($slave['username']);
         }
         self::$_slaveConfig[$dbName] = $dbOptions['slaves'];
         //Check if there is any entity that maybe be redirected to the slave.
         if ($dbOptions['entities'] === null) {
             continue;
         }
         //Iterate over the entities.
         foreach ($dbOptions['entities'] as $model => $options) {
             $peerClass = "{$model}Peer";
             //Check if the peer exits.
             if (!class_exists($peerClass)) {
                 continue;
             }
             $doSelectStmtHook = "{$peerClass}:doSelectStmt:doSelectStmt";
             $doCountHook = "{$peerClass}:doCount:doCount";
             //Register the interceptor function on the peer hooks.
             $interceptor = array('sfPropelRedirection', 'slaveConnection');
             sfMixer::register($doSelectStmtHook, $interceptor);
             sfMixer::register($doCountHook, $interceptor);
             //Check if the peer has conditions in order to be redirected to the slave.
             if (!isset($options['conditions'])) {
                 continue;
             }
             self::$_peerOptions[$peerClass]['conditions'] = $options['conditions'];
             //If there are zero conditions then we don't need to check a gen_column.
             if (!isset($options['gen_column'])) {
                 continue;
             }
             $columnName = strtolower($model) . '.' . strtoupper($options['gen_column']);
             //Check if the gen column really exists in the model
             if (!in_array($columnName, $peerClass::getFieldNames(BasePeer::TYPE_COLNAME))) {
                 continue;
             }
             self::$_peerOptions[$peerClass]['gen_column'] = $columnName;
         }
     }
     self::$_started = true;
 }
コード例 #2
0
 public static function add($class, $behaviors)
 {
     foreach ($behaviors as $name => $parameters) {
         if (is_int($name)) {
             // no parameters
             $name = $parameters;
         } else {
             // register parameters
             foreach ($parameters as $key => $value) {
                 sfConfig::set('propel_behavior_' . $name . '_' . $class . '_' . $key, $value);
             }
         }
         if (!isset(self::$behaviors[$name])) {
             throw new sfConfigurationException(sprintf('Propel behavior "%s" is not registered', $name));
         }
         // register hooks
         foreach (self::$behaviors[$name]['hooks'] as $hook => $callables) {
             foreach ($callables as $callable) {
                 sfMixer::register('Base' . $class . $hook, $callable);
             }
         }
         // register new methods
         foreach (self::$behaviors[$name]['methods'] as $callable) {
             sfMixer::register('Base' . $class, $callable);
         }
     }
 }
コード例 #3
0
 public function launchTests($object, $class)
 {
     $this->t->diag('Mixins via sfMixer');
     sfMixer::register($class, array('myMixinTest', 'newMethod'));
     $this->t->is($object->newMethod(), 'ok', '__call() accepts mixins via sfMixer');
     try {
         $object->nonexistantmethodname();
         $this->t->fail('__call() throws an exception if the method does not exist as a mixin');
     } catch (sfException $e) {
         $this->t->pass('__call() throws an exception if the method does not exist as a mixin');
     }
 }
コード例 #4
0
 protected function enableCustomColumnGetter()
 {
     // activate custom column getter if asColumns were added
     if ($this->getWithColumns() && !sfMixer::getCallable('Base' . $this->class . ':getColumn')) {
         sfMixer::register('Base' . $this->class, array($this, 'getColumn'));
     }
 }
コード例 #5
0
 /**
  * Finalizes the query, executes it and hydrates results
  * 
  * @return array List of Propel objects
  */
 public function doFind()
 {
     if ($cache = $this->cache) {
         $key = $this->getUniqueIdentifier();
         $ret = $cache->getIfSet($key);
         if ($ret !== false) {
             return $ret;
         }
     }
     if ($this->getWithClasses() || $this->getWithColumns()) {
         $c = $this->prepareCompositeCriteria();
         if (method_exists($this->peerClass, 'doSelectRS')) {
             $resultSet = call_user_func(array($this->peerClass, 'doSelectRS'), $c, $this->getConnection());
             $propelVersion = '1.2';
             $nextFunction = 'next';
             $nextParam = null;
         } else {
             $resultSet = call_user_func(array($this->peerClass, 'doSelectStmt'), $c, $this->getConnection());
             $propelVersion = '1.3';
             $nextFunction = 'fetch';
             $nextParam = PDO::FETCH_NUM;
         }
         // Hydrate the objects based on the resultset
         $omClass = call_user_func(array($this->peerClass, 'getOMClass'));
         $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
         $objects = array();
         $withObjs = array();
         while ($row = $resultSet->{$nextFunction}($nextParam)) {
             // First come the columns of the main class
             $obj = new $cls();
             if ($propelVersion == '1.2') {
                 $startCol = $obj->hydrate($resultSet, 1);
             } else {
                 $startCol = $obj->hydrate($row, 0);
             }
             if ($this->culture) {
                 $obj->setCulture($this->culture);
             }
             // Then the related classes added by way of 'with'
             $objectsInJoin = array($obj);
             foreach ($this->getWithClasses() as $className) {
                 $withObj = new $className();
                 if ($propelVersion == '1.2') {
                     $startCol = $withObj->hydrate($resultSet, $startCol);
                 } else {
                     $startCol = $withObj->hydrate($row, $startCol);
                 }
                 // As we can be in a left join, there is a possibility that the hydrated related object is null
                 // In this case, we must not relate it to the main object
                 $isEmpty = true;
                 foreach ($withObj->toArray() as $value) {
                     if ($value !== null) {
                         $isEmpty = false;
                     }
                 }
                 if ($isEmpty) {
                     continue;
                 }
                 // initialize our object directory
                 if (!isset($withObjs[$className])) {
                     $withObjs[$className] = array();
                 }
                 // check if object is not already referenced in allObjects directory
                 $isNewObject = true;
                 foreach ($withObjs[$className] as $otherObject) {
                     if ($otherObject->getPrimaryKey() === $withObj->getPrimaryKey()) {
                         $isNewObject = false;
                         $withObj = $otherObject;
                         break;
                     }
                 }
                 if (strpos(get_class($withObj), 'I18n') !== false) {
                     sfPropelFinderUtils::relateI18nObjects($withObj, $objectsInJoin, $this->culture);
                 } else {
                     sfPropelFinderUtils::relateObjects($withObj, $objectsInJoin, $isNewObject);
                 }
                 $objectsInJoin[] = $withObj;
                 if ($isNewObject) {
                     $withObjs[$className][] = $withObj;
                 }
             }
             // Then the columns added one by one by way of 'withColumn'
             foreach ($this->getWithColumns() as $alias => $column) {
                 // Additional columns are stored in the object, in a special 'namespace'
                 // see getColumn() for how to retrieve the value afterwards
                 // Using the third parameter of withColumn() as a type. defaults to $rs->get() (= $rs->getString())
                 $typedGetter = 'get' . ucfirst($column['type']);
                 if ($propelVersion == '1.2') {
                     $this->setColumn($obj, $alias, $resultSet->{$typedGetter}($startCol));
                 } else {
                     $this->setColumn($obj, $alias, $row[$startCol]);
                 }
                 $startCol++;
             }
             $objects[] = $obj;
         }
         // activate custom column getter if asColumns were added
         if ($this->getWithColumns() && !sfMixer::getCallable('Base' . $cls . ':getColumn')) {
             sfMixer::register('Base' . $cls, array($this, 'getColumn'));
         }
     } else {
         // No 'with', so we use the native Propel doSelect()
         $objects = call_user_func(array($this->peerClass, 'doSelect'), $this->buildCriteria(), $this->getConnection());
     }
     if ($cache) {
         $cache->set($key, $objects);
     }
     return $objects;
 }
コード例 #6
0
<?php

if (defined('SYMFONY_VERSION') && 0 !== strpos(SYMFONY_VERSION, '1.0')) {
    // >= symfony 1.1
    $listener = array('sfGoogleAnalyticsListener', 'observe');
    $this->dispatcher->connect('request.method_not_found', $listener);
    $this->dispatcher->connect('response.method_not_found', $listener);
    $this->dispatcher->connect('component.method_not_found', $listener);
    $this->dispatcher->connect('user.method_not_found', $listener);
} else {
    // symfony 1.0
    $getter = array('sfGoogleAnalyticsMixin', 'getTracker');
    $setter = array('sfGoogleAnalyticsMixin', 'setTracker');
    sfMixer::register('sfRequest', $getter);
    sfMixer::register('sfRequest', $setter);
    sfMixer::register('sfResponse', $getter);
    sfMixer::register('sfResponse', $setter);
    sfMixer::register('sfComponent', $getter);
    sfMixer::register('sfComponent', $setter);
    sfMixer::register('sfUser', $getter);
    sfMixer::register('sfUser', $setter);
}
コード例 #7
0
ファイル: sfMixerTest.php プロジェクト: sensorsix/app
        myClass::$retStatic .= "in myStaticMethod mixin method\n";
    }
    public function myMixinStaticMethodWithArgs($class, $arg1, $arg2 = 'default')
    {
        myClass::$retStatic .= "in myStaticMethodWithArgs mixin method ({$arg1}, {$arg2})\n";
    }
    public function newMethod($object)
    {
        return "in newMethod mixin method\n";
    }
    public function newMethodWithArgs($object, $arg1, $arg2 = 'default')
    {
        return "in newMethodWithArgs mixin method ({$arg1}, {$arg2})\n";
    }
}
sfMixer::register('myClass:myMethod', array('myClassMixins', 'myMixinMethod'));
sfMixer::register('myClass:myStaticMethod', array('myClassMixins', 'myMixinStaticMethod'));
$t->is($m->myMethod(), "before myMethod\nin myMethod mixin method\nafter myMethod\n", 'method call with a mixin');
$t->is(myClass::myStaticMethod(), "before myStaticMethod\nin myStaticMethod mixin method\nafter myStaticMethod\n", 'static method call with a mixin');
sfMixer::register('myClass:myMethodWithArgs', array('myClassMixins', 'myMixinMethodWithArgs'));
$t->is($m->myMethodWithArgs('value'), "before myMethodWithArgs\nin myMethodWithArgs mixin method (value, default)\nafter myMethodWithArgs\n", 'method call with arguments with a mixin');
sfMixer::register('myClass:myStaticMethodWithArgs', array('myClassMixins', 'myMixinStaticMethodWithArgs'));
$t->is(myClass::myStaticMethodWithArgs('value'), "before myStaticMethodWithArgs\nin myStaticMethodWithArgs mixin method (value, default)\nafter myStaticMethodWithArgs\n", 'static method call with arguments with a mixin');
sfMixer::register('myClass', array('myClassMixins', 'newMethod'));
$t->is($m->newMethod(), "before __call\nin newMethod mixin method\nafter __call\n", 'method call from a mixin');
sfMixer::register('myClass', array('myClassMixins', 'newMethodWithArgs'));
$t->is($m->newMethodWithArgs('value'), "before __call\nin newMethodWithArgs mixin method (value, default)\nafter __call\n", 'method call from a mixin with arguments');
sfMixer::register('myClass:myMethodWithSeveralHooks:before', array('myClassMixins', 'myMethodWithSeveralHooksBefore'));
sfMixer::register('myClass:myMethodWithSeveralHooks', array('myClassMixins', 'myMethodWithSeveralHooks'));
sfMixer::register('myClass:myMethodWithSeveralHooks:after', array('myClassMixins', 'myMethodWithSeveralHooksAfter'));
$t->is($m->myMethodWithSeveralHooks(), "before myMethodWithSeveralHooks\nin myMethodWithSeveralHooks mixin method for before hook\nmyMethodWithSeveralHooks\nin myMethodWithSeveralHooks mixin method for default hook\nafter myMethodWithSeveralHooks\nin myMethodWithSeveralHooks mixin method for after hook\n", 'method call with several registered hooks');
コード例 #8
0
ファイル: config.php プロジェクト: royalterra/pdns-gui
<?php

/*
 * This file is part of the sfErrorHandler plugin
 * (c) 2008-2009 Lee Bolding <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * sfHardenedRenderingFilter is a replacement for the sfRenderingFilter
 * The sfHardenedRendderingFilter dynamically replaces the sfRenderingFilter for an app
 * when the sfErrorHandler is one of the enabled modules
 *
 * @package    sfErrorHandlerPlugin
 * @author     Lee Bolding <*****@*****.**>
 * @version    SVN: $Id$
 */
if (in_array('sfErrorHandler', sfConfig::get('sf_enabled_modules', array()))) {
    sfMixer::register('sfException:printStackTrace', array('sfErrorHandler', 'logExpection'));
    sfConfig::set('sf_rendering_filter', array('sfHardenedRenderingFilter', array()));
}
コード例 #9
0
ファイル: config.php プロジェクト: sgrove/cothinker
<?php

sfMixer::register('sfException:printStackTrace', array('sfErrorLogger', 'log500'));
sfMixer::register('sfController:forward:error404', array('sfErrorLogger', 'log404'));