/** * Sets a variable in this session namespace. * @param string name * @param mixed value * @return void */ public function __set($name, $value) { $this->data[$name] = $value; if (is_object($value)) { $this->meta[$name]['V'] = Nette\Reflection\ClassReflection::from($value)->getAnnotation('serializationVersion'); } }
/** * Registers adapter for given file extension. * @param string file extension * @param string class name (IConfigAdapter) * @return void */ public static function registerExtension($extension, $class) { if (!class_exists($class)) { throw new \InvalidArgumentException("Class '{$class}' was not found."); } if (!Nette\Reflection\ClassReflection::from($class)->implementsInterface('Nette\\Config\\IConfigAdapter')) { throw new \InvalidArgumentException("Configuration adapter '{$class}' is not Nette\\Config\\IConfigAdapter implementor."); } self::$extensions[strtolower($extension)] = $class; }
/** * Returns annotations. * @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty * @return array */ public static function getAll(\Reflector $r) { if ($r instanceof \ReflectionClass) { $type = $r->getName(); $member = ''; } elseif ($r instanceof \ReflectionMethod) { $type = $r->getDeclaringClass()->getName(); $member = $r->getName(); } else { $type = $r->getDeclaringClass()->getName(); $member = '$' . $r->getName(); } if (!self::$useReflection) { // auto-expire cache $file = $r instanceof \ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName(); // will be used later if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) { unset(self::$cache[$type]); } unset(self::$timestamps[$file]); } if (isset(self::$cache[$type][$member])) { // is value cached? return self::$cache[$type][$member]; } if (self::$useReflection === NULL) { // detects whether is reflection available self::$useReflection = (bool) Nette\Reflection\ClassReflection::from(__CLASS__)->getDocComment(); } if (self::$useReflection) { return self::$cache[$type][$member] = self::parseComment($r->getDocComment()); } else { if (self::$cache === NULL) { self::$cache = (array) self::getCache()->offsetGet('list'); self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array(); } if (!isset(self::$cache[$type]) && $file) { self::$cache['*'][$file] = filemtime($file); self::parseScript($file); self::getCache()->save('list', self::$cache); } if (isset(self::$cache[$type][$member])) { return self::$cache[$type][$member]; } else { return self::$cache[$type][$member] = array(); } } }
public function universalFactory($options) { $arguments = isset($options["arguments"]) ? $this->processArguments($options["arguments"], $options["context"]) : array(); if (isset($options["class"])) { if (!empty($arguments)) { $object = ClassReflection::from($options["class"])->newInstanceArgs($arguments); } else { $class = $options["class"]; $object = new $class(); } } if (isset($options["factory"])) { $object = call_user_func_array($options["factory"], $arguments); } if (isset($options["callMethods"])) { foreach ($options["callMethods"] as $method => $args) { call_user_func_array(array($object, $method), $this->processArguments($args, $options["context"])); } } return $object; }
protected function execute(InputInterface $input, OutputInterface $output) { $name = ClassReflection::from($input->getOption("entity"))->getShortName(); $dir = $input->getOption("output") ?: APP_DIR . "/AdminModule/forms/{$name}"; $em = $this->getHelper("em")->getEntityManager(); /* @var $em \Doctrine\ORM\EntityManager */ $config = $em->getClassMetadata($input->getOption("entity")); $pk = $config->getSingleIdentifierFieldName(); foreach ($config->getColumnNames() as $column) { $fieldName = $config->getFieldName($column); if ($fieldName === $pk) { continue; } $maping = $config->getFieldMapping($fieldName); $field = (object) array("name" => $fieldName); if ($maping["type"] === "text") { $field->inputName = "TextArea"; } elseif ($maping["type"] === "boolean") { $field->inputName = "Checkbox"; } else { $field->inputName = "Text"; } $fields[] = $field; } foreach ($config->getAssociationMappings() as $maping) { $field = (object) null; $field->name = $maping["fieldName"]; $field->inputName = "Select"; $fields[] = $field; } $template = $this->createTemplate()->setFile(__DIR__ . "/formClass.phtml"); $template->name = $name; $template->fields = $fields; $this->tryWriteFile($dir . '/' . $name . 'Form.php', $template, $output); $template = $this->createTemplate()->setFile(__DIR__ . "/formTemplate.phtml"); $template->fields = $fields; $this->tryWriteFile($dir . '/' . $name . 'Form.phtml', $template, $output); }
/** * Starts and initializes session data. * @throws \InvalidStateException * @return void */ public function start() { if (self::$started) { throw new \InvalidStateException('Session has already been started.'); } elseif (self::$started === NULL && defined('SID')) { throw new \InvalidStateException('A session had already been started by session.auto-start or session_start().'); } // start session try { $this->configure($this->options); } catch (\NotSupportedException $e) { // ignore? } Nette\Tools::tryError(); session_start(); if (Nette\Tools::catchError($msg)) { @session_write_close(); // this is needed throw new \InvalidStateException($msg); } self::$started = TRUE; if ($this->regenerationNeeded) { session_regenerate_id(TRUE); $this->regenerationNeeded = FALSE; } /* structure: __NF: Counter, BrowserKey, Data, Meta DATA: namespace->variable = data META: namespace->variable = Timestamp, Browser, Version */ unset($_SESSION['__NT'], $_SESSION['__NS'], $_SESSION['__NM']); // old unused structures // initialize structures $nf =& $_SESSION['__NF']; if (empty($nf)) { // new session $nf = array('C' => 0); } else { $nf['C']++; } // browser closing detection $browserKey = $this->getHttpRequest()->getCookie('nette-browser'); if (!$browserKey) { $browserKey = (string) lcg_value(); } $browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey; $nf['B'] = $browserKey; // resend cookie $this->sendCookie(); // process meta metadata if (isset($nf['META'])) { $now = time(); // expire namespace variables foreach ($nf['META'] as $namespace => $metadata) { if (is_array($metadata)) { foreach ($metadata as $variable => $value) { if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || $variable !== '' && is_object($nf['DATA'][$namespace][$variable]) && (isset($value['V']) ? $value['V'] : NULL) !== Nette\Reflection\ClassReflection::from($nf['DATA'][$namespace][$variable])->getAnnotation('serializationVersion')) { if ($variable === '') { // expire whole namespace unset($nf['META'][$namespace], $nf['DATA'][$namespace]); continue 2; } unset($nf['META'][$namespace][$variable], $nf['DATA'][$namespace][$variable]); } } } } } register_shutdown_function(array($this, 'clean')); }
/** * Checks object @serializationVersion label. * @param string * @param mixed * @return bool */ private static function checkSerializationVersion($class, $value) { return Nette\Reflection\ClassReflection::from($class)->getAnnotation('serializationVersion') === $value; }
/** * Returns array of persistent components. * This default implementation detects components by class-level annotation @persistent(cmp1, cmp2). * @return array */ public static function getPersistentComponents() { return (array) Nette\Reflection\ClassReflection::from(get_called_class())->getAnnotation('persistent'); }
/** * Load associations */ protected function loadAssociations() { $annotations = ClassReflection::from($this->rowClass)->getAnnotations(); foreach ($annotations as $k => $v) { if ($v[0] instanceof \Ormion\Association\IAssociation) { foreach ($v as $association) { $association->setMapper($this); $this->associations[$association->getName()] = $association; } } } }
/** * Get entity instance with default data * * @param ActiveMapper\Manager $em * @param array $data * @return mixed */ public function getInstance(Manager $em, $data) { if (!is_array($data) && !$data instanceof \ArrayAccess) { throw new \InvalidArgumentException("Get instance data must be array or implement ArrayAccess."); } $ref = ClassReflection::from($this->entity); if ($this->hasProxy()) { $instance = $ref->newInstance($data); } else { $instance = $ref->newInstance(); foreach ($this->columns as $column) { $tmpName = Tools::underscore($column->name); if (isset($data[$tmpName])) { $prop = $ref->getProperty($column->name); $prop->setAccessible(TRUE); $prop->setValue($instance, $column->convertToPHPValue($data[$tmpName])); $prop->setAccessible(FALSE); } } } if (count($this->getAssociations()) > 0) { $propRef = $ref->getProperty('_associations'); $propRef->setAccessible(TRUE); $associations = $propRef->getValue($instance); foreach ($this->getAssociations() as $assoc) { $associations[$assoc->name] = new Associations\LazyLoad($em, $this->entity, $assoc->name, $data); } $propRef->setValue($instance, $associations); $propRef->setAccessible(FALSE); } return $instance; }
/** * Returns array of persistent components. * This default implementation detects components by class-level annotation @persistent(cmp1, cmp2). * @return array */ public static function getPersistentComponents() { return (array) Nette\Reflection\ClassReflection::from(/*5.2*func_get_arg(0)*//**/get_called_class()/**/)->getAnnotation('persistent'); }