Exemplo n.º 1
2
 function jws_fetchUrl($url)
 {
     //Can we use cURL?
     if (is_callable('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         $feedData = curl_exec($ch);
         curl_close($ch);
         //If not then use file_get_contents
     } elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
         $feedData = @file_get_contents($url);
         //Or else use the WP HTTP API
     } else {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $request = new WP_Http();
         $result = $request->request($url);
         $feedData = $result['body'];
     }
     /*    echo $feedData;
     		exit;*/
     return $feedData;
 }
Exemplo n.º 2
1
 public function addError($error, $passedMetaData = array())
 {
     // Check if this error should be sent to Bugsnag
     if (!$this->config->shouldNotify()) {
         return false;
     }
     // Add global meta-data to error
     $error->setMetaData($this->config->metaData);
     // Add request meta-data to error
     if (Bugsnag_Request::isRequest()) {
         $error->setMetaData(Bugsnag_Request::getRequestMetaData());
     }
     // Add environment meta-data to error
     if ($this->config->sendEnvironment && !empty($_ENV)) {
         $error->setMetaData(array("Environment" => $_ENV));
     }
     // Add user-specified meta-data to error
     $error->setMetaData($passedMetaData);
     // Run beforeNotify function (can cause more meta-data to be merged)
     if (isset($this->config->beforeNotifyFunction) && is_callable($this->config->beforeNotifyFunction)) {
         $beforeNotifyReturn = call_user_func($this->config->beforeNotifyFunction, $error);
     }
     // Skip this error if the beforeNotify function returned FALSE
     if (!isset($beforeNotifyReturn) || $beforeNotifyReturn !== false) {
         $this->errorQueue[] = $error;
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * @param mixed $accessor
  * @param bool  $retrieve
  * @return Document|null
  */
 public function getDocument($accessor = null, $retrieve = false)
 {
     if ($accessor === null) {
         $accessor = static::DEFAULT_ACCESSOR;
     }
     if ($accessor === null) {
         // the value contains the document itself
         $doc = $this->value;
         // if the view didn't emit the actual doc as value but was called with include_docs=true
         if (!$doc || !isset($doc->_id) && !isset($doc['_id'])) {
             $doc = $this->doc;
         }
     } elseif (is_callable($accessor)) {
         // an anonymous function or another kind of callback that will grab the value for us
         $doc = call_user_func($accessor, $this);
     } elseif (is_array($this->value) && isset($this->value[$accessor])) {
         // value is an array
         $doc = $this->value[$accessor];
     } elseif (isset($this->value->{$accessor})) {
         // it's the name of a property
         $doc = $this->value->{$accessor};
     } else {
         // exception
     }
     if ($doc) {
         $retval = new Document($this->getViewResult()->getDatabase());
         $retval->hydrate($doc);
         return $retval;
     } elseif ($retrieve) {
         // the view didn't emit the actual doc as value and the view wasn't called with include_docs=true
         return $this->viewResult->getDatabase()->retrieveDocument($this->id);
     } else {
         return null;
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
 {
     if (!is_callable($this->getOption('callback'))) {
         throw new \RuntimeException(sprintf('Please provide a valid callback option "filter" for field "%s"', $this->getName()));
     }
     $this->active = call_user_func($this->getOption('callback'), $queryBuilder, $alias, $field, $data);
 }
Exemplo n.º 5
0
 /**
  * Loads all plugins.
  *
  * @param Application $app
  */
 public function load(Application $app)
 {
     foreach ($this->loadConfigs() as $name => $config) {
         if (isset($this->plugins[$name])) {
             continue;
         }
         if (isset($config['autoload'])) {
             foreach ($config['autoload'] as $namespace => $path) {
                 $app['autoloader']->addPsr4($namespace, $config['path'] . "/{$path}");
             }
         }
         if (isset($config['events'])) {
             foreach ($config['events'] as $event => $listener) {
                 $app->on($event, $listener);
             }
         }
         if (is_string($class = $config['main'])) {
             $plugin = new $class();
             if ($plugin instanceof ApplicationAware) {
                 $plugin->setApplication($app);
             }
             if ($plugin instanceof PluginInterface) {
                 $plugin->load($app, $config);
             }
             $this->plugins[$name] = $plugin;
         } elseif (is_callable($config['main'])) {
             $this->plugins[$name] = call_user_func($config['main'], $app, $config) ?: true;
         }
     }
 }
Exemplo n.º 6
0
 public function getUserData()
 {
     $userAttrList = array('lastname' => NULL, 'firstname' => NULL, 'loginName' => NULL, 'email' => NULL, 'officialCode' => NULL, 'phoneNumber' => NULL, 'isCourseCreator' => NULL, 'authSource' => NULL);
     foreach ($this->extAuthAttribNameList as $claroAttribName => $extAuthAttribName) {
         if (!is_null($extAuthAttribName)) {
             $userAttrList[$claroAttribName] = $this->auth->getAuthData($extAuthAttribName);
         }
     }
     foreach ($userAttrList as $claroAttribName => $claroAttribValue) {
         if (array_key_exists($claroAttribName, $this->extAuthAttribTreatmentList)) {
             $treatmentCallback = $this->extAuthAttribTreatmentList[$claroAttribName];
             if (is_callable($treatmentCallback)) {
                 $claroAttribValue = $treatmentCallback($claroAttribValue);
             } else {
                 $claroAttribValue = $treatmentCallback;
             }
         }
         $userAttrList[$claroAttribName] = $claroAttribValue;
     }
     // end foreach
     /* Two fields retrieving info from another source ... */
     $userAttrList['loginName'] = $this->auth->getUsername();
     $userAttrList['authSource'] = $this->authSourceName;
     if (isset($userAttrList['status'])) {
         $userAttrList['isCourseCreator'] = $userAttrList['status'] == 1 ? 1 : 0;
     }
     return $userAttrList;
 }
Exemplo n.º 7
0
 public function run(CantigaController $controller, $id, $customDataGenerator = null)
 {
     try {
         $repository = $this->info->getRepository();
         $fetch = $this->fetch;
         $item = $fetch($repository, $id);
         $nameProperty = 'get' . ucfirst($this->info->getItemNameProperty());
         $name = $item->{$nameProperty}();
         $customData = null;
         if (is_callable($customDataGenerator)) {
             $customData = $customDataGenerator($item);
         }
         $vars = $this->getVars();
         $vars['pageTitle'] = $this->info->getPageTitle();
         $vars['pageSubtitle'] = $this->info->getPageSubtitle();
         $vars['item'] = $item;
         $vars['name'] = $name;
         $vars['custom'] = $customData;
         $vars['indexPage'] = $this->info->getIndexPage();
         $vars['infoPage'] = $this->info->getInfoPage();
         $vars['insertPage'] = $this->info->getInsertPage();
         $vars['editPage'] = $this->info->getEditPage();
         $vars['removePage'] = $this->info->getRemovePage();
         $controller->breadcrumbs()->link($name, $this->info->getInfoPage(), $this->slugify(['id' => $id]));
         return $controller->render($this->info->getTemplateLocation() . $this->info->getInfoTemplate(), $vars);
     } catch (ItemNotFoundException $exception) {
         return $this->onError($controller, $controller->trans($this->info->getItemNotFoundErrorMessage()));
     } catch (ModelException $exception) {
         return $this->onError($controller, $controller->trans($exception->getMessage()));
     }
 }
Exemplo n.º 8
0
 public function notify($errno, $errstr, $errfile, $errline, $trace)
 {
     $body = array();
     $body[] = $this->_makeSection("", join("\n", array(@$_SERVER['GATEWAY_INTERFACE'] ? "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" : "", "{$errno}: {$errstr}", "at {$errfile} on line {$errline}")));
     if ($this->_whatToLog & self::LOG_TRACE && $trace) {
         $body[] = $this->_makeSection("TRACE", Debug_ErrorHook_Util::backtraceToString($trace));
     }
     /*if ($this->_whatToLog & self::LOG_SERVER) {
           $body[] = $this->_makeSection("SERVER", Debug_ErrorHook_Util::varExport($_SERVER));
       }*/
     if (!empty($_COOKIE) && $this->_whatToLog & self::LOG_COOKIE) {
         $body[] = $this->_makeSection("COOKIES", Debug_ErrorHook_Util::varExport($_COOKIE));
     }
     if (!empty($_GET) && $this->_whatToLog & self::LOG_GET) {
         $body[] = $this->_makeSection("GET", Debug_ErrorHook_Util::varExport($_GET));
     }
     if (!empty($_POST) && $this->_whatToLog & self::LOG_POST) {
         $body[] = $this->_makeSection("POST", Debug_ErrorHook_Util::varExport($_POST));
     }
     if (!empty($_SESSION) && $this->_whatToLog & self::LOG_SESSION) {
         $body[] = $this->_makeSection("SESSION", Debug_ErrorHook_Util::varExport(@$_SESSION));
     }
     // Append body suffix?
     $suffix = $this->_bodySuffix && is_callable($this->_bodySuffix) ? call_user_func($this->_bodySuffix) : $this->_bodySuffix;
     if ($suffix) {
         $body[] = $this->_makeSection("ADDITIONAL INFO", $suffix);
     }
     // Remain only 1st line for subject.
     $errstr = preg_replace("/\r?\n.*/s", '', $errstr);
     $this->_notifyText("{$errno}: {$errstr} at {$errfile} on line {$errline}", join("\n", $body));
 }
Exemplo n.º 9
0
/**
* Smarty truncate modifier plugin
* 
* Type:     modifier<br>
* Name:     truncate<br>
* Purpose:  Truncate a string to a certain length if necessary,
*             optionally splitting in the middle of a word, and
*             appending the $etc string or inserting $etc into the middle.
* 
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> 
* @param string $string input string
* @param integer $length lenght of truncated text
* @param string $etc end string
* @param boolean $break_words truncate at word boundary
* @param boolean $middle truncate in the middle of text
* @return string truncated string
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
    if ($length == 0) {
        return '';
    }
    if (is_callable('mb_strlen')) {
        if (mb_strlen($string) > $length) {
            $length -= min($length, mb_strlen($etc));
            if (!$break_words && !$middle) {
                $string = mb_ereg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p');
            }
            if (!$middle) {
                return mb_substr($string, 0, $length) . $etc;
            } else {
                return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, -$length / 2);
            }
        } else {
            return $string;
        }
    } else {
        if (strlen($string) > $length) {
            $length -= min($length, strlen($etc));
            if (!$break_words && !$middle) {
                $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1));
            }
            if (!$middle) {
                return substr($string, 0, $length) . $etc;
            } else {
                return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
            }
        } else {
            return $string;
        }
    }
}
Exemplo n.º 10
0
 /**
  * @covers ::__construct
  * @covers ::getJobRunnerFactory
  * @dataProvider configProvider
  */
 public function testTheJobRunnerFactoryIsReturnedIfProperlyConfigured($options)
 {
     $config = new JobQueueConfig($options);
     $callback = $config->getJobRunnerFactory();
     $this->assertTrue(is_callable($callback));
     $this->assertSame($options['job_runner'], $callback);
 }
Exemplo n.º 11
0
 protected function InvokeInternal(array $arguments = null)
 {
     $func = $this->_Callback;
     if ($this->_Object != null) {
         $func = array($this->_Object, $func);
     }
     $parameters = $this->_Params;
     if ($parameters != null) {
         $parameter_keys = array_keys($parameters);
         $count = count($parameter_keys);
         $argument_list = array();
         for ($i = 0; $i < $count; $i++) {
             $key = $parameter_keys[$i];
             $parameter = $parameters[$key];
             $value = isset($parameter['default']) ? $parameter['default'] : null;
             if (isset($arguments[$key])) {
                 $value = $arguments[$key];
             } else {
                 if (isset($arguments[$i])) {
                     $value = $arguments[$i];
                 }
             }
             $argument_list[$i] = $value;
         }
         $arguments = $argument_list;
     }
     if (!isset($arguments[0]) || $arguments[0] === null) {
         $arguments[0] = $this->_Default;
     }
     if (is_callable($func)) {
         return call_user_func_array($func, $arguments);
     }
     return $arguments[0];
 }
Exemplo n.º 12
0
 public static function __callStatic($name, array $params)
 {
     $params = $params[0];
     #print_r($params); #die;
     #echo 'Вы хотели вызвать '.__CLASS__.'::'.$name.', но его не существует, и сейчас выполняется '.__METHOD__.'()';
     #print_r(self::$codes);
     #echo $name . "<br/>\n";
     #var_dump(self::$codes[$name]);
     #die;
     if (isset(self::$codes[$name]) && is_callable(self::$codes[$name])) {
         #return self::$codes[$name]($params);
         return call_user_func(self::$codes[$name], $params);
     } else {
         $return = array();
         if (is_array($params)) {
             foreach ($params as $key => $val) {
                 $return[] = "{$key}={$val}";
             }
         }
         $return = implode(" ", $return);
         if ($return != '') {
             $return = ' ' . $return;
         }
         return "[" . $name . $return . "]";
     }
 }
Exemplo n.º 13
0
 /**
  * Render the js and/or css include html
  *
  * @param bool $include_js
  * @param bool $include_css
  * @param  function $modifier Callback function to modify the asset url
  * @return string
  */
 public static function render($include_js = TRUE, $include_css = FALSE, $modifier = null)
 {
     $html = '';
     if ($include_js) {
         if ($list = self::get(self::JAVASCRIPT_RESOURCE_KEY)) {
             foreach ($list as $data) {
                 $url = $data['src'];
                 if (is_callable($modifier)) {
                     $url = call_user_func($modifier, $url);
                 }
                 $html .= self::script_tag($url);
             }
         }
     }
     if ($include_css) {
         if ($list = self::get(self::CSS_RESOURCE_KEY)) {
             foreach ($list as $data) {
                 $url = $data['src'];
                 if (is_callable($modifier)) {
                     $url = call_user_func($modifier, $url);
                 }
                 $html .= self::style_tag($url);
             }
         }
     }
     return $html;
 }
Exemplo n.º 14
0
 /**
  * Request a page and return it as string.
  *
  * @param   string $url    A url to request.
  * @param   string $method Request method, GET or POST.
  * @param   string $query  Query string. eg: 'option=com_content&id=11&Itemid=125'. <br /> Only use for POST.
  * @param   array  $option An option array to override CURL OPT.
  *
  * @throws \Exception
  * @return  mixed  If success, return string, or return false.
  */
 public static function get($url, $method = 'get', $query = '', $option = array())
 {
     if ((!function_exists('curl_init') || !is_callable('curl_init')) && ini_get('allow_url_fopen')) {
         $return = new Object();
         $return->body = file_get_contents($url);
         return $return;
     }
     $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1", CURLOPT_FOLLOWLOCATION => !ini_get('open_basedir') ? true : false, CURLOPT_SSL_VERIFYPEER => false);
     // Merge option
     $options = $option + $options;
     $http = \JHttpFactory::getHttp(new \JRegistry($options), 'curl');
     try {
         switch ($method) {
             case 'post':
             case 'put':
             case 'patch':
                 $result = $http->{$method}(UriHelper::safe($url), $query);
                 break;
             default:
                 $result = $http->{$method}(UriHelper::safe($url));
                 break;
         }
     } catch (\Exception $e) {
         return new NullObject();
     }
     return $result;
 }
 /**
  * @dataProvider getAcceptData
  */
 public function testAccept($mode, $expected)
 {
     if (!is_callable($mode)) {
         switch ($mode) {
             case SortableIterator::SORT_BY_ACCESSED_TIME:
                 file_get_contents(self::toAbsolute('.git'));
                 sleep(1);
                 file_get_contents(self::toAbsolute('.bar'));
                 break;
             case SortableIterator::SORT_BY_CHANGED_TIME:
                 file_put_contents(self::toAbsolute('test.php'), 'foo');
                 sleep(1);
                 file_put_contents(self::toAbsolute('test.py'), 'foo');
                 break;
             case SortableIterator::SORT_BY_MODIFIED_TIME:
                 file_put_contents(self::toAbsolute('test.php'), 'foo');
                 sleep(1);
                 file_put_contents(self::toAbsolute('test.py'), 'foo');
                 break;
         }
     }
     $inner = new Iterator(self::$files);
     $iterator = new SortableIterator($inner, $mode);
     if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME || $mode === SortableIterator::SORT_BY_CHANGED_TIME || $mode === SortableIterator::SORT_BY_MODIFIED_TIME) {
         $this->assertOrderedIteratorForGroups($expected, $iterator);
     } else {
         $this->assertOrderedIterator($expected, $iterator);
     }
 }
Exemplo n.º 16
0
 private function _filter($value)
 {
     if ($this->_filter && is_callable($this->_filter)) {
         $value = call_user_func($this->_filter, $value);
     }
     return $value;
 }
Exemplo n.º 17
0
 /**
  * @param DomainEvent $event
  * @return void
  */
 protected function when(DomainEvent $event)
 {
     $method = 'when' . ClassFunctions::short($event);
     if (is_callable([$this, $method])) {
         $this->{$method}($event);
     }
 }
Exemplo n.º 18
0
/**
 * Smarty {json} plugin
 *
 * Type:       function
 * Name:       json
 * Date:       Apr 12, 2009
 * Purpose:    Read JSON from file, decode and assign data to Smarty template variable
 * Syntax:     {json file="filename.json"}: 'file' is a required parameter (URL)
 *             Predefined additional parameters:
 *             - assign="data": assign all JSON data to template variable $data
 *             - obj2obj [ Boolean | default:false ]:
 *               decodes JSON objects as either PHP associative arrays or PHP objects
 *             - debug [ Boolean | default:false ]: print decoded data in template
 *             Variable parameters:
 *             {json file="filename.json" home="homepage" lang="languages"}:
 *               assign (JSONdata)["homepage"] to template variable $home
 *               and (JSONdata)["languages"] to $lang,
 *               compare to: {config_load file="filename.conf" section="homepage"}
 * Install:    Drop into the plugin directory
 * @link       http://jlix.net/extensions/smarty/json
 * @author     Sander Aarts <smarty at jlix dot net>
 * @copyright  2009 Sander Aarts
 * @license    LGPL License
 * @version    1.0.1
 * @param      array
 * @param      Smarty
 */
function smarty_function_json($params, &$smarty)
{
    if (!is_callable('json_decode')) {
        $smarty->_trigger_fatal_error("{json} requires json_decode() function (PHP 5.2.0+)");
    }
    if (empty($params['file'])) {
        $smarty->_trigger_fatal_error("{json} parameter 'file' must not be empty");
    }
    if (isset($params['assign'], $params[$params['assign']])) {
        $smarty->_trigger_fatal_error("{json} parameter 'assign' conflicts with a variable assign parameter (both refer to the same variable)");
    }
    $assoc = $params['obj2obj'] == true ? false : true;
    $json = trim(file_get_contents($params['file']));
    $data = json_decode($json, $assoc);
    if ($params['debug'] == true) {
        echo "<pre>";
        print_r($data);
        echo "</pre>";
    }
    unset($params['file'], $params['obj2obj'], $params['debug']);
    $assign = array();
    foreach ($params as $key => $value) {
        if ($key === 'assign') {
            $assign[$value] = $data;
        } else {
            $assign[$key] = $assoc ? $data[$value] : $data->{$value};
        }
    }
    if (count($assign) > 0) {
        $smarty->assign($assign);
    } else {
        return $data;
    }
}
    function content_561617a7564969_20234583($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_replace')) {
            include 'D:\\workspace\\php\\nagoya6\\tools\\smarty\\plugins\\modifier.replace.php';
        }
        ?>

<h3><?php 
        echo smartyTranslate(array('s' => 'Referral program rules', 'mod' => 'referralprogram'), $_smarty_tpl);
        ?>
</h3>

<?php 
        if (isset($_smarty_tpl->tpl_vars['xml']->value)) {
            ?>
<div id="referralprogram_rules">
	<?php 
            if (isset($_smarty_tpl->tpl_vars['xml']->value->body->{$_smarty_tpl->tpl_vars['paragraph']->value})) {
                ?>
<div class="rte"><?php 
                echo smarty_modifier_replace(smarty_modifier_replace($_smarty_tpl->tpl_vars['xml']->value->body->{$_smarty_tpl->tpl_vars['paragraph']->value}, "\\'", "'"), '\\"', '"');
                ?>
</div><?php 
            }
            ?>
</div>
<?php 
        }
    }
Exemplo n.º 20
0
 /**
  * Returns `true` if value is of the specified type
  *
  * @param string $type
  * @param mixed $value
  * @return bool
  */
 protected function checkType($type, $value)
 {
     switch ($type) {
         case 'array':
             return is_array($value);
         case 'bool':
         case 'boolean':
             return is_bool($value);
         case 'callable':
             return is_callable($value);
         case 'float':
         case 'double':
             return is_float($value);
         case 'int':
         case 'integer':
             return is_int($value);
         case 'null':
             return is_null($value);
         case 'numeric':
             return is_numeric($value);
         case 'object':
             return is_object($value);
         case 'resource':
             return is_resource($value);
         case 'scalar':
             return is_scalar($value);
         case 'string':
             return is_string($value);
         case 'mixed':
             return true;
         default:
             return $value instanceof $type;
     }
 }
Exemplo n.º 21
0
 /**
  * @param mixed $callback
  * @throws \InvalidArgumentException
  */
 public function setCallback($callback)
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException("Callback is not callable");
     }
     $this->callback = $callback;
 }
Exemplo n.º 22
0
 /**
  * @param int      $expectedType     Expected triggered error type (pass one of PHP's E_* constants)
  * @param string[] $expectedMessages Expected error messages
  * @param callable $testCode         A callable that is expected to trigger the error messages
  */
 public static function assertErrorsAreTriggered($expectedType, $expectedMessages, $testCode)
 {
     if (!is_callable($testCode)) {
         throw new \InvalidArgumentException(sprintf('The code to be tested must be a valid callable ("%s" given).', gettype($testCode)));
     }
     $e = null;
     $triggeredMessages = array();
     try {
         $prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use($expectedType, &$triggeredMessages, &$prevHandler) {
             if ($expectedType !== $type) {
                 return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context);
             }
             $triggeredMessages[] = $message;
         });
         call_user_func($testCode);
     } catch (\Exception $e) {
     } catch (\Throwable $e) {
     }
     restore_error_handler();
     if (null !== $e) {
         throw $e;
     }
     \PHPUnit_Framework_Assert::assertCount(count($expectedMessages), $triggeredMessages);
     foreach ($triggeredMessages as $i => $message) {
         \PHPUnit_Framework_Assert::assertContains($expectedMessages[$i], $message);
     }
 }
Exemplo n.º 23
0
 /**
  * Generic variable clean method
  */
 public static function clean($var, $filters = null)
 {
     is_null($filters) and $filters = \Config::get('security.input_filter', array());
     $filters = is_array($filters) ? $filters : array($filters);
     foreach ($filters as $filter) {
         // is this filter a callable local function?
         if (is_string($filter) and is_callable('static::' . $filter)) {
             $var = static::$filter($var);
         } elseif (is_callable($filter)) {
             if (is_array($var)) {
                 foreach ($var as $key => $value) {
                     $var[$key] = call_user_func($filter, $value);
                 }
             } else {
                 $var = call_user_func($filter, $var);
             }
         } else {
             if (is_array($var)) {
                 foreach ($var as $key => $value) {
                     $var[$key] = preg_replace('#[' . $filter . ']#ui', '', $value);
                 }
             } else {
                 $var = preg_replace('#[' . $filter . ']#ui', '', $var);
             }
         }
     }
     return $var;
 }
Exemplo n.º 24
0
 /**
  * @param callable<(callable $resolve, callable $reject): callable|null> $resolver
  */
 public function __construct(callable $resolver)
 {
     /**
      * Resolves the promise with the given promise or value. If another promise, this promise takes
      * on the state of that promise. If a value, the promise will be fulfilled with that value.
      *
      * @param mixed $value A promise can be resolved with anything other than itself.
      */
     $resolve = function ($value = null) {
         $this->resolve($value);
     };
     /**
      * Rejects the promise with the given exception.
      *
      * @param \Throwable $reason
      */
     $reject = function (\Throwable $reason) {
         $this->reject($reason);
     };
     try {
         $onCancelled = $resolver($resolve, $reject);
         if (null !== $onCancelled && !is_callable($onCancelled)) {
             throw new InvalidResolverError($resolver);
         }
         parent::__construct($onCancelled);
     } catch (\Throwable $exception) {
         parent::__construct();
         $this->reject($exception);
     }
 }
Exemplo n.º 25
0
 public function __call($name, $arguments)
 {
     if (isset($this->apis[$name]) && is_callable($this->apis[$name])) {
         return call_user_func_array($this->apis[$name], $arguments);
     }
     return null;
 }
 function content_55ccdf859b05a7_65053932($_smarty_tpl)
 {
     if (!is_callable('smarty_function_style')) {
         include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.style.php';
     }
     echo smarty_function_style(array('src' => "addons/discussion/styles.less"), $_smarty_tpl);
 }
Exemplo n.º 27
0
 /**
  * Constructor. CURLOPT_FOLLOWLOCATION must be disabled when open_basedir or safe_mode are enabled.
  *
  * @param   JRegistry  $options  Client options object.
  *
  * @see     http://www.php.net/manual/en/function.curl-setopt.php
  * @since   11.3
  * @throws  RuntimeException
  */
 public function __construct(JRegistry $options)
 {
     if (!function_exists('curl_init') || !is_callable('curl_init')) {
         throw new RuntimeException('Cannot use a cURL transport when curl_init() is not available.');
     }
     $this->options = $options;
 }
 private function createStorage($storageKey, array $storages, $urlResolver, Config $config)
 {
     if (!array_key_exists($storageKey, $storages)) {
         throw new InvalidArgumentException("{$storageKey} is not a valid fineuploader server storage");
     }
     $storage = $storages[$storageKey];
     if (!array_key_exists('class', $storage)) {
         throw new InvalidArgumentException("{$storageKey} does not have a valid storage class");
     }
     $storageConfig = array_key_exists('config', $storage) ? $storage['config'] : [];
     if (is_array($urlResolver)) {
         if (!array_key_exists('class', $urlResolver)) {
             throw new InvalidArgumentException("urlResolver needs a class key");
         }
         $resolverConfig = array_key_exists('config', $urlResolver) ? $urlResolver['config'] : [];
         $urlResolver = new $urlResolver['class']($resolverConfig);
         if (!$urlResolver instanceof UrlResolverInterface) {
             throw new InvalidArgumentException(get_class($urlResolver) . " does not implement " . "Optimus\\Http\\UrlResolverInterface");
         }
     } elseif (!is_callable($urlResolver)) {
         throw new InvalidArgumentException("Url resolver is not a method.");
     }
     $storage = new $storage['class']($storageConfig, $config, $urlResolver);
     return $storage;
 }
Exemplo n.º 29
0
 /**
  * @param string $class_name
  */
 protected function getClass($class_name, $subclass_of = 'Cyan\\Framework\\Controller', array $arguments = [], \Closure $newInstance = null)
 {
     $required_traits = ['Cyan\\Framework\\TraitSingleton'];
     $reflection_class = new ReflectionClass($class_name);
     foreach ($required_traits as $required_trait) {
         if (!in_array($required_trait, $reflection_class->getTraitNames())) {
             throw new TraitException(sprintf('%s class must use %s', $class_name, $required_trait));
         }
     }
     if (!is_subclass_of($class_name, $subclass_of)) {
         throw new TraitException(sprintf('%s class must be a instance of %s', $class_name, $subclass_of));
     }
     if (is_callable($newInstance)) {
         $instance = call_user_func_array($newInstance, $arguments);
     } else {
         $instance = !empty($arguments) ? call_user_func_array([$class_name, 'getInstance'], $arguments) : $class_name::getInstance();
     }
     if ($this->hasContainer('application')) {
         if (!$instance->hasContainer('application')) {
             $instance->setContainer('application', $this->getContainer('application'));
         }
         if (!$instance->hasContainer('factory_plugin')) {
             $instance->setContainer('factory_plugin', $this->getContainer('application')->getContainer('factory_plugin'));
         }
     }
     if (is_callable([$instance, 'initialize']) || method_exists($instance, 'initialize')) {
         $instance->initialize();
     }
     return $instance;
 }
Exemplo n.º 30
-1
 /**
  * Loops until the waitCallback returns true and sleeps in between attempts
  * for a length of time specified by the interval. Also emits a WaitEvent
  * during each loop before sleeping.
  *
  * @throws \RuntimeException if the max attempts is exceeded
  */
 public function wait()
 {
     $attempts = 0;
     // Perform an initial delay if configured
     if ($this->config['delay']) {
         usleep($this->config['delay'] * 1000000);
     }
     // If not yet reached max attempts, keep trying to perform wait callback
     while ($attempts < $this->config['max_attempts']) {
         // Perform the callback; if true, then waiting is finished
         if (call_user_func($this->waitCallback)) {
             return;
         }
         // Emit a wait event so collaborators can do something between waits
         $event = new WaitEvent($this->config, $attempts);
         $this->getEmitter()->emit('wait', $event);
         // Wait the specified interval
         if ($interval = $this->config['interval']) {
             if (is_callable($interval)) {
                 $interval = $interval();
             }
             usleep($interval * 1000000);
         }
         $attempts++;
     }
     throw new \RuntimeException("Waiter failed after {$attempts} attempts");
 }