/** * Overloading method to convert this implementation to a string. * * @return string */ public function __toString() { if ($tz = Norm::options('tz')) { $this->setTimezone(new DateTimeZone($tz)); } return $this->format('c'); }
/** * Initialize the provider */ public function initialize() { $app = $this->app; $include = $app->request->get('!include'); if (!empty($include)) { Norm::options('include', true); } $tz = $app->request->get('!tz'); if (!empty($tz)) { Norm::options('tz', $tz); } if (!isset($this->options['datasources'])) { $this->options['datasources'] = $this->app->config('norm.datasources'); } // DEPRECATED: norm.databases deprecated if (!isset($this->options['datasources'])) { $this->options['datasources'] = $this->app->config('norm.databases'); } if (!isset($this->options['datasources'])) { throw new \Exception('[Norm] No data source configuration. Append "norm.datasources" bono configuration!'); } if (!isset($this->options['collections'])) { $this->options['collections'] = $this->app->config('norm.collections'); } Norm::init($this->options['datasources'], $this->options['collections']); $controllerConfig = $this->app->config('bono.controllers'); if (!isset($controllerConfig['default'])) { $controllerConfig['default'] = 'Norm\\Controller\\NormController'; } $this->app->config('bono.controllers', $controllerConfig); if (!class_exists('Norm')) { class_alias('Norm\\Norm', 'Norm'); } $d = explode(DIRECTORY_SEPARATOR . 'src', __DIR__); $this->app->theme->addBaseDirectory($d[0], 10); }
public function toJSON($value) { if (!is_string($this['foreign'])) { $foreign = val($this['foreign']); if (isset($foreign[$value])) { if (is_scalar($foreign[$value])) { return $value; } else { return $foreign[$value]; } } return null; } $foreignCollection = Norm::factory($this['foreign']); if (Norm::options('include')) { $foreignKey = $this['foreignKey']; if (is_null($foreignKey)) { return $foreignCollection->findOne($value); } else { return $foreignCollection->findOne(array($this['foreignKey'] => $value)); } } return $value; }
/** * Implement the json serializer normalizing the data structures. * * @return array */ public function jsonSerialize() { if (!Norm::options('include')) { return $this->toArray(); } $destination = array(); $source = $this->toArray(); $schema = $this->collection->schema(); foreach ($source as $key => $value) { if (isset($schema[$key]) and isset($value)) { $destination[$key] = $schema[$key]->toJSON($value); } else { $destination[$key] = $value; } $destination[$key] = JsonKit::replaceObject($destination[$key]); } return $destination; }
public function toJSON($value) { if (!is_string($this['foreign'])) { // FIXME should return translated value if non scalar foreign item return $value; } $foreignCollection = Norm::factory($this['foreign']); if (Norm::options('include')) { $foreignKey = $this['foreignKey']; $newValue = array(); foreach ($value as $k => $v) { if (is_null($foreignKey)) { $newValue[] = $foreignCollection->findOne($v); } else { $newValue[] = $foreignCollection->findOne(array($this['foreignKey'] => $v)); } } $value = $newValue; } return $value; }