Exemple #1
0
 private function _doSync()
 {
     $it = new DirectoryIterator(self::getCoreComponentsDir());
     foreach ($it as $dir) {
         if (!$dir->isDot() && $dir->isDir()) {
             $componentFile = new SplFileInfo($dir->getPathname() . DIRECTORY_SEPARATOR . 'Component' . DIRECTORY_SEPARATOR . 'Component.php');
             if ($componentFile->isFile()) {
                 try {
                     $class = new ReflectionClass('\\' . $dir->getFilename() . '\\Component\\Component');
                     if (!$class->isAbstract() && !$class->isInterface() && !$class->isTrait() && $class->implementsInterface('ModSync\\Component\\IsComponentInterface')) {
                         $o = $class->newInstance();
                         if ($o->isSyncable()) {
                             $o->sync();
                         }
                     }
                 } catch (LogicException $e) {
                     ModSync\Logger::warn($e->getMessage());
                 } catch (ReflectionException $e) {
                     ModSync\Logger::warn($e->getMessage());
                 } catch (\Exception $e) {
                     die($e->getMessage());
                 }
             }
         }
     }
 }
Exemple #2
0
 /**
  * Report execution time
  */
 public final function reportProfiling()
 {
     if (null !== $this->_profiling && $this->_profiling->enabled) {
         $this->_profiling->endTime = microtime();
         $begin = explode(' ', $this->_profiling->beginTime);
         $end = explode(' ', $this->_profiling->endTime);
         $this->_profiling->duration = $end[1] + $end[0] - ($begin[1] + $begin[0]);
         ModSync\Logger::debug(sprintf(get_called_class() . ': %s (%1.3f seconds)', $this->getName(), $this->_profiling->duration));
         if ($this->_profiling->duration > $this->_profiling->threshold) {
             ModSync\Logger::warn(sprintf(get_called_class() . ': inefficient code - %s (%1.3f seconds)', $this->getName(), $this->_profiling->duration));
         }
     }
 }
Exemple #3
0
 /**
  * Loops through elements to be synced
  *
  * @param string $path - path
  *
  * @todo Improve error handling of this method.
  */
 private function _syncFolder($path)
 {
     $dir = new \SplFileInfo($path);
     if (!$dir->isDir()) {
         return;
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
     $filePath = '';
     while ($it->valid()) {
         /* @var $file SplFileInfo */
         $file = $it->current();
         if ($filePath != $file->getPathname() && !$it->isDir() && $it->getExtension() == 'php') {
             $filePath = $file->getPathname();
             $name = str_replace(DIRECTORY_SEPARATOR, '\\', substr($file->getPathname(), strlen(self::getCoreComponentsDir() . DIRECTORY_SEPARATOR), (strlen($file->getExtension()) + 1) * -1));
             try {
                 $class = new ReflectionClass($name);
                 if (!$class->isAbstract() && !$class->isInterface() && !$class->isTrait() && $class->implementsInterface('ModSync\\IsSyncableInterface')) {
                     /* @var $o ModSync\IsSyncableInterface */
                     $o = $class->newInstance();
                     if ($o->isSyncable()) {
                         if ($class->implementsInterface('ModSync\\Element\\Category\\HasCategoryInterface')) {
                             if (!$o->hasCategory() && $this->hasCategory()) {
                                 $o->setCategory($this->getCategory());
                             }
                         }
                         $o->sync();
                     }
                 }
             } catch (LogicException $e) {
                 ModSync\Logger::warn($e->getMessage());
             } catch (ReflectionException $e) {
                 ModSync\Logger::warn($e->getMessage());
             } catch (\Exception $e) {
                 die($e->getMessage());
             }
         }
         $it->next();
     }
 }