/**
  * Sets validator options
  *
  * @param  string|array|\Traversable $options
  */
 public function __construct($options = null)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     $case = null;
     if (1 < func_num_args()) {
         $case = func_get_arg(1);
     }
     if (is_array($options)) {
         if (isset($options['case'])) {
             $case = $options['case'];
             unset($options['case']);
         }
         if (!array_key_exists('extension', $options)) {
             $options = array('extension' => $options);
         }
     } else {
         $options = array('extension' => $options);
     }
     if ($case !== null) {
         $options['case'] = $case;
     }
     parent::__construct($options);
 }
Example #2
0
 /**
  * Removes all blanks in an array and merges them into a string
  *
  * @param string $glue String to include between each element
  * @param array $array Array containing elements to be imploded
  * @param string $itemCallback A transformation closure to call on each element of the array
  * @param string $keysToInclude,... Keys of the array elements to include - if not supplied, all elements will be used
  * @return string String of concatenated elements
  */
 public static function implodeIgnoringBlanks($glue, $array, $itemCallback = null, $keysToInclude = null)
 {
     $array = array_filter($array);
     if (!empty($itemCallback)) {
         foreach ($array as $key => $value) {
             $array[$key] = $itemCallback($value);
         }
     }
     $keys = array($keysToInclude);
     for ($i = 4; $i < func_num_args(); $i++) {
         $keys[] = func_get_arg($i);
     }
     $keys = array_filter($keys);
     $string = "";
     if (count($keys)) {
         foreach ($keys as $key) {
             if (!empty($array[$key])) {
                 $string .= $array[$key] . $glue;
             }
         }
         if (strlen($string) >= strlen($glue)) {
             $string = substr($string, 0, strlen($string) - strlen($glue));
         }
     } else {
         $string = implode($glue, $array);
     }
     return $string;
 }
 /**
  * Carrega a página "/views/user-register/index.php"
  */
 public function index()
 {
     // Page title
     $this->title = 'User Register';
     // Verifica se o usuário está logado
     if (!$this->logged_in) {
         // Se não; garante o logout
         $this->logout();
         // Redireciona para a página de login
         $this->goto_login();
         // Garante que o script não vai passar daqui
         return;
     }
     // Verifica se o usuário tem a permissão para acessar essa página
     if (!$this->check_permissions($this->permission_required, $this->userdata['user_permissions'])) {
         // Exibe uma mensagem
         echo 'Você não tem permissões para acessar essa página.';
         // Finaliza aqui
         return;
     }
     // Parametros da função
     $parametros = func_num_args() >= 1 ? func_get_arg(0) : array();
     // Carrega o modelo para este view
     $modelo = $this->load_model('user-register/user-register-model');
     /** Carrega os arquivos do view **/
     // /views/_includes/header.php
     require ABSPATH . '/views/_includes/header.php';
     // /views/_includes/menu.php
     require ABSPATH . '/views/_includes/menu.php';
     // /views/user-register/index.php
     require ABSPATH . '/views/user-register/user-register-view.php';
     // /views/_includes/footer.php
     require ABSPATH . '/views/_includes/footer.php';
 }
Example #4
0
 /**
  * Sets validator options
  *
  * @param  array|Zend_Config $haystack
  * @return void
  */
 public function __construct($options)
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } else {
         if (!is_array($options)) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Array expected as parameter');
         } else {
             $count = func_num_args();
             $temp = array();
             if ($count > 1) {
                 $temp['haystack'] = func_get_arg(0);
                 $temp['strict'] = func_get_arg(1);
                 $options = $temp;
             } else {
                 $temp = func_get_arg(0);
                 if (!array_key_exists('haystack', $options)) {
                     $options = array();
                     $options['haystack'] = $temp;
                 } else {
                     $options = $temp;
                 }
             }
         }
     }
     $this->setHaystack($options['haystack']);
     if (array_key_exists('strict', $options)) {
         $this->setStrict($options['strict']);
     }
     if (array_key_exists('recursive', $options)) {
         $this->setRecursive($options['recursive']);
     }
 }
Example #5
0
/**
 * Creates a new user from the "Users" form using $_POST information.
 *
 * It seems that the first half is for backwards compatibility, but only
 * has the ability to alter the user's role. WordPress core seems to
 * use this function only in the second way, running edit_user() with
 * no id so as to create a new user.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return null|WP_Error|int Null when adding user, WP_Error or User ID integer when no parameters.
 */
function add_user()
{
    if (func_num_args()) {
        // The hackiest hack that ever did hack
        global $current_user, $wp_roles;
        $user_id = (int) func_get_arg(0);
        if (isset($_POST['role'])) {
            $new_role = sanitize_text_field($_POST['role']);
            // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
            if ($user_id != $current_user->id || $wp_roles->role_objects[$new_role]->has_cap('edit_users')) {
                // If the new role isn't editable by the logged-in user die with error
                $editable_roles = get_editable_roles();
                if (empty($editable_roles[$new_role])) {
                    wp_die(__('You can&#8217;t give users that role.'));
                }
                $user = new WP_User($user_id);
                $user->set_role($new_role);
            }
        }
    } else {
        add_action('user_register', 'add_user');
        // See above
        return edit_user();
    }
}
Example #6
0
 /**
  * Processes the dump variables, if none is supplied, all the twig
  * template variables are used
  * @param  Twig_Environment $env
  * @param  array            $context
  * @return string
  */
 public function runDump(Twig_Environment $env, $context)
 {
     if (!$env->isDebug()) {
         return;
     }
     $result = '';
     $count = func_num_args();
     if ($count == 2) {
         $this->variablePrefix = true;
         $vars = [];
         foreach ($context as $key => $value) {
             if (!$value instanceof Twig_Template) {
                 $vars[$key] = $value;
             }
         }
         $result .= $this->dump($vars, static::PAGE_CAPTION);
     } else {
         $this->variablePrefix = false;
         for ($i = 2; $i < $count; $i++) {
             $var = func_get_arg($i);
             if ($var instanceof ComponentBase) {
                 $caption = [static::COMPONENT_CAPTION, get_class($var)];
             } elseif (is_array($var)) {
                 $caption = static::ARRAY_CAPTION;
             } elseif (is_object($var)) {
                 $caption = [static::OBJECT_CAPTION, get_class($var)];
             } else {
                 $caption = [static::OBJECT_CAPTION, gettype($var)];
             }
             $result .= $this->dump($var, $caption);
         }
     }
     return $result;
 }
Example #7
0
 public function __construct()
 {
     if (func_num_args() == 1) {
         $this->setDefaultValue(func_get_arg(0));
         $this->setHumanValue(func_get_arg(0));
     }
 }
Example #8
0
 protected final function __new__()
 {
     parent::__new__(func_num_args() > 0 ? func_get_arg(0) : null);
     $this->o('Template')->cp($this->vars);
     $this->request_url = parent::current_url();
     $this->request_query = parent::query_string() == null ? null : '?' . parent::query_string();
 }
Example #9
0
File: 16.php Project: badlamer/hhvm
function test()
{
    var_dump(func_get_arg(0));
    var_dump(func_get_arg(1));
    var_dump(func_get_arg(2));
    var_dump(func_get_arg(3));
}
Example #10
0
 public function execute($id)
 {
     if (!isset($this->prepares[$id])) {
         throw new Moonlake_Exception_ModelConnector("The given id doesn't represent a valid prepared statement. This mostly means, that the statement is freed befor this call");
     }
     for ($i = 0; $i < count($this->prepares[$id]['types']); $i++) {
         $args[] = func_get_arg($i + 1);
     }
     $stmt = $this->prepares[$id]['stmt'];
     call_user_method_array('bind_param', $stmt, $args);
     $stmt->execute() or $this->error($this->prepares[$id]['sql']);
     // bind result byref to array
     call_user_func_array(array($stmt, "bind_result"), $byref_array_for_fields);
     // returns a copy of a value
     $copy = create_function('$a', 'return $a;');
     $results = array();
     while ($mysqli_stmt_object->fetch()) {
         // array_map will preserve keys when done here and this way
         $result = array_map($copy, $byref_array_for_fields);
         $mresult = new Moonlake_Model_Result();
         foreach ($result as $key => $val) {
             $mresult->{$key} = $val;
         }
         $results[] = $mresult;
     }
     // create with this new query
     $qid = count($this->queries);
     $this->queries[$qid]['sql'] = $sql;
     $this->queries[$qid]['rows'] = count($results);
     $this->queries[$qid]['seek'] = 0;
     $this->queries[$qid]['result'] = $results;
     return $results;
 }
Example #11
0
function sort2DArray($ArrayData, $KeyName1, $SortOrder1 = "SORT_ASC", $SortType1 = "SORT_REGULAR")
{
    if (!is_array($ArrayData)) {
        return $ArrayData;
    }
    // Get args number.
    $ArgCount = func_num_args();
    // Get keys to sort by and put them to SortRule array.
    for ($I = 1; $I < $ArgCount; $I++) {
        $Arg = func_get_arg($I);
        if (!@eregi("SORT", $Arg)) {
            $KeyNameList[] = $Arg;
            $SortRule[] = '$' . $Arg;
        } else {
            $SortRule[] = $Arg;
        }
    }
    // Get the values according to the keys and put them to array.
    foreach ($ArrayData as $Key => $Info) {
        foreach ($KeyNameList as $KeyName) {
            ${$KeyName}[$Key] = $Info[$KeyName];
        }
    }
    // Create the eval string and eval it.
    $EvalString = 'array_multisort(' . join(",", $SortRule) . ',$ArrayData);';
    eval($EvalString);
    return $ArrayData;
}
Example #12
0
 /**
  * @param array $elements
  */
 public function __construct($elements = array())
 {
     if (!is_array($elements)) {
         $elements = func_get_arg(1);
     }
     parent::__construct($this->getAllowedType(), $elements);
 }
 /**
  * Constructor to set initial or default values of member properties
  * @param   string            $status   Initialization value for the property $this->status
  * @param   string            $uuid     Initialization value for the property $this->uuid  
  */
 public function __construct()
 {
     if (2 == func_num_args()) {
         $this->status = func_get_arg(0);
         $this->uuid = func_get_arg(1);
     }
 }
Example #14
0
 public function __construct()
 {
     if (func_num_args() == 1) {
         $arg = func_get_arg(0);
         $this->_fromArray($arg);
     }
 }
 /**
  * @return Statement
  */
 public function query()
 {
     $query = func_get_arg(0);
     $stmt = new Statement($this, $query);
     $stmt->execute();
     return $stmt;
 }
Example #16
0
 public function __construct()
 {
     if (func_num_args() > 0) {
         $parameters = func_get_arg(0);
         $this->amount = isset($parameters['amount']) ? $parameters['amount'] : null;
     }
 }
Example #17
0
 public static function parse($parser)
 {
     $parser->disableCache();
     $title = $parser->getTitle()->getText();
     $titleArray = explode(':', $title);
     $ontAbbr = $titleArray[0];
     $termID = str_replace(' ', '_', $titleArray[1]);
     $ontology = new OntologyData($ontAbbr);
     $term = $ontology->parseTermByID($termID);
     $params = array();
     for ($i = 2; $i < func_num_args(); $i++) {
         $params[] = func_get_arg($i);
     }
     list($options, $valids, $invalids) = self::extractSupClass($params, $ontology);
     $pathType = $GLOBALS['okwHierarchyConfig']['pathType'];
     $supClasses = array();
     if (!empty($valids)) {
         foreach ($valids as $index => $value) {
             $supClasses[] = $value['iri'];
             $hierarchy = $ontology->parseTermHierarchy($term, $pathType, $value['iri']);
             if ($value['iri'] == $GLOBALS['okwRDFConfig']['Thing']) {
                 $GLOBALS['okwCache']['hierarchy'][$index] = $hierarchy;
             } else {
                 foreach ($hierarchy as $path) {
                     if (!empty($path['path'])) {
                         $GLOBALS['okwCache']['hierarchy'][$index] = $hierarchy;
                     }
                 }
             }
         }
     }
     wfDebugLog('OntoKiWi', sprintf('OKW\\Parser\\HierarchyParser: parsed hierarchy {%s} for [[%s]]', join(';', $supClasses), $title));
     wfDebugLog('OntoKiWi', '[caches] OKW\\Parser\\HierarchyParser: hierarchy');
     return array('', 'noparse' => true);
 }
Example #18
0
 /**
  * Sets validator options
  *
  * @param  array|\Zend\Config\Config $haystack
  * @return void
  */
 public function __construct($options = null)
 {
     if ($options instanceof \Zend\Config\Config) {
         $options = $options->toArray();
     } else {
         if (!is_array($options)) {
             throw new Exception\InvalidArgumentException('Array expected as parameter');
         } else {
             $count = func_num_args();
             $temp = array();
             if ($count > 1) {
                 $temp['haystack'] = func_get_arg(0);
                 $temp['strict'] = func_get_arg(1);
                 $options = $temp;
             } else {
                 $temp = func_get_arg(0);
                 if (!array_key_exists('haystack', $options)) {
                     $options = array();
                     $options['haystack'] = $temp;
                 } else {
                     $options = $temp;
                 }
             }
         }
     }
     $this->setHaystack($options['haystack']);
     if (array_key_exists('strict', $options)) {
         $this->setStrict($options['strict']);
     }
     if (array_key_exists('recursive', $options)) {
         $this->setRecursive($options['recursive']);
     }
 }
 /**
  * Set the browser cookie
  * @param string $name The name of the cookie.
  * @param string $value The value to be stored in the cookie.
  * @param int|null $expire Unix timestamp (in seconds) when the cookie should expire.
  *        0 (the default) causes it to expire $wgCookieExpiration seconds from now.
  *        null causes it to be a session cookie.
  * @param array $options Assoc of additional cookie options:
  *     prefix: string, name prefix ($wgCookiePrefix)
  *     domain: string, cookie domain ($wgCookieDomain)
  *     path: string, cookie path ($wgCookiePath)
  *     secure: bool, secure attribute ($wgCookieSecure)
  *     httpOnly: bool, httpOnly attribute ($wgCookieHttpOnly)
  *     raw: bool, if true uses PHP's setrawcookie() instead of setcookie()
  *   For backwards compatibility, if $options is not an array then it and
  *   the following two parameters will be interpreted as values for
  *   'prefix', 'domain', and 'secure'
  * @since 1.22 Replaced $prefix, $domain, and $forceSecure with $options
  */
 public function setcookie($name, $value, $expire = 0, $options = array())
 {
     global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
     global $wgCookieSecure, $wgCookieExpiration, $wgCookieHttpOnly;
     if (!is_array($options)) {
         // Backwards compatibility
         $options = array('prefix' => $options);
         if (func_num_args() >= 5) {
             $options['domain'] = func_get_arg(4);
         }
         if (func_num_args() >= 6) {
             $options['secure'] = func_get_arg(5);
         }
     }
     $options = array_filter($options, function ($a) {
         return $a !== null;
     }) + array('prefix' => $wgCookiePrefix, 'domain' => $wgCookieDomain, 'path' => $wgCookiePath, 'secure' => $wgCookieSecure, 'httpOnly' => $wgCookieHttpOnly, 'raw' => false);
     if ($expire === null) {
         $expire = 0;
         // Session cookie
     } elseif ($expire == 0 && $wgCookieExpiration != 0) {
         $expire = time() + $wgCookieExpiration;
     }
     $func = $options['raw'] ? 'setrawcookie' : 'setcookie';
     if (Hooks::run('WebResponseSetCookie', array(&$name, &$value, &$expire, $options))) {
         wfDebugLog('cookie', $func . ': "' . implode('", "', array($options['prefix'] . $name, $value, $expire, $options['path'], $options['domain'], $options['secure'], $options['httpOnly'])) . '"');
         call_user_func($func, $options['prefix'] . $name, $value, $expire, $options['path'], $options['domain'], $options['secure'], $options['httpOnly']);
     }
 }
Example #20
0
 /**
  * Constructor to set initial or default values of member properties
  * @param   array             $data   Initialization value for the property $this->data
  * @param   array             $meta   Initialization value for the property $this->meta
  */
 public function __construct()
 {
     if (2 == func_num_args()) {
         $this->data = func_get_arg(0);
         $this->meta = func_get_arg(1);
     }
 }
Example #21
0
 function gitDir()
 {
     if (func_num_args()) {
         $this->gitDir = func_get_arg(0);
     }
     return $this->gitDir;
 }
Example #22
0
 /**
  * Static render method is used to prevent exposing $this and other Template
  * properties to the template scope.
  *
  * @param string $file
  * @param array $scope
  * @return string
  */
 private static function _render()
 {
     extract(func_get_arg(1), \EXTR_REFS);
     ob_start();
     require func_get_arg(0);
     return ob_get_clean();
 }
Example #23
0
 /**
  * Invokes internal PHP function with own error handler.
  * @param  string
  * @return mixed
  */
 public static function invokeSafe($function, array $args, $onError)
 {
     $prev = set_error_handler(function ($severity, $message, $file) use($onError, &$prev, $function) {
         if ($file === '' && defined('HHVM_VERSION')) {
             // https://github.com/facebook/hhvm/issues/4625
             $file = func_get_arg(5)[1]['file'];
         }
         if ($file === __FILE__) {
             $msg = preg_replace("#^{$function}\\(.*?\\): #", '', $message);
             if ($onError($msg, $severity) !== FALSE) {
                 return;
             }
         }
         return $prev ? $prev(...func_get_args()) : FALSE;
     });
     try {
         $res = $function(...$args);
         restore_error_handler();
         return $res;
     } catch (\Throwable $e) {
         restore_error_handler();
         throw $e;
     } catch (\Exception $e) {
         restore_error_handler();
         throw $e;
     }
 }
 public function onControllerPagesDesignBlocks_InitData()
 {
     $method_name = func_get_arg(0);
     if ($method_name == 'insert') {
         $lm = new ALayoutManager();
         $this->baseObject->loadLanguage('banner_manager/banner_manager');
         $this->baseObject->loadLanguage('design/blocks');
         $block = $lm->getBlockByTxtId('banner');
         $block_id = $block['block_id'];
         $this->baseObject->data['tabs'][1000] = array('href' => $this->html->getSecureURL('extension/banner_manager/insert_block', '&block_id=' . $block_id), 'text' => $this->language->get('text_banner_block'), 'active' => false);
     }
     if ($method_name == 'edit') {
         $lm = new ALayoutManager();
         $blocks = $lm->getAllBlocks();
         foreach ($blocks as $block) {
             if ($block['custom_block_id'] == (int) $this->request->get['custom_block_id']) {
                 $block_txt_id = $block['block_txt_id'];
                 break;
             }
         }
         if ($block_txt_id == 'banner_block') {
             header('Location: ' . $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . (int) $this->request->get['custom_block_id']));
             exit;
         }
     }
 }
Example #25
0
 /**
  * Returns a specific character in UTF-8.
  * @param  int     codepoint
  * @return string
  */
 public static function chr($code)
 {
     if (func_num_args() > 1 && strcasecmp(func_get_arg(1), 'UTF-8')) {
         trigger_error(__METHOD__ . ' supports only UTF-8 encoding.', E_USER_DEPRECATED);
     }
     return iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code));
 }
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->validated_types = array('D' => 'date', 'E' => 'email', 'N' => 'number', 'F' => 'phone', 'A' => 'ipaddress');
     $this->loadLanguage('forms_manager/forms_manager');
     $instance_id = func_get_arg(0);
     $block_data = $this->getBlockContent($instance_id);
     $this->view->assign('block_framed', $block_data['block_framed']);
     $this->view->assign('content', $block_data['content']);
     $this->view->assign('heading_title', $block_data['title']);
     $this->view->assign('stat_url', $this->html->getURL('r/extension/banner_manager'));
     $this->view->assign('error_required', $this->language->get('error_required'));
     $this->view->assign('template_dir', RDIR_TEMPLATE);
     if ($block_data['content']) {
         $this->document->addScript(DIR_EXTENSIONS . 'forms_manager' . DIR_EXT_STORE . 'js/form_check.js');
         // need to set wrapper for non products listing blocks
         if ($this->view->isTemplateExists($block_data['block_wrapper'])) {
             $this->view->setTemplate($block_data['block_wrapper']);
         }
         $this->processTemplate();
     }
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
/**
 * Smarty strip_tags modifier plugin
 *
 * Type:    modifier
 * Name:    strip_tags
 * Purpose: strip html tags from text
 * @link    http://www.smarty.net/manual/en/language.modifier.strip.tags.php
 *          strip_tags (Smarty online manual)
 *
 * @author  Monte Ohrt <monte at="" ohrt="" dot="" com="">
 * @author  Jordon Mears <jordoncm at="" gmail="" dot="" com="">
 *
 * @version 2.0
 *
 * @param   string
 * @param   boolean optional
 * @param   string optional
 * @return  string
 */
function smarty_modifier_stripTags($string)
{
    switch (func_num_args()) {
        case 1:
            $replace_with_space = true;
            break;
        case 2:
            $arg = func_get_arg(1);
            if ($arg === 1 || $arg === true || $arg === '1' || $arg === 'true') {
                // for full legacy support || $arg === 'false' should be included
                $replace_with_space = true;
                $allowable_tags = '';
            } elseif ($arg === 0 || $arg === false || $arg === '0' || $arg === 'false') {
                // for full legacy support || $arg === 'false' should be removed
                $replace_with_space = false;
                $allowable_tags = '';
            } else {
                $replace_with_space = true;
                $allowable_tags = $arg;
            }
            break;
        case 3:
            $replace_with_space = func_get_arg(1);
            $allowable_tags = func_get_arg(2);
            break;
    }
    if ($replace_with_space) {
        $string = preg_replace('!(<[^>]*?>)!', '$1 ', $string);
    }
    $string = strip_tags($string, $allowable_tags);
    if ($replace_with_space) {
        $string = preg_replace('!(<[^>]*?>) !', '$1', $string);
    }
    return $string;
}
Example #28
0
 static function put($product, $qty = 1)
 {
     if (!$product instanceof Product) {
         $product = Product::find(static::idFrom($product));
     }
     if (!$product) {
         $product = func_get_arg(0);
         Log::warn_Cart("Unknown product [{$product}] to place in cart.");
     } elseif (!$product->available) {
         Log::warn_Cart("Attempting to place unavailable product [{$product->title}].");
     } else {
         $oldQty = static::qty($product) ?: null;
         $qty = max(0, round(S::toFloat($qty), 2));
         $key = 'cart_goods.' . $product->id;
         if ($qty == 0) {
             if ($oldQty) {
                 Session::forget($key);
                 Event::fire('cart.removed', array($product, &$oldQty));
             }
         } else {
             $qty = max($product->min, $qty);
             $product->fractable or $qty = ceil($qty);
             if ($qty != $oldQty) {
                 Session::put($key, $qty);
                 Event::fire('cart.added', array($product, &$oldQty));
             }
         }
         return $product;
     }
 }
Example #29
0
 /**
  * Creates new instance of \Google\Protobuf\DescriptorProto\ReservedRange
  *
  * @throws \InvalidArgumentException
  *
  * @return ReservedRange
  */
 public static function create()
 {
     switch (func_num_args()) {
         case 0:
             return new ReservedRange();
         case 1:
             return new ReservedRange(func_get_arg(0));
         case 2:
             return new ReservedRange(func_get_arg(0), func_get_arg(1));
         case 3:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2));
         case 4:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3));
         case 5:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
         case 6:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5));
         case 7:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6));
         case 8:
             return new ReservedRange(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6), func_get_arg(7));
         default:
             throw new \InvalidArgumentException('More than 8 arguments supplied, please be reasonable.');
     }
 }
Example #30
0
function query()
{
    $sql = func_get_arg(0);
    $parameters = array_slice(func_get_args(), 1);
    // try to connect to database
    static $handle;
    if (!isset($handle)) {
        try {
            // connect to database
            $handle = new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER . ";charset=utf8", USERNAME, PASSWORD);
            // ensure that PDO::prepare returns false when passed invalid SQL
            $handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        } catch (Exception $e) {
            trigger_error($e->getMessage(), E_USER_ERROR);
            exit;
        }
    }
    $statement = $handle->prepare($sql);
    if ($statement === false) {
        trigger_error($handle->errorInfo()[2], E_USER_ERROR);
        exit;
    }
    $results = $statement->execute($parameters);
    // return result set's rows, if any
    if ($results !== false) {
        return $statement->fetchAll(PDO::FETCH_ASSOC);
    } else {
        return false;
    }
}