示例#1
0
 /**
  * Assigns entity to form ( Doctrine 2 ).
  *
  * @param object $entity The Doctrine2 Entity
  * @param OSS_Controller_Action $controller An instance of OSS_Controller_Action
  * @param bool $isEdit
  * @return OSS_Form The form object
  */
 public function assignEntityToForm($entity, $controller, $isEdit = true)
 {
     $fields = $controller->getD2EM()->getClassMetadata(get_class($entity))->getFieldNames();
     foreach ($this->getElements() as $eName => $eConfig) {
         if (in_array($eName, $fields)) {
             $fn = 'get' . Doctrine\Common\Util\Inflector::classify($eName);
             if ($entity->{$fn}() instanceof DateTime) {
                 $this->getElement($eName)->setValue($entity->{$fn}()->format('Y-m-d H:i:s'));
             } else {
                 $this->getElement($eName)->setValue($entity->{$fn}());
             }
         }
     }
     return $this;
 }
示例#2
0
文件: init.php 项目: Devdits/pinboard
    } else {
        $baseUrl = $app['params']['base_url'];
    }
    if (substr($baseUrl, -1) != '/') {
        $baseUrl .= '/';
    }
    $twig->addGlobal('base_url', $baseUrl);
    return $twig;
}));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$dbOptions = array('driver' => 'pdo_mysql', 'dbname' => $app['params']['db']['name'], 'host' => $app['params']['db']['host'], 'user' => $app['params']['db']['user'], 'password' => $app['params']['db']['pass']);
if (isset($app['params']['db']['port'])) {
    $dbOptions['port'] = $app['params']['db']['port'];
}
if (isset($app['params']['db']['unix_socket'])) {
    $dbOptions['unix_socket'] = $app['params']['db']['unix_socket'];
}
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dbOptions));
$app['dbs.config']['default']->setSQLLogger(new DbalLogger(new Stopwatch(), $app['params']['db']['host']));
//query caching
$cacheClassName = 'Doctrine\\Common\\Cache\\' . (isset($app['params']['cache']) ? Doctrine\Common\Util\Inflector::classify($app['params']['cache']) : 'Array') . 'Cache';
$app['db']->getConfiguration()->setResultCacheImpl(new $cacheClassName());
$users = array();
if (isset($app['params']['secure']['users'])) {
    foreach ($app['params']['secure']['users'] as $userName => $userData) {
        $users[$userName] = array("ROLE_USER", $userData['password']);
    }
}
if (isset($app['params']['secure']['enable']) && $app['params']['secure']['enable']) {
    $app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('secure_area' => array('pattern' => "^/", 'http' => true, 'users' => $users))));
}
 public function loadCollectionLoop($o, $entity, $collection)
 {
     $data = array();
     $filter = 'filterPersistentCollection';
     if ($entity) {
         $meta = self::getEntityMetadata(get_class($entity));
         $params = func_get_args();
         unset($params[0], $params[2]);
         $repoGetColl = 'getEntity' . Doctrine\Common\Util\Inflector::classify($collection);
         $getColl = 'get' . Doctrine\Common\Util\Inflector::classify($collection);
         if (method_exists($meta->customRepositoryClassName, $repoGetColl)) {
             $repo = EM()->getRepository($meta->name);
             $coll = call_user_func_array(array($repo, $repoGetColl), $params);
             $data = $coll->toArray();
         } else {
             if (method_exists($entity, $getColl)) {
                 $coll = call_user_func_array(array($entity, $getColl), $params);
                 $data = $coll->toArray();
             } else {
                 throw new \InvalidArgumentException("The getter : {$getColl} does not exists in {$meta->name} or {$meta->customRepositoryClassName}");
             }
         }
         if ($coll instanceof \Doctrine\Common\Collections\ArrayCollection) {
             $filter = 'filterArrayCollection';
         } else {
             if ($coll instanceof \Doctrine\ORM\PersistentCollection) {
                 $filter = 'filterPersistentCollection';
             }
         }
     }
     $o->{$collection} = new loop_array($data, array($this, $filter));
     return $o;
 }