예제 #1
0
 /**
  * @return array
  */
 public function getUnregisteredExtensions()
 {
     $unregisteredExtensions = array();
     $coreFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Fraym' . DIRECTORY_SEPARATOR . '*.php');
     $extensionFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . '*.php');
     $files = array_merge($coreFiles, $extensionFiles);
     foreach ($files as $file) {
         $classname = basename($file, '.php');
         $namespace = str_ireplace($this->core->getApplicationDir(), '', dirname($file));
         $namespace = str_replace('/', '\\', $namespace) . '\\';
         $class = $namespace . $classname;
         if (is_file($file)) {
             require_once $file;
             if (class_exists($class)) {
                 $classAnnotation = $this->getRegistryConfig($class);
                 if ($classAnnotation) {
                     $registryEntry = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findOneByClassName($class);
                     if ($registryEntry === null) {
                         $unregisteredExtensions[$class] = (array) $classAnnotation;
                         $unregisteredExtensions[$class]['file'] = $file;
                         $unregisteredExtensions[$class]['fileHash'] = md5($file);
                     }
                 }
             }
         }
     }
     return $unregisteredExtensions;
 }
예제 #2
0
 /**
  * @return array
  */
 public function getExtensions()
 {
     $extensions = [];
     $coreFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Fraym' . DIRECTORY_SEPARATOR . '*.php');
     $extensionFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . '*.php');
     $files = array_merge($coreFiles, $extensionFiles);
     foreach ($files as $file) {
         $classname = basename($file, '.php');
         $namespace = str_ireplace($this->core->getApplicationDir(), '', dirname($file));
         $namespace = str_replace('/', '\\', $namespace) . '\\';
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Extension' . preg_quote('\\') . '#', '\\Fraym\\Extension\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Hook' . preg_quote('\\') . '#', '\\Fraym\\Hook\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Test' . preg_quote('\\') . '#', '\\Fraym\\Test\\', $namespace);
         $class = $namespace . $classname;
         if (is_file($file)) {
             require_once $file;
             if (class_exists($class)) {
                 $classAnnotation = $this->getRegistryConfig($class);
                 if ($classAnnotation) {
                     $registryEntry = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findOneByClassName($class);
                     $extensions[$class] = (array) $classAnnotation;
                     if ($classAnnotation->composerPackage === true) {
                         $package = $this->getPackage($classAnnotation->repositoryKey);
                         if ($package) {
                             $package = $this->getLatestPackageVersion($package);
                             $extensions[$class]['package'] = $package->getName();
                             $extensions[$class]['description'] = $package->getDescription();
                             $extensions[$class]['version'] = $package->getVersion();
                             $extensions[$class]['homepage'] = $package->getHomepage();
                             $extensions[$class]['author'] = $this->getAuthorsFromPackage($package);
                         }
                     } else {
                         $extensions[$class]['package'] = $classAnnotation->repositoryKey;
                         $extensions[$class]['description'] = '';
                         $extensions[$class]['version'] = '0.0.0';
                         $extensions[$class]['homepage'] = null;
                         $extensions[$class]['author'] = null;
                     }
                     $extensions[$class]['registred'] = $registryEntry !== null;
                 }
             }
         }
     }
     return $extensions;
 }
예제 #3
0
파일: Database.php 프로젝트: fraym/core
 /**
  * @return $this
  */
 public function connect()
 {
     // Prevent to connect twice
     if ($this->entityManager) {
         return $this;
     }
     $applicationDir = $this->core->getApplicationDir();
     $this->createModuleDirCache();
     $cache = $this->cache->getCacheProvider();
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl($cache);
     $config->addCustomStringFunction('MD5', '\\DoctrineExtensions\\Query\\Mysql\\Md5');
     $config->addCustomStringFunction('ACOS', '\\DoctrineExtensions\\Query\\Mysql\\Acos');
     $config->addCustomStringFunction('ASIN', '\\DoctrineExtensions\\Query\\Mysql\\Asin');
     $config->addCustomStringFunction('ATAN', '\\DoctrineExtensions\\Query\\Mysql\\Atan');
     $config->addCustomStringFunction('ATAN2', '\\DoctrineExtensions\\Query\\Mysql\\Atan2');
     $config->addCustomStringFunction('BINARY', '\\DoctrineExtensions\\Query\\Mysql\\Binary');
     $config->addCustomStringFunction('CHARLENGTH', '\\DoctrineExtensions\\Query\\Mysql\\CharLength');
     $config->addCustomStringFunction('CONCATWS', '\\DoctrineExtensions\\Query\\Mysql\\ConcatWs');
     $config->addCustomStringFunction('COS', '\\DoctrineExtensions\\Query\\Mysql\\Cos');
     $config->addCustomStringFunction('COT', '\\DoctrineExtensions\\Query\\Mysql\\COT');
     $config->addCustomStringFunction('COUNTIF', '\\DoctrineExtensions\\Query\\Mysql\\CountIf');
     $config->addCustomStringFunction('CRC32', '\\DoctrineExtensions\\Query\\Mysql\\Crc32');
     $config->addCustomStringFunction('DATE', '\\DoctrineExtensions\\Query\\Mysql\\Date');
     $config->addCustomStringFunction('DATEADD', '\\DoctrineExtensions\\Query\\Mysql\\DateAdd');
     $config->addCustomStringFunction('DATEDIFF', '\\DoctrineExtensions\\Query\\Mysql\\DateFormat');
     $config->addCustomStringFunction('DAY', '\\DoctrineExtensions\\Query\\Mysql\\Day');
     $config->addCustomStringFunction('DEGREES', '\\DoctrineExtensions\\Query\\Mysql\\Degrees');
     $config->addCustomStringFunction('FIELD', '\\DoctrineExtensions\\Query\\Mysql\\Field');
     $config->addCustomStringFunction('FINDINSET', '\\DoctrineExtensions\\Query\\Mysql\\FindInSet');
     $config->addCustomStringFunction('GROUPCONCAT', '\\DoctrineExtensions\\Query\\Mysql\\GroupConcat');
     $config->addCustomStringFunction('HOUR', '\\DoctrineExtensions\\Query\\Mysql\\Hour');
     $config->addCustomStringFunction('IFELSE', '\\DoctrineExtensions\\Query\\Mysql\\IfElse');
     $config->addCustomStringFunction('IFNULL', '\\DoctrineExtensions\\Query\\Mysql\\IfNUll');
     $config->addCustomStringFunction('MATCHAGAINST', '\\DoctrineExtensions\\Query\\Mysql\\MatchAgainst');
     $config->addCustomStringFunction('MONTH', '\\DoctrineExtensions\\Query\\Mysql\\Month');
     $config->addCustomStringFunction('NULLIF', '\\DoctrineExtensions\\Query\\Mysql\\NullIf');
     $config->addCustomStringFunction('PI', '\\DoctrineExtensions\\Query\\Mysql\\Pi');
     $config->addCustomStringFunction('RADIANS', '\\DoctrineExtensions\\Query\\Mysql\\Radians');
     $config->addCustomStringFunction('RAND', '\\DoctrineExtensions\\Query\\Mysql\\Rand');
     $config->addCustomStringFunction('REGEXP', '\\DoctrineExtensions\\Query\\Mysql\\Regexp');
     $config->addCustomStringFunction('ROUND', '\\DoctrineExtensions\\Query\\Mysql\\Round');
     $config->addCustomStringFunction('SHA1', '\\DoctrineExtensions\\Query\\Mysql\\Sha1');
     $config->addCustomStringFunction('SHA2', '\\DoctrineExtensions\\Query\\Mysql\\Sha2');
     $config->addCustomStringFunction('SIN', '\\DoctrineExtensions\\Query\\Mysql\\Sin');
     $config->addCustomStringFunction('STRTODATE', '\\DoctrineExtensions\\Query\\Mysql\\StrToDate');
     $config->addCustomStringFunction('TAN', '\\DoctrineExtensions\\Query\\Mysql\\Tan');
     $config->addCustomStringFunction('TIMESTAMPDIFF', '\\DoctrineExtensions\\Query\\Mysql\\TimestampDiff');
     $config->addCustomStringFunction('WEEK', '\\DoctrineExtensions\\Query\\Mysql\\Week');
     $config->addCustomStringFunction('YEAR', '\\DoctrineExtensions\\Query\\Mysql\\Year');
     if (!defined('ENV') || ENV === \Fraym\Core::ENV_DEVELOPMENT) {
         $config->setAutoGenerateProxyClasses(true);
     }
     $modelDirs = $this->getModuleDirCache();
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) {
         return class_exists($class, true);
     });
     $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
     $this->cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
     $this->annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->cachedAnnotationReader, $modelDirs);
     /**
      * Ignore PHP-DI Annotation
      */
     $annotationReader->addGlobalIgnoredName('Injectable');
     $annotationReader->addGlobalIgnoredName('Inject');
     $config->setMetadataDriverImpl($this->annotationDriver);
     $config->setQueryCacheImpl($cache);
     $config->setResultCacheImpl($cache);
     $config->setProxyDir($applicationDir . DIRECTORY_SEPARATOR . CACHE_DOCTRINE_PROXY_PATH);
     $config->setProxyNamespace('Proxies');
     $this->fetchMode = \PDO::FETCH_OBJ;
     $tablePrefix = new TablePrefix(DB_TABLE_PREFIX);
     $this->eventManager = new \Doctrine\Common\EventManager();
     $this->eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
     $this->entityManager = \Doctrine\ORM\EntityManager::create($this->connectionOptions, $config, $this->eventManager);
     $this->pdo = $this->entityManager->getConnection();
     $this->pdo->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
     $driverChain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
     \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $this->cachedAnnotationReader);
     $this->eventManager->addEventListener([\Doctrine\ORM\Events::preRemove, \Doctrine\ORM\Events::postRemove, \Doctrine\ORM\Events::prePersist, \Doctrine\ORM\Events::postPersist, \Doctrine\ORM\Events::preUpdate, \Doctrine\ORM\Events::postUpdate, \Doctrine\ORM\Events::postLoad, \Doctrine\ORM\Events::onFlush], $this->eventListener);
     return $this;
 }
예제 #4
0
 /**
  * @param $xml
  * @return string
  * @throws \Exception
  */
 private function execBlockOfTypeImage($xml)
 {
     $imageTags = array('width' => $this->getXMLAttr($xml, 'width'), 'height' => $this->getXMLAttr($xml, 'height'), 'alt' => $this->getXMLAttr($xml, 'alt'), 'class' => $this->getXMLAttr($xml, 'class'), 'align' => $this->getXMLAttr($xml, 'align'), 'ismap' => $this->getXMLAttr($xml, 'ismap'), 'crossoriginNew' => $this->getXMLAttr($xml, 'crossoriginNew'), 'usemap' => $this->getXMLAttr($xml, 'usemap'));
     $placeHolderConfig = array('phtext' => $this->getXMLAttr($xml, 'phtext'), 'phwidth' => $this->getXMLAttr($xml, 'phwidth'), 'phheight' => $this->getXMLAttr($xml, 'phheight'), 'phcolor' => $this->getXMLAttr($xml, 'phcolor'), 'phbgcolor' => $this->getXMLAttr($xml, 'phbgcolor'), 'phfont' => $this->getXMLAttr($xml, 'phfont'), 'phfontsize' => $this->getXMLAttr($xml, 'phfontsize'));
     $src = $this->getXMLAttr($xml, 'src');
     $src = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $src);
     if ($src === null) {
         $srcFilePath = $src = $this->createImagePlaceholder($placeHolderConfig);
     } else {
         if (substr($src, 0, 1) === '/' || strpos($src, ':') !== false) {
             // absolute path
             $srcFilePath = $src;
         } else {
             // relative path
             $srcFilePath = $this->core->getApplicationDir() . DIRECTORY_SEPARATOR . ltrim($src, '/');
         }
         if (is_file($srcFilePath) === false) {
             return '';
         }
     }
     $imagine = $this->serviceLocator->get('Imagine');
     $image = $imagine->open($srcFilePath);
     $pathInfo = pathinfo($srcFilePath);
     $allowedMethods = array('thumbnail', 'resize', '');
     // methods fit / resize / none
     $imageQuality = intval($this->getXMLAttr($xml, 'quality') ?: '80');
     $method = $this->getXMLAttr($xml, 'method') ?: '';
     $mode = $this->getXMLAttr($xml, 'mode') ?: 'outbound';
     if (!in_array($method, $allowedMethods)) {
         throw new \Exception("Image method '{$method}' is not allowed.");
     }
     if (!empty($method)) {
         $imageBox = $this->getImageBox($imageTags, $image);
         $imagePath = $this->getImageSavePath($pathInfo['filename'] . '_' . md5_file($srcFilePath), $imageBox->getWidth(), $imageBox->getHeight(), $pathInfo['extension']);
         if (!is_file($imagePath)) {
             if ($method == 'resize') {
                 $image->resize($imageBox);
             } else {
                 if ($mode == 'outbound') {
                     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
                 } else {
                     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
                 }
                 $image = $image->thumbnail(new \Imagine\Image\Box($imageTags['width'], $imageTags['height']), $mode);
                 // new Box($imageTags['width'], $imageTags['height']));
             }
             $image->save($imagePath, array('quality' => $imageQuality));
             $imageTags['width'] = $image->getSize()->getWidth();
             $imageTags['height'] = $image->getSize()->getHeight();
         } else {
             $image = $imagine->open($imagePath);
             $imageTags['width'] = $image->getSize()->getWidth();
             $imageTags['height'] = $image->getSize()->getHeight();
         }
         // remove Public folder
         $convertedImageFileName = substr($imagePath, strpos($imagePath, DIRECTORY_SEPARATOR) + 1);
     } else {
         $convertedImageFileName = ltrim(str_replace('\\', '/', str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath($src))), '/');
         $imageTags['width'] = $image->getSize()->getWidth();
         $imageTags['height'] = $image->getSize()->getHeight();
     }
     if ($this->getXMLAttr($xml, 'autosize')) {
         unset($imageTags['width']);
         unset($imageTags['height']);
     }
     $attributes = '';
     foreach ($imageTags as $tag => $val) {
         if (empty($val) === false) {
             $attributes .= "{$tag}=\"{$val}\" ";
         }
     }
     if ($src === null) {
         unlink($srcFilePath);
     }
     return '<img src="/' . str_replace(array('\\', '/'), '/', $convertedImageFileName) . '" ' . $attributes . ' />';
 }
예제 #5
0
파일: Route.php 프로젝트: fraym/core
 /**
  * @return $this
  */
 protected function initAnnotationRoutes()
 {
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile($this->core->getApplicationDir() . '/Fraym/Annotation/Route.php');
     $coreFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Fraym' . DIRECTORY_SEPARATOR . '*.php');
     $extensionFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . '*.php');
     foreach (array_merge($coreFiles, $extensionFiles) as $file) {
         $classname = basename($file, '.php');
         $namespace = str_ireplace($this->core->getApplicationDir(), '', dirname($file));
         $namespace = str_replace('/', '\\', $namespace) . '\\';
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Extension' . preg_quote('\\') . '#', '\\Fraym\\Extension\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Test' . preg_quote('\\') . '#', '\\Fraym\\Test\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Hook' . preg_quote('\\') . '#', '\\Fraym\\Hook\\', $namespace);
         $class = $namespace . $classname;
         if (is_file($file)) {
             require_once $file;
             if (class_exists($class)) {
                 $this->initClassAnnotationRoutes($class);
                 foreach (get_class_methods($class) as $method) {
                     $key = null;
                     $refMethod = new \ReflectionMethod($class, $method);
                     $methodAnnotation = $this->db->getAnnotationReader()->getMethodAnnotation($refMethod, 'Fraym\\Annotation\\Route');
                     if (empty($methodAnnotation) === false) {
                         $route = $methodAnnotation->value;
                         $key = $methodAnnotation->name;
                         $regex = $methodAnnotation->regex;
                         $permission = $methodAnnotation->permission;
                         $callback = [$class, $method];
                         $contextCallback = null;
                         $this->addVirtualRoute($key, $route, $callback, $contextCallback, $regex, $permission);
                     }
                 }
             }
         }
     }
 }