Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function fileReflection($filename)
 {
     $fileMD5 = $this->files->md5($filename = $this->files->normalizePath($filename));
     $reflection = new ReflectionFile($this->fetchTokens($filename), (array) $this->memory->loadData($fileMD5, self::MEMORY_LOCATION));
     //Let's save to cache
     $this->memory->saveData($fileMD5, $reflection->exportSchema(), static::MEMORY_LOCATION);
     return $reflection;
 }
Esempio n. 2
0
 /**
  * Bootload set of classes
  *
  * @param array       $classes
  * @param string|null $memory Memory section to be used for caching, set to null to disable
  *                            caching.
  */
 public function bootload(array $classes, $memory = null)
 {
     if (!empty($memory)) {
         $schema = $this->memory->loadData($memory);
     }
     if (empty($schema) || $schema['snapshot'] != $classes) {
         //Schema expired or empty
         $schema = $this->generateSchema($classes, $this->container);
         if (!empty($memory)) {
             $this->memory->saveData($memory, $schema);
         }
         return;
     }
     //We can initiate schema thought the cached schema
     $this->schematicBootload($this->container, $schema);
 }
Esempio n. 3
0
 /**
  * Save language bundle into memory.
  *
  * @param string $bundle
  */
 protected function saveBundle($bundle)
 {
     if (!isset($this->bundles[$bundle])) {
         return;
     }
     $this->memory->saveData($bundle, $this->bundles[$bundle], $this->languageOptions['directory']);
 }
Esempio n. 4
0
 /**
  * Load environment data.
  *
  * @return $this
  */
 public function load()
 {
     if (!$this->files->exists($this->filename)) {
         throw new EnvironmentException("Unable to load environment, file is missing");
     }
     //Unique env file hash
     $this->id = $this->files->md5($this->filename);
     if (!empty($values = $this->memory->loadData($this->id, static::MEMORY_SECTION))) {
         //Restore from cache
         $this->initEnvironment($values);
         return $this;
     }
     //Load env values using DotEnv extension
     $values = $this->initEnvironment($this->parseValues($this->filename));
     $this->memory->saveData($this->id, $values, static::MEMORY_SECTION);
     return $this;
 }
Esempio n. 5
0
 /**
  * Locate every available Symfony command using Tokenizer.
  *
  * @return array
  */
 public function locateCommands()
 {
     $this->commands = [];
     foreach ($this->locator->getClasses(SymfonyCommand::class) as $class) {
         if ($class['abstract']) {
             continue;
         }
         $this->commands[] = $class['name'];
     }
     $this->memory->saveData('commands', $this->commands);
     return $this->commands;
 }
Esempio n. 6
0
 /**
  * Locate every available Symfony command using Tokenizer.
  *
  * @return array
  */
 public function findCommands()
 {
     $this->commands = [];
     foreach ($this->tokenizer->getClasses(SymfonyCommand::class, null, 'Command') as $class) {
         if ($class['abstract']) {
             continue;
         }
         $this->commands[] = $class['name'];
     }
     $this->memory->saveData('commands', $this->commands);
     return $this->commands;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function import($replace = false)
 {
     if (empty($this->language)) {
         throw new ImporterException("Unable to perform bundles import, no language detected.");
     }
     if (!isset($this->translator->config()['languages'][$this->language])) {
         throw new ImporterException("Unable to import language '{$this->language}', no presets found.");
     }
     $directory = $this->translator->config()['languages'][$this->language]['directory'];
     foreach ($this->bundles as $bundle => $strings) {
         if (!$replace && !empty($existed = $this->memory->loadData($bundle, $directory))) {
             $strings = $strings + $existed;
         }
         $this->memory->saveData($bundle, $strings, $directory);
     }
 }
Esempio n. 8
0
 /**
  * Find class declaration and load it.
  *
  * @param string $class Class name with namespace included.
  * @return bool
  */
 public function loadClass($class)
 {
     if (isset($this->loadmap[$class])) {
         try {
             //We already know route to class declaration
             include_once $this->classes[$class] = $this->loadmap[$class];
         } catch (\ErrorException $exception) {
             //File was replaced or removed
             unset($this->loadmap[$class]);
             if (!empty($this->name)) {
                 $this->memory->saveData($this->name, $this->loadmap);
             }
             //Try to update route to class
             return $this->loadClass($class);
         }
         return true;
     }
     //Composer and other loaders.
     foreach (spl_autoload_functions() as $function) {
         if ($function instanceof \Closure || $function[0] != $this) {
             //Calling loaders
             call_user_func($function, $class);
             if (class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false)) {
                 //Class has been successfully found by external loader
                 //External loader are not going to provide us any information about class
                 //location, let's get it via Reflection
                 $reflector = new \ReflectionClass($class);
                 try {
                     $filename = str_replace('\\', '/', $reflector->getFileName());
                     $filename = rtrim(str_replace('//', '/', $filename), '/');
                     //Direct access to filesystem, yep.
                     if (file_exists($filename)) {
                         $this->loadmap[$class] = $this->classes[$class] = $filename;
                         $this->memory->saveData($this->name, $this->loadmap);
                     }
                 } catch (\ErrorException $exception) {
                     //getFileName can throw and exception, we can ignore it
                 }
                 //Class found
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 9
0
 /**
  * Get singular primary key associated with desired table. Used to emulate last insert id.
  *
  * @param string $table Fully specified table name, including postfix.
  * @return string
  * @throws DriverException
  */
 public function getPrimary($table)
 {
     if (empty($this->primaryKeys)) {
         $this->primaryKeys = $this->memory->loadData($this->getSource() . '-primary');
     }
     if (!empty($this->primaryKeys) && array_key_exists($table, $this->primaryKeys)) {
         return $this->primaryKeys[$table];
     }
     if (!$this->hasTable($table)) {
         throw new DriverException("Unable to fetch table primary key, no such table '{$table}' exists.");
     }
     $this->primaryKeys[$table] = $this->tableSchema($table)->getPrimaryKeys();
     if (count($this->primaryKeys[$table]) === 1) {
         //We do support only single primary key
         $this->primaryKeys[$table] = $this->primaryKeys[$table][0];
     } else {
         $this->primaryKeys[$table] = null;
     }
     //Caching
     $this->memory->saveData($this->getSource() . '-primary', $this->primaryKeys);
     return $this->primaryKeys[$table];
 }
Esempio n. 10
0
 /**
  * Load catalogue data from source.
  *
  * @param string $locale
  * @return Catalogue
  */
 protected function loadCatalogue($locale)
 {
     $catalogue = new Catalogue($locale, $this->memory);
     if (array_key_exists($locale, $this->loadedLocales) && $this->config->cacheLocales()) {
         //Has been loaded
         return $catalogue;
     }
     $benchmark = $this->benchmark('load', $locale);
     try {
         //Loading catalogue data from source
         foreach ($this->source->loadLocale($locale) as $messageCatalogue) {
             $catalogue->mergeFrom($messageCatalogue);
         }
         //To remember that locale already loaded
         $this->loadedLocales[$locale] = $catalogue->getDomains();
         $this->memory->saveData(static::MEMORY, $this->loadedLocales);
         //Saving domains memory
         $catalogue->saveDomains();
     } finally {
         $this->benchmark($benchmark);
     }
     return $catalogue;
 }
Esempio n. 11
0
 /**
  * Update ORM records schema, synchronize declared and database schemas and return instance of
  * SchemaBuilder.
  *
  * @param SchemaBuilder $builder User specified schema builder.
  * @return SchemaBuilder
  */
 public function updateSchema(SchemaBuilder $builder = null)
 {
     $builder = !empty($builder) ? $builder : $this->schemaBuilder();
     //Casting relations between records
     $builder->castRelations();
     //Create all required tables and columns
     $builder->synchronizeSchema();
     //Saving
     $this->memory->saveData(static::SCHEMA_SECTION, $this->schema = $builder->normalizeSchema());
     //Let's reinitialize records
     DataEntity::resetInitiated();
     return $builder;
 }
Esempio n. 12
0
 /**
  * Update ODM documents schema and return instance of SchemaBuilder.
  *
  * @param SchemaBuilder $builder User specified schema builder.
  * @return SchemaBuilder
  */
 public function updateSchema(SchemaBuilder $builder = null)
 {
     $builder = !empty($builder) ? $builder : $this->schemaBuilder();
     //We will create all required indexes now
     $builder->createIndexes();
     //Saving
     $this->memory->saveData(static::SCHEMA_SECTION, $this->schema = $builder->normalizeSchema());
     //Let's reinitialize models
     DataEntity::resetInitiated();
     return $builder;
 }
Esempio n. 13
0
 /**
  * Update ORM records schema, synchronize declared and database schemas and return instance of
  * SchemaBuilder.
  *
  * @param SchemaBuilder $builder    User specified schema builder.
  * @param bool          $syncronize Create all required tables and columns
  * @return SchemaBuilder
  */
 public function updateSchema(SchemaBuilder $builder = null, $syncronize = false)
 {
     if (empty($builder)) {
         $builder = $this->schemaBuilder();
     }
     //Create all required tables and columns
     if ($syncronize) {
         $builder->synchronizeSchema();
     }
     //Getting normalized (cached) version of schema
     $this->schema = $builder->normalizeSchema();
     //Saving
     $this->memory->saveData(static::MEMORY, $this->schema);
     //Let's reinitialize records
     DataEntity::resetInitiated();
     return $builder;
 }
Esempio n. 14
0
 /**
  * Save domain data into memory.
  *
  * @param string $domain
  * @param array  $data
  */
 protected function saveDomain($domain, $data)
 {
     $this->memory->saveData("{$this->locale}-{$domain}", $data, static::MEMORY_LOCATION);
 }
Esempio n. 15
0
 /**
  * @param HippocampusInterface $memory
  */
 public function perform(HippocampusInterface $memory)
 {
     $memory->saveData('bootloading', null);
     $this->writeln("<info>Bootload cache has been cleared.</info>");
 }
Esempio n. 16
0
 /**
  * Update ODM documents schema and return instance of SchemaBuilder.
  *
  * @param SchemaBuilder $builder User specified schema builder.
  * @param bool          $createIndexes
  * @return SchemaBuilder
  */
 public function updateSchema(SchemaBuilder $builder = null, $createIndexes = false)
 {
     if (empty($builder)) {
         $builder = $this->schemaBuilder();
     }
     //We will create all required indexes now
     if ($createIndexes) {
         $builder->createIndexes();
     }
     //Getting cached/normalized schema
     $this->schema = $builder->normalizeSchema();
     //Saving
     $this->memory->saveData(static::MEMORY, $this->schema);
     //Let's reinitialize models
     DataEntity::resetInitiated();
     return $builder;
 }