Beispiel #1
0
 /**
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return void
  * @throws \Exception
  */
 public function linkUrls(Url $oldUrl, Url $newUrl)
 {
     if ($oldUrl->getId() === null or $newUrl->getId() === null) {
         throw new UrlNotPersistedException();
     }
     try {
         $this->em->beginTransaction();
         $alreadyRedirectedUrls = $this->findByActualUrl($oldUrl->getId());
         /** @var Url $url */
         foreach ($alreadyRedirectedUrls as $url) {
             $url->setRedirectTo($newUrl);
             $this->em->persist($url);
             $this->cache->clean([Cache::TAGS => [$url->getCacheKey()]]);
         }
         $oldUrl->setRedirectTo($newUrl);
         $this->em->persist($oldUrl);
         $this->cache->clean([Cache::TAGS => [$oldUrl->getCacheKey()]]);
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
Beispiel #2
0
 /**
  * @param $urlPath
  * @param $presenter
  * @param $action
  * @param null $internal_id
  * @return Url
  */
 public static function create($urlPath, $presenter, $action, $internal_id = null)
 {
     $url = new Url();
     $url->setUrlPath($urlPath);
     $url->setDestination($presenter, $action);
     $url->setInternalId($internal_id);
     return $url;
 }
Beispiel #3
0
 /**
  * @param Url $url
  * @param array $params
  * @param string $direction
  */
 private function convert(Url $url, array &$params, $direction)
 {
     if (empty($this->mappings)) {
         return;
     }
     if (isset($this->mappings[$url->getPresenter()][$url->getAction()])) {
         foreach ($this->mappings[$url->getPresenter()][$url->getAction()][$direction] as $from => $to) {
             if (isset($params[$from])) {
                 $params[$to] = $params[$from];
                 unset($params[$from]);
             }
         }
     }
 }
Beispiel #4
0
 public function testReadmeExamples()
 {
     $url = new Url();
     $url->setScheme('https://')->setHost('www.reddit.com')->setPath('/r/programming');
     $this->assertEquals('https://www.reddit.com/r/programming', (string) $url);
     $url = new Url('http://example.com?x=0&a=1&b=2');
     $this->assertEquals(array('a' => 1, 'b' => 2, 'x' => 0), $url->getQuery());
     $this->assertEquals('a=1&b=2&x=0', $url->getQueryStr());
     $url = new Url('http://example.com');
     $this->assertEquals('http://example.com', (string) $url);
     $url = new Url('http://example.com/');
     $this->assertEquals('http://example.com/', (string) $url);
     $url = new Url('http://example.com');
     $url->setPath('/');
     $this->assertEquals('http://example.com/', (string) $url);
 }
Beispiel #5
0
 public function getCurrentUrlId()
 {
     if (!isset($this->actualUrlToRedirect)) {
         return $this->getId();
     }
     return $this->actualUrlToRedirect->getId();
 }
Beispiel #6
0
 function set_dependencies(array $controllers)
 {
     $dir_controller = \Url\Url::GetRootUrl("Controllers", true);
     foreach ($controllers as $values) {
         $depend = $dir_controller . $values . ".php";
         if (file_exists($depend)) {
             include $depend;
         }
     }
 }
Beispiel #7
0
 /**
  * @param Url $url
  * @return Url
  * @throws UrlAlreadyExistsException
  * @throws \Exception
  */
 public function save(Url $url)
 {
     try {
         $this->em->beginTransaction();
         if ($url->getId() !== null) {
             $url = $this->update($url);
         } else {
             $url = $this->create($url);
         }
         $this->em->commit();
     } catch (UrlAlreadyExistsException $uae) {
         $this->closeEntityManager();
         $this->logger->addError(sprintf('Url path already exists: %s', $uae));
         throw $uae;
     } catch (\Exception $e) {
         $this->closeEntityManager();
         $this->logger->addError(sprintf('Url Entity saving failure: %s', $e));
         throw $e;
     }
     return $url;
 }
Beispiel #8
0
 /**
  * @author Rolando Antonio Arriaza
  * @todo Constructor de la clase mysqlconection
  * @version 1.3
  * @param Array $conect_dsn Conecta un dsn nuevo fuera del la conexion principal
  * @param string $directory directorio del config (Option en vez del $conect_dsn)
  * @since 1.1
  */
 public function __construct()
 {
     global $CONFIG_;
     $this->dsn = $CONFIG_["DB_MYSQL"]["driver"] . ':host=' . $CONFIG_["DB_MYSQL"]["host"] . ';dbname=' . $CONFIG_["DB_MYSQL"]["database"] . ';port=' . $CONFIG_["DB_MYSQL"]["port"];
     try {
         parent::__construct($this->dsn, $CONFIG_["DB_MYSQL"]["user"], $CONFIG_["DB_MYSQL"]["password"]);
         parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $ex) {
         $header = new \Http\Header();
         if ($ex->getMessage() == "could not find driver") {
             $header->redirect(\Url\Url::GetContentUrl("web/admin/error/database/index.php?err=0"));
         } else {
             $header->redirect(\Url\Url::GetContentUrl("web/admin/error/database/index.php?err=1"));
         }
     }
 }
Beispiel #9
0
 public static function GetUrl($link, $mask_state = TRUE)
 {
     return \Url\Url::GetUrl($link, $mask_state);
 }
Beispiel #10
0
 /**
  * @param string $urlAddress
  * @return Url
  */
 private function createUrl($urlAddress)
 {
     $url = new Url();
     $url->setDestination(Page::PRESENTER, Page::PRESENTER_ACTION);
     $url->setUrlPath($urlAddress);
     return $url;
 }
Beispiel #11
0
 /**
  * @return string
  */
 public function getUrlPath()
 {
     return $this->url->getCurrentUrlPath();
 }
Beispiel #12
0
 public function testRawUrlEncode()
 {
     $url = new Url();
     $rawEncode = rawurlencode($this->url);
     $this->assertEquals($rawEncode, $url->rawUrlEncode($this->url));
 }