/**
  * Uses the static method approach if our DI var is null
  *
  * @return Object
  * @author Dan Cox
  */
 public function __get($service)
 {
     if (is_null($this->DI)) {
         return DI::get($service);
     }
     return $this->DI->get($service);
 }
Example #2
0
 function display($tpl = null)
 {
     $this->state = $this->get('State');
     $this->form = $this->get('Form');
     //check if user access level allows view
     $user = JFactory::getUser();
     $groups = $user->getAuthorisedViewLevels();
     $access = isset($this->form->frontendaccess) && in_array($this->form->frontendaccess, $groups) ? true : false;
     if ($access == false) {
         JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return;
     }
     // get params from menu
     $this->menu_params = $this->state->get('params');
     if ($this->menu_params['menu-meta_description']) {
         $this->document->setDescription($this->menu_params['menu-meta_description']);
     }
     if ($this->menu_params['menu-meta_keywords']) {
         $this->document->setMetadata('keywords', $this->menu_params['menu-meta_keywords']);
     }
     //get Item id d
     $this->itemid = $this->state->get('itemid', '0');
     //get form id
     $this->id = JFactory::getApplication()->input->getInt('id', -1);
     if ($this->_layout == "detail") {
         // Get data from the model
         $this->item = $this->get('Detail');
     }
     // Get data from the model
     $this->form = $this->get('Form');
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     $this->fields = $this->get('Datafields');
     parent::display($tpl);
 }
Example #3
0
 /**
  * Display the toolbar.
  *
  * @return  void
  *
  * @since   2.5
  */
 protected function addToolbar()
 {
     Request::setVar('hidemainmenu', 1);
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == User::get('id'));
     $canDo = UsersHelper::getActions($this->state->get('filter.category_id'), $this->item->id);
     Toolbar::title(Lang::txt('COM_USERS_NOTES'), 'user');
     // If not checked out, can save the item.
     if (!$checkedOut && ($canDo->get('core.edit') || count(User::getAuthorisedCategories('com_users', 'core.create')))) {
         Toolbar::apply('note.apply');
         Toolbar::save('note.save');
     }
     if (!$checkedOut && count(User::getAuthorisedCategories('com_users', 'core.create'))) {
         Toolbar::save2new('note.save2new');
     }
     // If an existing item, can save to a copy.
     if (!$isNew && count(User::getAuthorisedCategories('com_users', 'core.create')) > 0) {
         Toolbar::save2copy('note.save2copy');
     }
     if (empty($this->item->id)) {
         Toolbar::cancel('note.cancel');
     } else {
         Toolbar::cancel('note.cancel', 'JTOOLBAR_CLOSE');
     }
     Toolbar::divider();
     Toolbar::help('note');
 }
Example #4
0
 /**
  * Test that the collection returns all on a NULL name
  *
  * @return void
  * @author Dan Cox
  */
 public function test_returnAllOnNullName()
 {
     $collections = $this->collection->get();
     $this->assertTrue(array_key_exists('question', $collections));
     $this->assertTrue(array_key_exists('comment', $collections));
     $this->assertTrue(array_key_exists('error', $collections));
 }
Example #5
0
 /**
  * Returns a service, if a mock is specified for it, it will return the mock instead
  *
  * @return Object
  * @author Dan Cox
  */
 public static function get($service)
 {
     if (array_key_exists($service, static::$mocks)) {
         return static::$mocks[$service];
     }
     return static::$container->get($service);
 }
 /**
  * @see	\herosphp\session\interfaces\ISession::read().
  */
 public static function read($sessionId)
 {
     if (self::$handler == NULL) {
         return '';
     }
     $data = self::$handler->get($sessionId);
     return $data;
 }
Example #7
0
 /**
  * Set up the helper class
  *
  * @return void
  */
 public function __construct($di = null)
 {
     if (!is_null($di)) {
         $this->di = $di;
         $this->output = $this->di->get('output');
         $this->input = $this->di->get('input');
     }
 }
 /**
  * 获得缓存数据
  * @param string $sid
  * @return void
  */
 function read($sid)
 {
     $m_data = $this->memcache->get($sid);
     if (!isset($m_data['card'])) {
         return array();
     }
     return $m_data['card'] === $this->card ? $m_data['Data'] : array();
 }
Example #9
0
 /**
  * Register the compiler pass and compile the DI
  *
  * @return void
  * @author Dan Cox
  */
 public function test_compileAndRegister()
 {
     $mock = new ServiceMockery('service');
     $mock->add();
     $this->DI->addCompilerPass(new MockeryPass());
     $this->DI->compile();
     $this->DI->get('service')->shouldReceive('test')->andReturn(true);
     $this->assertTrue($this->DI->get('service')->test());
 }
Example #10
0
 /**
  * 获得缓存数据
  * @param string $sid
  * @return void
  */
 function read($sid)
 {
     $data = $this->redis->get($sid);
     if ($data) {
         $values = explode("|#|", $data);
         return $values[0] === $this->card ? $values[1] : '';
     }
     return $data;
 }
Example #11
0
 /**
  * Test that when loading an existing mask, it overwrites current values
  *
  * @return void
  * @author Dan Cox
  */
 public function test_replacementOfMaskValue()
 {
     // Add a single mask
     $this->masks->addMask('test', 'value');
     // Replace this by adding a single mask with the same name
     $this->masks->addMask('test', 'different');
     $this->assertEquals('different', $this->masks->get('test'));
     // Replace this again by adding an array
     $this->masks->addMasks(array('test' => 'foo'));
     $this->assertEquals('foo', $this->masks->get('test'));
 }
Example #12
0
 /**
  * 获取数据
  * 
  * @param String $key 键值
  * @return Mixed
  */
 public function get($key)
 {
     $val = $this->mObject->get($key);
     $unserialize_val = unserialize($val);
     if (is_array($unserialize_val)) {
         return $unserialize_val;
     } else {
         return $val;
     }
     return $val;
 }
Example #13
0
 /**
  * Checks a string for format codes and replaces it with its background/foreground color codes
  *
  * @return String
  */
 public static function format($str)
 {
     preg_match('/<[A-Za-z0-9]+?>/', $str, $matches);
     foreach ($matches as $match) {
         $keyword = str_replace(array('<', '>'), '', $match);
         $format = static::$collection->get(strtolower($keyword));
         if (!empty($format)) {
             $foreground = !isset($format['foreground']) ? '' : "[" . $format['foreground'] . "m";
             $background = !isset($format['background']) ? '' : "[" . $format['background'] . "m";
             $str = str_replace(array('<' . $keyword . '>', '</' . $keyword . '>'), array($foreground . $background, ""), $str);
         }
     }
     return $str;
 }
Example #14
0
 /**
  * 從MD5取得檔案路徑
  * 
  * @param Object $f3
  * @param String $md5
  * @return string
  * @author Pulipuli Chen <*****@*****.**>
  * @version 20140908
  */
 public static function get_tmp_dir_path($f3, $md5)
 {
     $path1 = substr($md5, 0, 2);
     $path2 = substr($md5, 2, 2);
     if ($f3->get("DEBUG.use_sys_tmp") === TRUE) {
         $file_dir = sys_get_temp_dir() . "/";
     } else {
         $file_dir = $f3->get("UPLOADS") . "tmp/";
     }
     $file_dir .= "PFH/" . $path1 . "/" . $path2 . "/";
     if (is_dir($file_dir) === FALSE) {
         mkdir($file_dir, 0700, true);
     }
     return $file_dir;
 }
Example #15
0
 /**
  * 获得缓存数据
  * @access public
  * @param string $name  缓存KEY
  * @return boolean
  */
 public function get($name, $ctime = null)
 {
     //缓存KEY
     $name = $this->options['prefix'] . $name;
     $data = $this->memcacheObj->get($name);
     return $data !== false ? $data : NULL;
 }
Example #16
0
 /**
  * Funcion para procesar la respuesta de PayU
  * 
  * la peticion es recibida a traves de GET
  * 
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @return boolean|string retorna el codigo de la transaccion si fue exitosa, false en otro caso
  */
 public function processResponse($request)
 {
     $response = $request->query->all();
     $amount = $this->amountFormat($response['TX_VALUE']);
     $signature = $this->generateSignature($response['referenceCode'], $amount, $response['merchantId'], $response['transactionState']);
     $responseSignature = $response['signature'];
     $trans = $this->serv_cont->get('translator');
     $message = '
         <table class="table">
             <tbody>
                 <tr><td>' . $trans->trans("descripcion.transaccion") . '</td><td>' . $response['description'] . '</td></tr>
                 <tr><td>' . $trans->trans("estado.transaccion") . '</td><td>' . $response['message'] . '</td></tr>
                 <tr><td>' . $trans->trans("metodo.transaccion") . '</td><td>' . $response['lapPaymentMethod'] . '</td></tr>
                 <tr><td>' . $trans->trans("valor.transaccion") . '</td><td>$ ' . $amount . '</td></tr>
             </tbody>
         </table>
     ';
     if ($signature == $responseSignature) {
         if ($response['transactionState'] == 4 && $response['polResponseCode'] == 1) {
             return array('status' => 'success', 'message' => $message, 'referenceCode' => $response['referenceCode']);
         } else {
             return array('status' => 'error', 'message' => $message, 'referenceCode' => $response['referenceCode']);
         }
     } else {
         return array('status' => 'error', 'message' => $trans->trans("validacion.transaccion.invalida"), 'referenceCode' => $response['referenceCode']);
     }
 }
Example #17
0
 /**
  * Display the toolbar.
  *
  * @return  void
  *
  * @since   2.5
  */
 protected function addToolbar()
 {
     $canDo = UsersHelper::getActions();
     Toolbar::title(Lang::txt('COM_USERS_VIEW_NOTES_TITLE'), 'user');
     if ($canDo->get('core.create')) {
         Toolbar::addNew('note.add');
     }
     if ($canDo->get('core.edit')) {
         Toolbar::editList('note.edit');
     }
     if ($canDo->get('core.edit.state')) {
         Toolbar::divider();
         Toolbar::publish('notes.publish', 'JTOOLBAR_PUBLISH', true);
         Toolbar::unpublish('notes.unpublish', 'JTOOLBAR_UNPUBLISH', true);
         Toolbar::divider();
         Toolbar::archiveList('notes.archive');
         Toolbar::checkin('notes.checkin');
     }
     if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
         Toolbar::deleteList('', 'notes.delete', 'JTOOLBAR_EMPTY_TRASH');
         Toolbar::divider();
     } elseif ($canDo->get('core.edit.state')) {
         Toolbar::trash('notes.trash');
         Toolbar::divider();
     }
     if ($canDo->get('core.admin')) {
         Toolbar::preferences('com_users');
         Toolbar::divider();
     }
     Toolbar::help('notes');
 }
Example #18
0
 /**
  * Read from stream
  *
  * @param Integer $count
  * @return Mixed
  * @access public
  */
 function _stream_read($count)
 {
     switch ($this->mode) {
         case 'w':
         case 'a':
         case 'x':
         case 'c':
             return false;
     }
     // commented out because some files - eg. /dev/urandom - will say their size is 0 when in fact it's kinda infinite
     //if ($this->pos >= $this->size) {
     //    $this->eof = true;
     //    return false;
     //}
     $result = $this->sftp->get($this->path, false, $this->pos, $count);
     if (isset($this->notification) && is_callable($this->notification)) {
         if ($result === false) {
             call_user_func($this->notification, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_SEVERITY_ERR, $this->sftp->getLastSFTPError(), NET_SFTP_OPEN, 0, 0);
             return 0;
         }
         // seems that PHP calls stream_read in 8k chunks
         call_user_func($this->notification, STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, strlen($result), $this->size);
     }
     if (empty($result)) {
         // ie. false or empty string
         $this->eof = true;
         return false;
     }
     $this->pos += strlen($result);
     return $result;
 }
Example #19
0
 /**
  * Evaluate request uri
  *
  * @param string $requestUri Request uri
  * @param string $requestMethod Request method
  */
 public function validate(string $requestUri, string $requestMethod) : bool
 {
     //check if route is already cached
     if (($cachedRoute = $this->cache->get($requestUri)) !== false) {
         //get cached route
         $this->route = $cachedRoute;
         return true;
     }
     //if route not cached, validate, if valid cache it
     if (parent::validate($requestUri, $requestMethod)) {
     }
     //cache validated route
     $this->cache->set($requestUri, $this->route);
     return true;
     return false;
 }
Example #20
0
 /**
  * Invoke a target
  *
  * @param   xp.codegen.AbstractGenerator generator
  * @param   lang.reflect.Method method
  * @param   util.collections.HashTable targets
  * @return  var result
  */
 protected static function invoke(AbstractGenerator $generator, Method $method, Object $targets)
 {
     $target = $targets->get($method);
     if ($target->containsKey('result')) {
         return $target['result'][0];
     }
     Console::writeLine('---> Target ', $method->getName(), ': ');
     // Execute dependencies
     if ($target->containsKey('depends')) {
         foreach ($target->get('depends') as $depends) {
             self::invoke($generator, $depends, $targets);
         }
     }
     // Retrieve arguments
     $arguments = array();
     if ($target->containsKey('arguments')) {
         foreach ($target->get('arguments') as $argument) {
             $arguments[] = self::invoke($generator, $argument, $targets);
         }
     }
     // Execute target itself
     $result = $method->invoke($generator, $arguments);
     $target['result'] = new ArrayList($result);
     Console::writeLine(NULL === $result ? '<ok>' : xp::typeOf($result));
     return $result;
 }
Example #21
0
 function get($key)
 {
     if (is_float($key)) {
         if ((double) (int) $key === $key && $key >= 0) {
             return $this->callMethod('charAt', $key);
         }
     }
     return parent::get($key);
 }
Example #22
0
 /**
  * 
  * Render print button/text HTML
  * 
  * @param Object $article
  * @param Object $params
  */
 static function print_screen($article, $params)
 {
     if ($params->get('show_icons')) {
         $text = JHtml::_('image', 'system/printButton.png', JText::_('JGLOBAL_PRINT'), NULL, true);
     } else {
         $text = JText::_('JGLOBAL_PRINT');
     }
     return '<a >' . $text . '</a>';
 }
Example #23
0
 /**
  * Runs the commands given
  *
  * @return void
  * @author Dan Cox
  */
 public function runProcess($command)
 {
     $args = explode(' ', $this->DI->get('mask')->replace($command));
     $p = $this->hasDefinition($args);
     if (!$p) {
         $process = $this->DI->get('skeletonprocess');
         $process->build(['directory' => $this->input->getArgument('directory'), 'verbose' => $this->input->getOption('output') ? TRUE : FALSE]);
         $p = $process->setArguments($args)->getProcess();
     }
     try {
         $p->mustRun();
         $cmd = $p->getCommandLine();
     } catch (\Exception $e) {
         $this->output->writeln($e->getMessage());
         return false;
     }
     $this->output->writeln("Successfully ran command: {$cmd}");
     return true;
 }
 /**
  * Fetch posts from WordPress
  * @return self
  */
 public function fetch($number = 25)
 {
     if (!$this->valid()) {
         $this->posts = array();
         return $this;
     }
     if (!$this->check_cache()) {
         $options = array('screen_name' => $this->settings->username, 'count' => $number);
         $this->connection = new TwitterOAuth($this->settings->consumer_key, $this->settings->consumer_secret, $this->settings->access_token, $this->settings->access_secret);
         $result = $this->connection->get('statuses/user_timeline', $options);
         if (isset($result['errors'])) {
             $this->posts = array();
         } else {
             $this->posts = $result;
             $this->write_cache();
         }
     }
     return $this;
 }
Example #25
0
 /**
  * 取得現在的網址
  * 
  * 相關參數:http://fatfreeframework.com/quick-reference#body
  * 
  * @param Object $f3
  * @param string $route 要處理的路徑
  * @return string
  */
 static function get_base_url($f3, $route = NULL)
 {
     $protocol = $f3->get("SCHEME");
     //$host = $_SERVER["HTTP_HOST"];
     $host = $f3->get("HOST");
     $port = $f3->get("PORT");
     $uri = $f3->get("BASE");
     $url = $protocol . "://" . $host;
     if (isset($port) && $port !== "" && $port !== "80" && $port !== 80) {
         $url = $url . ":" . $port;
     }
     $url = $url . $uri;
     if (is_string($route)) {
         if (substr($route, 0, 1) !== "/") {
             $route = "/" . $route;
         }
         $url = $url . $route;
     }
     return $url;
 }
Example #26
0
 public function testSynchronizationWithFullEmptyPoints()
 {
     $T = new Object(array(Object::LATITUDES => array(0.0, 0.0, 0.0, 0.0), Object::LONGITUDES => array(0.0, 0.0, 0.0, 0.0)));
     $T->synchronize();
     $this->assertEquals(null, $T->get(Object::STARTPOINT_LATITUDE));
     $this->assertEquals(null, $T->get(Object::STARTPOINT_LONGITUDE));
     $this->assertEquals(null, $T->get(Object::ENDPOINT_LATITUDE));
     $this->assertEquals(null, $T->get(Object::ENDPOINT_LONGITUDE));
     $this->assertEquals(null, $T->get(Object::MIN_LATITUDE));
     $this->assertEquals(null, $T->get(Object::MIN_LONGITUDE));
     $this->assertEquals(null, $T->get(Object::MAX_LATITUDE));
     $this->assertEquals(null, $T->get(Object::MAX_LONGITUDE));
 }
Example #27
0
 /**
  * Get the last redirect from a url
  *
  * @param  string $url []
  *
  * @return Response object
  */
 public function getEffectiveUrl($url)
 {
     $stack = HandlerStack::create();
     $stack->push(EffectiveUrlMiddleware::middleware());
     $response = $this->client->get($url, ['handler' => $stack, 'http_errors' => false, 'on_headers' => function (\Psr\Http\Message\ResponseInterface $response) {
         if (strpos($response->getHeaderLine('Content-Type'), 'text/html') === false) {
             throw new HtmlContentTypeException();
         }
     }]);
     return $response;
 }
Example #28
0
 /**
  * Test adding a few mocks and clearing them all
  *
  * @return void
  * @author Dan Cox
  */
 public function test_addClearAll()
 {
     $this->DI->addMock('test', array());
     $this->DI->addMock('mock', array());
     $this->assertEquals(array(), $this->DI->get('test'));
     $this->assertEquals(array(), $this->DI->get('mock'));
     $this->DI->clearMocks();
     $this->setExpectedException("Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException");
     // No mocks should be available now
     $this->assertNull($this->DI->get('mock'));
 }
Example #29
0
 /**
  * Sorts out options into correct orders
  *
  * @return void
  */
 public function sortOptions()
 {
     $options = array();
     $expectedOptions = $this->di->get('option')->getExpectedOrder();
     foreach ($expectedOptions as $pos => $key) {
         if (array_key_exists($pos, $this->options)) {
             $options[$key] = $this->di->get('option')->validate($key, $this->options[$pos]);
         } else {
             $this->di->get('option')->validate($key, null);
         }
     }
     $this->di->get('option')->load($options);
 }
Example #30
0
 /**
  * Find all
  *
  * @return object/NULL
  */
 public function findAll()
 {
     if ($this->object) {
         $this->db->where($this->getData());
     }
     if ($result = $this->db->get($this->table)->result()) {
         foreach ($result as &$element) {
             event('Db_ORM.findAll', $this, $result);
             $this->cache($element->{$this->primary}, $element);
             $element = $this->filterData($element, self::FILTER_OUT);
         }
         $this->clear();
     }
     return $result;
 }