Exemplo n.º 1
0
 /**
  * Trigger a visitor action
  *
  * @param        $companyFid
  * @param        $actionKey
  * @param        $transactionId
  * @param int    $transactionValue
  * @param array  $data
  * @param null   $couponCode
  * @param bool   $returnPixels
  * @param string $userReference
  * @param string $campaignHash
  * @param string $sid1
  * @param string $sid2
  * @param string $sid3
  *
  * @return PostActionResponse
  */
 public function triggerAction($companyFid, $actionKey, $transactionId, $transactionValue = 0, array $data = null, $couponCode = null, $returnPixels = true, $userReference = null, $campaignHash = null, $sid1 = null, $sid2 = null, $sid3 = null)
 {
     $endpoint = AffiliateActionEndpoint::bound($this->_getApi());
     $payload = new PostActionPayload();
     $payload->userAgent = $this->_fortifi->getUserAgent();
     $payload->language = $this->_fortifi->getUserLanguage();
     $payload->clientIp = $this->_fortifi->getClientIp();
     $payload->encoding = $this->_fortifi->getUserEncoding();
     $payload->companyFid = $companyFid;
     $payload->actionKey = $actionKey;
     $payload->transactionId = $transactionId;
     $payload->transactionValue = $transactionValue;
     $payload->coupon = $couponCode;
     $payload->data = $data;
     $payload->returnPixels = $returnPixels;
     $payload->visitorId = $this->_visitorId;
     $payload->userReference = ValueAs::nonempty($userReference, $this->_alias);
     $payload->campaignHash = $campaignHash;
     $payload->sid1 = $sid1;
     $payload->sid2 = $sid2;
     $payload->sid3 = $sid3;
     $req = $endpoint->post($payload);
     $result = $this->_processRequest($req);
     if ($returnPixels) {
         /**
          * @var $result PostActionResponse
          */
         $this->_pixels = $result->pixels;
     }
     return $result;
 }
Exemplo n.º 2
0
 public function testCoalesce()
 {
     $this->assertEquals('zebra', ValueAs::coalesce(null, 'zebra'));
     $this->assertEquals(null, ValueAs::coalesce());
     $this->assertEquals(false, ValueAs::coalesce(false, null));
     $this->assertEquals(false, ValueAs::coalesce(null, false));
 }
Exemplo n.º 3
0
 public function __toString()
 {
     $prefix = null;
     if ($this->protocol || $this->domain || $this->port) {
         $protocol = ValueAs::nonempty($this->protocol, 'http');
         $auth = '';
         if (strlen($this->user) && strlen($this->pass)) {
             $auth = SafeHtml::escapeUri($this->user) . ':' . SafeHtml::escapeUri($this->pass) . '@';
         } else {
             if (strlen($this->user)) {
                 $auth = SafeHtml::escapeUri($this->user) . '@';
             }
         }
         if ($protocol != 'javascript') {
             $prefix = $protocol . '://' . $auth . $this->domain;
         } else {
             $prefix = $protocol . ':';
         }
         if ($this->port) {
             $prefix .= ':' . $this->port;
         }
     }
     if ($this->query) {
         $query = '?' . http_build_query($this->query);
     } else {
         $query = null;
     }
     if (strlen($this->getFragment())) {
         $fragment = '#' . $this->getFragment();
     } else {
         $fragment = null;
     }
     return $prefix . $this->getPath() . $query . $fragment;
 }
Exemplo n.º 4
0
 /**
  * Create a new customer (and trigger a lead)
  *
  * @param string $companyFid
  * @param string $email
  * @param string $firstName
  * @param string $lastName
  * @param string $phoneNumber
  * @param string $reference                   Your internal ID for this
  *                                            customer (e.g. user id)
  * @param string $accountType
  * @param int    $createdTime
  * @param bool   $isImport
  *
  * @return $this
  */
 public function create($companyFid, $email, $firstName, $lastName = null, $phoneNumber = null, $reference = null, $accountType = CustomerAccountType::RESIDENTIAL, $createdTime = null, $isImport = false)
 {
     $exRef = ValueAs::nonempty($reference, $this->_externalReference);
     $createCustomerPayload = new CreateCustomerPayload();
     $createCustomerPayload->externalReference = $exRef;
     $createCustomerPayload->companyFid = $companyFid;
     $createCustomerPayload->email = $email;
     $createCustomerPayload->firstName = $firstName;
     $createCustomerPayload->lastName = $lastName;
     $createCustomerPayload->accountType = $accountType;
     $createCustomerPayload->createdTime = $createdTime;
     $createCustomerPayload->isImport = $isImport;
     $customerEp = $this->_getEndpoint();
     $req = $customerEp->createProspect($createCustomerPayload);
     $customer = $this->_processRequest($req);
     $this->_customerFid = $customer->fid;
     if (!empty($phoneNumber)) {
         try {
             $this->addPhoneNumber($phoneNumber, true);
         } catch (\Exception $e) {
         }
     }
     try {
         $locationPayload = new CustomerSetLocationPayload();
         $locationPayload->fid = $this->_customerFid;
         $locationPayload->userIp = $this->_fortifi->getClientIp();
         $this->_processRequest($this->_getEndpoint()->setLocation($locationPayload));
     } catch (\Exception $e) {
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Open the connection
  *
  * @return static
  *
  * @throws ConnectionException
  */
 public function connect()
 {
     if ($this->_client === null) {
         $remainingAttempts = (int) $this->_config()->getItem('connect_attempts', 1);
         while ($remainingAttempts > 0) {
             $remainingAttempts--;
             $exception = null;
             try {
                 if (empty($this->_availableHosts)) {
                     $this->_availableHosts = ValueAs::arr($this->_config()->getItem('hosts', 'localhost'));
                     $this->_availableHostCount = count($this->_availableHosts);
                     if ($this->_availableHostCount < 1) {
                         throw new ConnectionException('Could not find any configured hosts');
                     }
                 }
                 shuffle($this->_availableHosts);
                 $host = reset($this->_availableHosts);
                 $this->_socket = new DalSocket($host, (int) $this->_config()->getItem('port', 9160), ValueAs::bool($this->_config()->getItem('persist', false)));
                 $this->_socket->setConnectTimeout((int) $this->_config()->getItem('connect_timeout', 1000));
                 $this->_socket->setRecvTimeout((int) $this->_config()->getItem('receive_timeout', 1000));
                 $this->_socket->setSendTimeout((int) $this->_config()->getItem('send_timeout', 1000));
                 $this->_transport = new TFramedTransport($this->_socket);
                 $this->_protocol = new TBinaryProtocolAccelerated($this->_transport);
                 $this->_client = new CassandraClient($this->_protocol);
                 $this->_transport->open();
                 $this->_connected = true;
                 $this->_clearStmtCache();
                 $username = $this->_config()->getItem('username');
                 // @codeCoverageIgnoreStart
                 if ($username) {
                     $this->_client->login(new AuthenticationRequest(['credentials' => ['username' => $username, 'password' => $this->_config()->getItem('password', '')]]));
                 }
                 //@codeCoverageIgnoreEnd
                 $this->_switchDatabase(null, !$this->_socket->isPersistent());
             } catch (TException $e) {
                 $exception = $e;
             } catch (CqlException $e) {
                 $exception = $e;
             }
             if ($exception) {
                 $this->_removeCurrentHost();
                 $this->disconnect();
                 if ($remainingAttempts < 1) {
                     if (!$exception instanceof CqlException) {
                         $exception = CqlException::from($exception);
                     }
                     throw new ConnectionException('Failed to connect: ' . $exception->getMessage(), $exception->getCode(), $exception->getPrevious());
                 }
             } else {
                 break;
             }
         }
     }
     return $this;
 }
 protected function _dataNodeLink($property, $subProperty = null, $displayName = null)
 {
     $fid = $this->{$property . 'Fid'};
     $response = $this->{$property};
     if ($subProperty) {
         $fid = $response->{$subProperty . 'Fid'};
         $response = $response->{$subProperty};
     }
     $text = ValueAs::nonempty($displayName, Objects::property($response, 'displayName'), $fid);
     return '"{' . $text . '[' . $fid . ']}"';
 }
Exemplo n.º 7
0
 public function configure(ConfigSectionInterface $config)
 {
     $this->_config = $config;
     $mode = $config->getItem('mode', 'reader');
     if ($mode == 'reader') {
         $this->_reader = new Reader($config->getItem('database', new \Exception('No GeoIP Database defined')));
     } else {
         if ($mode == 'client') {
             $this->_reader = new Client($config->getItem('user_id', new \Exception("No maxmind user id specified")), $config->getItem('licence_key', new \Exception("No maxmind licence key specified")), ValueAs::arr($config->getItem('locales', 'en')), $config->getItem('host', 'geoip.maxmind.com'));
         }
     }
 }
Exemplo n.º 8
0
 /**
  * @param $resource
  *
  * @return ArrayHelper
  *
  * @throws \Exception
  */
 public static function create($resource)
 {
     if (is_object($resource)) {
         return new static((array) $resource);
     }
     if (is_array($resource)) {
         return new static($resource);
     }
     if (is_string($resource)) {
         return new static(ValueAs::arr($resource));
     }
     throw new \Exception(gettype($resource) . " is not currently supported");
 }
Exemplo n.º 9
0
 /**
  * Open the connection
  *
  * @return static
  *
  * @throws ConnectionException
  */
 public function connect()
 {
     $cfg = $this->_config();
     $this->_connection = $this->_newConnection();
     $servers = ValueAs::arr($cfg->getItem('servers', 'localhost'));
     foreach ($servers as $alias => $server) {
         $port = (int) $cfg->getItem($alias . '.port', $cfg->getItem('port', 11211));
         $persist = ValueAs::bool($cfg->getItem($alias . '.persist', $cfg->getItem('persist', true)));
         $weight = (int) $cfg->getItem($alias . '.weight', $cfg->getItem('weight', 1));
         $timeout = (int) $cfg->getItem($alias . '.timeout', $cfg->getItem('timeout', 1));
         $this->_addserver($server, $port, $persist, $weight, $timeout);
     }
     return $this;
 }
Exemplo n.º 10
0
 /**
  * Create a new customer (and trigger a lead)
  *
  * @param string $companyFid
  * @param string $email
  * @param string $firstName
  * @param string $lastName
  * @param string $phoneNumber
  * @param string $reference                   Your internal ID for this
  *                                            customer (e.g. user id)
  * @param string $accountType
  * @param string $accountStatus
  * @param string $subscriptionType
  * @param bool   $triggerLeadAction
  * @param int    $createdTime
  *
  * @return $this
  */
 public function create($companyFid, $email, $firstName, $lastName = null, $phoneNumber = null, $reference = null, $accountType = CustomerAccountType::RESIDENTIAL, $accountStatus = CustomerAccountStatus::ACTIVE, $subscriptionType = CustomerSubscriptionType::FREE, $triggerLeadAction = false, $createdTime = null)
 {
     $exRef = ValueAs::nonempty($reference, $this->_externalReference);
     $createCustomerPayload = new CreateCustomerPayload();
     $createCustomerPayload->externalReference = $exRef;
     $createCustomerPayload->companyFid = $companyFid;
     $createCustomerPayload->email = $email;
     $createCustomerPayload->firstName = $firstName;
     $createCustomerPayload->lastName = $lastName;
     $createCustomerPayload->accountType = $accountType;
     $createCustomerPayload->accountStatus = $accountStatus;
     $createCustomerPayload->subscriptionType = $subscriptionType;
     $createCustomerPayload->createdTime = $createdTime;
     $customerEp = $this->_getEndpoint();
     $req = $customerEp->createCustomer($createCustomerPayload);
     $customer = $this->_processRequest($req);
     $this->_customerFid = $customer->fid;
     if (!empty($phoneNumber)) {
         try {
             $this->addPhoneNumber($phoneNumber, true);
         } catch (\Exception $e) {
         }
     }
     if ($triggerLeadAction) {
         $trigger = $this->_fortifi->visitor($this->_visitorId)->triggerAction($companyFid, AffiliateBuiltInAction::LEAD, $reference, 0, ['customerFid' => $this->_customerFid, 'email' => $email, 'first_name' => $firstName, 'last_name' => $lastName, 'phone_number' => $phoneNumber, 'external_reference' => $exRef, 'accountType' => $accountType, 'accountStatus' => $accountStatus, 'subscriptionType' => $subscriptionType]);
         if (!empty($trigger->visitorId)) {
             $this->setVisitorId($trigger->visitorId);
         }
         $affPayload = new CustomerSetAffiliatePayload();
         $affPayload->affiliateFid = $trigger->affiliate;
         $affPayload->fid = $this->_customerFid;
         $affPayload->sid1 = $trigger->sid1;
         $affPayload->sid2 = $trigger->sid2;
         $affPayload->sid3 = $trigger->sid3;
         try {
             $this->_processRequest($this->_getEndpoint()->setAffiliate($affPayload));
         } catch (\Exception $e) {
         }
     }
     try {
         $locationPayload = new CustomerSetLocationPayload();
         $locationPayload->fid = $this->_customerFid;
         $locationPayload->userIp = $this->_fortifi->getClientIp();
         $this->_processRequest($this->_getEndpoint()->setLocation($locationPayload));
     } catch (\Exception $e) {
     }
     return $this;
 }
Exemplo n.º 11
0
 /**
  * @param AffiliatePolicyPayload       $payload
  * @param string                       $companyFid
  * @param string                       $resourceFid
  * @param string                       $campaignFid
  * @param string                       $sid1
  * @param string                       $sid2
  * @param string                       $sid3
  * @param string                       $action
  * @param string                       $country
  * @param string                       $platform
  * @param AffiliatePolicyRulePayload[] $rules
  * @param string                       $description
  *
  * @return FidResponse|FortifiApiRequestInterface
  */
 public function set(AffiliatePolicyPayload $payload, $companyFid = null, $resourceFid = null, $campaignFid = null, $sid1 = null, $sid2 = null, $sid3 = null, $action = null, $country = null, $platform = null, $rules = null, $description = null)
 {
     $payload->companyFid = ValueAs::nonempty($companyFid, $payload->companyFid);
     $payload->resourceFid = ValueAs::nonempty($resourceFid, $payload->resourceFid);
     $payload->campaignFid = ValueAs::nonempty($campaignFid, $payload->campaignFid);
     $payload->sid1 = ValueAs::nonempty($sid1, $payload->sid1);
     $payload->sid2 = ValueAs::nonempty($sid2, $payload->sid2);
     $payload->sid3 = ValueAs::nonempty($sid3, $payload->sid3);
     $payload->action = ValueAs::nonempty($action, $payload->action);
     $payload->country = ValueAs::nonempty($country, $payload->country);
     $payload->platform = ValueAs::nonempty($platform, $payload->platform);
     $payload->rules = ValueAs::nonempty($rules, $payload->rules);
     $payload->description = ValueAs::nonempty($description, $payload->description);
     $ep = AffiliatePolicyEndpoint::bound($this->getApi());
     return $ep->set($payload)->get();
 }
Exemplo n.º 12
0
 public function getContent()
 {
     $data = parent::getContent();
     //Return the raw content if minification has been disabled
     if (!ValueAs::bool($this->getOption('minify', true))) {
         return $data;
     }
     //Do not minify scripts containing the @do-not-minify
     if (strpos($data, '@' . 'do-not-minify') !== false) {
         return $data;
     }
     try {
         return Minifier::minify($data);
     } catch (\Exception $e) {
         return $data;
     }
 }
Exemplo n.º 13
0
 /**
  * Open the connection
  *
  * @return static
  *
  * @throws ConnectionException
  */
 public function connect()
 {
     if (!$this->isConnected()) {
         $this->_clearStmtCache();
         $this->_host = null;
         $this->_username = $this->_config()->getItem('username', 'root');
         $dsn = $this->_config()->getItem('dsn', null);
         if ($dsn === null) {
             $this->_host = $this->_config()->getItem('hostname', '127.0.0.1');
             $this->_port = $this->_config()->getItem('port', 3306);
             $dsn = sprintf("mysql:host=%s;port=%d", $this->_host, $this->_port);
         }
         $options = array_replace($this->_defaultOptions(), ValueAs::arr($this->_config()->getItem('options')));
         $remainingAttempts = (int) $this->_config()->getItem('connect_retries', 3);
         while ($remainingAttempts > 0 && $this->_connection === null) {
             try {
                 $cachedConnection = $this->_getCachedConnection();
                 if ($cachedConnection && $cachedConnection instanceof \PDO) {
                     $this->_connection = $cachedConnection;
                 } else {
                     $this->_connection = new \PDO($dsn, $this->_username, $this->_config()->getItem('password', ''), $options);
                 }
                 if (isset($options[\PDO::ATTR_EMULATE_PREPARES])) {
                     $this->_emulatedPrepares = $options[\PDO::ATTR_EMULATE_PREPARES];
                 } else {
                     $serverVersion = $this->_connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
                     $this->_emulatedPrepares = version_compare($serverVersion, '5.1.17', '<');
                     $this->_connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, $this->_emulatedPrepares);
                 }
                 $this->_storeCachedConnection($this->_connection);
                 $this->_switchDatabase(null, true);
                 $remainingAttempts = 0;
             } catch (\Exception $e) {
                 $remainingAttempts--;
                 $this->_connection = null;
                 if ($remainingAttempts > 0) {
                     usleep(mt_rand(1000, 5000));
                 } else {
                     throw new ConnectionException("Failed to connect to PDO: " . $e->getMessage(), $e->getCode(), $e);
                 }
             }
         }
         $this->_lastConnectTime = time();
     }
     return $this;
 }
Exemplo n.º 14
0
 /**
  * @inheritdoc
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|mixed|null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (ValueAs::bool($this->showfig)) {
         $output->write(Figlet::create('PHP WEB', 'ivrit'));
         $output->write(Figlet::create('SERVER', 'ivrit'));
     }
     $output->writeln("");
     $output->write("\tStarting on ");
     $output->write("http://");
     $output->write($this->host == '0.0.0.0' ? 'localhost' : $this->host);
     $output->write(':' . $this->port);
     $output->writeLn("");
     $projectRoot = trim($this->getCubex()->getProjectRoot());
     $projectRoot = $projectRoot ? '"' . $projectRoot . '"' : '';
     $command = ["php -S {$this->host}:{$this->port} -t"];
     $command[] = $projectRoot;
     $command[] = trim($this->router);
     $command = implode(' ', array_filter($command));
     $output->writeln(["", "\tRaw Command: {$command}", ""]);
     return $this->runCommand($command);
 }
Exemplo n.º 15
0
 public function getContent()
 {
     $data = parent::getContent();
     //Return the raw content if minification has been disabled
     if (!ValueAs::bool($this->getOption('minify', true))) {
         return $data;
     }
     //Do not minify scripts containing the @do-not-minify
     if (strpos($data, '@' . 'do-not-minify') !== false) {
         return $data;
     }
     // Remove comments.
     $data = preg_replace('@/\\*.*?\\*/@s', '', $data);
     // Remove whitespace around symbols.
     $data = preg_replace('@\\s*([{}:;,])\\s*@', '\\1', $data);
     // Remove unnecessary semicolons.
     $data = preg_replace('@;}@', '}', $data);
     // Replace #rrggbb with #rgb when possible.
     $data = preg_replace('@#([a-f0-9])\\1([a-f0-9])\\2([a-f0-9])\\3@i', '#\\1\\2\\3', $data);
     return trim($data);
 }
Exemplo n.º 16
0
 public function repairValue($tag, $property, $value, $options)
 {
     switch (strtolower($tag)) {
         case 'bool':
             $validBools = ['true', '1', 1, true, 'false', '0', 0, false];
             if (in_array($value, $validBools)) {
                 $value = ValueAs::bool($value);
             }
             break;
         case 'int':
             if (strlen((int) $value) == strlen($value)) {
                 $value = (int) $value;
             }
             break;
         case 'float':
             if ((double) $value == strlen($value)) {
                 $value = (double) $value;
             }
             break;
     }
     $this->_payload->{$property} = $value;
 }
Exemplo n.º 17
0
 public function removeClass($class)
 {
     if (func_num_args() === 1) {
         $classes = ValueAs::arr($class);
     } else {
         $classes = func_get_args();
     }
     foreach ($classes as $class) {
         if (is_array($class)) {
             foreach ($class as $c) {
                 $this->_removeClass($c);
             }
         } else {
             $this->_removeClass($class);
         }
     }
     return $this;
 }
Exemplo n.º 18
0
 /**
  * @param bool $bool
  *
  * @return $this
  */
 public function showAutoSubmitButton($bool)
 {
     $this->_showAutoSubmitButton = ValueAs::bool($bool);
     return $this;
 }
Exemplo n.º 19
0
 public function getDisplayText()
 {
     return ValueAs::nonempty($this->displayName, implode(' ', array_filter([$this->firstName, $this->lastName])), 'Employee');
 }
Exemplo n.º 20
0
 /**
  * Trigger a visitor action
  *
  * @param        $companyFid
  * @param        $actionKey
  * @param        $transactionId
  * @param Carbon $time,
  * @param int    $transactionValue
  * @param array  $data
  * @param null   $couponCode
  * @param bool   $returnPixels
  * @param string $userReference
  * @param string $campaignHash
  * @param string $sid1
  * @param string $sid2
  * @param string $sid3
  *
  * @return PostActionPayload
  */
 public function preparePayload($companyFid, $actionKey, $transactionId, Carbon $time, $transactionValue = 0, array $data = null, $couponCode = null, $returnPixels = true, $userReference = null, $campaignHash = null, $sid1 = null, $sid2 = null, $sid3 = null)
 {
     $payload = new PostActionPayload();
     $payload->userAgent = $this->_fortifi->getUserAgent();
     $payload->language = $this->_fortifi->getUserLanguage();
     $payload->clientIp = $this->_fortifi->getClientIp();
     $payload->encoding = $this->_fortifi->getUserEncoding();
     $payload->companyFid = $companyFid;
     $payload->actionKey = $actionKey;
     $payload->transactionId = $transactionId;
     $payload->timestamp = $time->getTimestamp();
     $payload->transactionValue = $transactionValue;
     $payload->coupon = $couponCode;
     $payload->data = $data;
     $payload->returnPixels = $returnPixels;
     $payload->visitorId = $this->_visitorId;
     $payload->userReference = ValueAs::nonempty($userReference, $this->_alias);
     $payload->campaignHash = $campaignHash;
     $payload->sid1 = $sid1;
     $payload->sid2 = $sid2;
     $payload->sid3 = $sid3;
     return $payload;
 }
Exemplo n.º 21
0
 /**
  * Is Dispatch responsible for the incoming request
  *
  * @param Request $request
  *
  * @return bool
  */
 public function isDispatchRequest(Request $request)
 {
     $runOn = $this->_config->getItem('run_on', 'path');
     switch ($runOn) {
         case 'path':
             $match = $this->_config->getItem('run_match', 'res');
             return Strings::startsWith($request->getPathInfo() . '/', "/{$match}/");
         case 'subdomain':
             $matchCfg = $this->_config->getItem('run_match', 'static.,assets.');
             $subDomains = ValueAs::arr($matchCfg, ['static.']);
             return Strings::startsWithAny($request->getHost(), $subDomains);
         case 'domain':
             $matchCfg = $this->_config->getItem('run_match', null);
             $domains = ValueAs::arr($matchCfg, []);
             return Strings::endsWithAny($request->getHttpHost(), $domains, false);
     }
     return false;
 }
Exemplo n.º 22
0
 /**
  * Convert an alias URL to the correct path
  *
  * @param $parts
  *
  * @return null|string
  */
 public function aliasPath($parts)
 {
     $check = $parts[1];
     $aliases = ValueAs::arr($this->_config->getItem('aliases'));
     if (isset($aliases[$check])) {
         return $aliases[$check];
     }
     return null;
 }
Exemplo n.º 23
0
 /**
  * Generate the URI for the provided details
  *
  * @param $type
  * @param $lookup
  * @param $domain
  * @param $path
  * @param $file
  *
  * @return null|string
  */
 public function generateUriPath($type, $lookup, $domain, $path, $file)
 {
     $parts = [];
     //Include the map type
     $parts[] = $type;
     //When lookup parts are avilable, e.g. vendor/package, include them
     if (is_array($lookup)) {
         foreach ($lookup as $lookupPart) {
             $parts[] = $lookupPart;
         }
     }
     $parts[] = static::hashDomain($domain);
     //If not path is available, assume you are requesting the base path
     if (empty($path)) {
         $partHash = 'b';
     } else {
         //Build the hashable path
         $partHash = $this->_mapper->hashDirectoryArray(ValueAs::arr(explode('/', $path)));
     }
     $parts[] = $partHash;
     $baseDir = $this->getBasePath($this->_mapper, $type, (array) $lookup);
     $filePath = Path::build($baseDir, $path, $file);
     $fileHash = $this->_dispatcher->getFileHash($filePath);
     if ($fileHash === null) {
         //File hash doesnt exist in the cache, so lets look it up
         $fullPath = Path::build($this->_dispatcher->getBaseDirectory(), $filePath);
         $fileHash = ResourceGenerator::getFileHash($fullPath);
         if (!$fileHash) {
             //If we cant get a hash of the file, its unlikely it exists
             return null;
         }
         //Cache the entry, to optimise should the same resource be re-requested
         $this->_dispatcher->addFileHashEntry($filePath, $fileHash);
     }
     $parts[] = substr($fileHash, 0, 7);
     //Include the file extension
     $parts[] = $file;
     return implode('/', $parts);
 }
Exemplo n.º 24
0
 /**
  * @return IAuthedUser
  */
 public function getAuthedUser()
 {
     if ($this->_authedUser !== null) {
         return $this->_authedUser;
     }
     //Check cookie
     $cookieUser = $this->getCookieUser(false);
     if ($cookieUser !== null) {
         $this->_authedUser = $cookieUser;
         return $this->_authedUser;
     }
     //Check auth provider retrieve
     $serviceUser = $this->_authProvider->retrieveUser();
     if ($serviceUser !== null) {
         $this->_authedUser = $serviceUser;
         //Set the login cookie when retrieved the user from the auth provider
         //Defaulted to on for speed, but can be disabled within the config
         if (ValueAs::bool($this->getCubex()->getConfiguration()->getItem('auth', 'cookie_retriever'), true)) {
             $this->_setLoginCookie($serviceUser);
         }
     }
     return $this->_authedUser;
 }
Exemplo n.º 25
0
 /**
  * @param string $useName  Use this as the key
  * @param string $useValue Use this as the value
  *
  * @return string
  */
 public function getReadableValue($useName = null, $useValue = null)
 {
     $useName = $useName ?: ucwords(Strings::humanize($this->key));
     $useValue = $useValue ?: $this->value;
     if (is_array($useValue)) {
         $useValue = implode(', ', ValueAs::arr($useValue));
     }
     $nonIsComparators = [AdvancedFilterComparator::STARTS_WITH, AdvancedFilterComparator::NOT_STARTS_WITH, AdvancedFilterComparator::ENDS_WITH, AdvancedFilterComparator::NOT_ENDS_WITH];
     if (!in_array($this->comparator, $nonIsComparators)) {
         $useName .= ' is';
     }
     if (in_array($this->comparator, [AdvancedFilterComparator::BETWEEN, AdvancedFilterComparator::NOT_BETWEEN])) {
         list($min, $max) = explode(',', $useValue);
         return $useName . ' between ' . trim($min) . ' and ' . trim($max);
     }
     if (is_bool($useValue)) {
         return $useName . ' ' . ($useValue ? 'true' : 'false');
     }
     return $useName . ' ' . AdvancedFilterComparator::getDisplayValue($this->comparator) . ' ' . $useValue;
 }
Exemplo n.º 26
0
 public function setDummyData()
 {
     $this->_daos = [];
     $this->_daos[1] = ValueAs::obj(['name' => 'Test', 'id' => 1]);
     $this->_daos[2] = ValueAs::obj(['name' => 'Test', 'id' => 2]);
     $user = new MockUsr();
     $user->name = 'User';
     $user->id = 5;
     $this->_daos[5] = $user;
     $mock = new MockAbstractDao();
     $mock->name = 'Testing';
     $mock->id = 8;
     $this->_daos[8] = $mock;
 }
Exemplo n.º 27
0
 /**
  * @param $data string Serialized representation of the authed user
  *
  * @throws \Exception
  *
  * @return IAuthedUser|self
  */
 public function unserialize($data)
 {
     $json = json_decode($data);
     if (json_last_error() === JSON_ERROR_NONE) {
         $this->_data = (array) $json;
         $this->_data['data'] = ValueAs::arr($this->_data['data'], []);
     } else {
         throw new \Exception('Unable to unserialize login cookie', json_last_error());
     }
     return $this;
 }
 /**
  * Hydrate the public properties
  *
  * @param $data
  */
 public function hydrate($data)
 {
     parent::hydrate($data);
     $this->values = ValueAs::arr($this->values);
 }
Exemplo n.º 29
0
 public function hydrate($data)
 {
     parent::hydrate($data);
     $this->result = ValueAs::arr($this->result);
 }
Exemplo n.º 30
0
 public static function generate($time = null)
 {
     return (ValueAs::nonempty($time, time()) << 32) + Arrays::first(unpack('L', Strings::randomString(4)));
 }