示例#1
0
 /**
  * Dump Array or Object as tree node. If send multiple params in this method, this function will batch print it.
  *
  * @param   mixed  $data   Array or Object to dump.
  *
  * @since   2.0
  *
  * @return  void
  */
 function show($data)
 {
     $args = func_get_args();
     $last = array_pop($args);
     if (is_int($last)) {
         $level = $last;
     } else {
         $level = 5;
         $args[] = $last;
     }
     echo "\n\n";
     if (PHP_SAPI != 'cli') {
         echo '<pre>';
     }
     // Dump Multiple values
     if (count($args) > 1) {
         $prints = array();
         $i = 1;
         foreach ($args as $arg) {
             $prints[] = "[Value " . $i . "]\n" . \Windwalker\Utilities\ArrayHelper::dump($arg, $level);
             $i++;
         }
         echo implode("\n\n", $prints);
     } else {
         // Dump one value.
         echo \Windwalker\Utilities\ArrayHelper::dump($data, $level);
     }
     if (PHP_SAPI != 'cli') {
         echo '</pre>';
     }
 }
示例#2
0
 /**
  * matchRequest
  *
  * @param array $query
  *
  * @return  boolean
  */
 protected function matchRequest($query = [])
 {
     $input = Ioc::getInput();
     if (!$query) {
         return true;
     }
     return !empty(ArrayHelper::query([$input->toArray()], $query));
 }
示例#3
0
 /**
  * getDefaultData
  *
  * @return array
  */
 public function getFormDefaultData()
 {
     $sessionData = (array) $this['form.data'];
     $pk = $this['item.pk'];
     $item = User::get($pk);
     if (ArrayHelper::getValue($sessionData, 'id') == $item->id) {
         unset($sessionData['password']);
         unset($sessionData['password2']);
         return $sessionData;
     }
     unset($item->password);
     return $item->dump();
 }
 /**
  * getDefaultData
  *
  * @return array
  */
 public function getFormDefaultData()
 {
     $sessionData = (array) $this['form.data'];
     try {
         $keyName = $this['keyName'] ?: $this->getKeyName();
     } catch (\DomainException $e) {
         $keyName = null;
     }
     $keyName = $keyName ?: 'id';
     $item = $this->getItem();
     if ($sessionData && ArrayHelper::getValue($sessionData, $keyName) == $item->{$keyName}) {
         return $sessionData;
     }
     return $item->dump(true);
 }
 /**
  * Parse variable and replace it. This method is a simple template engine.
  *
  * Example: The {{ foo.bar.yoo }} will be replace to value of `$data['foo']['bar']['yoo']`
  *
  * @param   string $string The template to replace.
  * @param   array  $data   The data to find.
  * @param   array  $tags   The variable tags.
  *
  * @return  string Replaced template.
  */
 public static function render($string, $data = array(), $tags = array('{{', '}}'))
 {
     $defaultTags = array('{{', '}}');
     $tags = (array) $tags + $defaultTags;
     list($begin, $end) = $tags;
     $regex = preg_quote($begin) . '\\s*(.+?)\\s*' . preg_quote($end);
     return preg_replace_callback(chr(1) . $regex . chr(1), function ($match) use($data) {
         $return = ArrayHelper::getByPath($data, $match[1]);
         if (is_array($return) || is_object($return)) {
             return print_r($return, 1);
         } else {
             return $return;
         }
     }, $string);
 }
示例#6
0
 /**
  * compress
  *
  * @return  void
  */
 public function compress()
 {
     // Get assets list from Document
     $list = $this->getStorage();
     $list = ArrayHelper::getColumn($list, 'url');
     // Build assets hash per page.
     $name = $this->buildHash($list);
     // Cache file path.
     $path = $this->getCachePath($name);
     $assetPath = WINDWALKER_PUBLIC . '/' . $this->asset->getAssetFolder() . '/' . $path;
     // Prepare to minify and combine files.
     if (!is_file($assetPath)) {
         // Combine data by file list.
         $data = $this->combineData($list);
         $data = $this->doCompress($data);
         File::write($assetPath, $data);
     }
     $this->addAsset($path);
 }
 /**
  * Do this execute.
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     /** @var ConvertOperator $operator */
     $operator = $this->container->get('operator.factory')->getOperator('convert');
     $replace = ArrayHelper::flatten($this->replace);
     // Flip replace array because we want to convert template.
     $replace = array_flip($replace);
     foreach ($replace as &$val) {
         $val = StringHelper::quote($val, $operator->getTagVariable());
     }
     // Flip src and dest because we want to convert template.
     $src = $this->config['dir.src'];
     $dest = $this->config['dir.dest'];
     if (is_dir($dest)) {
         // Remove dir first
         Folder::delete($dest);
     }
     $operator->copy($src, $dest, $replace);
 }
示例#8
0
 public static function ipBlock()
 {
     $ezset = \Ezset::getInstance();
     $blockType = $ezset->params->get('ipBlock', 0);
     if (!$blockType) {
         return;
     }
     $clients = $ezset->params->get('ipBlockClient');
     if ($ezset->app->isSite() && !in_array('site', $clients)) {
         return;
     }
     if ($ezset->app->isAdmin() && !in_array('administrator', $clients)) {
         return;
     }
     $ips = $ezset->params->get('ipBlockList');
     $ips = explode("\n", $ips);
     $ips = array_map('trim', $ips);
     $ips = static::addLocalhost($ips);
     $block = false;
     $currentIps = array(ArrayHelper::getValue($_SERVER, 'HTTP_CLIENT_IP'), ArrayHelper::getValue($_SERVER, 'HTTP_X_FORWARDED_FOR'), ArrayHelper::getValue($_SERVER, 'REMOTE_ADDR'));
     if (array_intersect($ips, $currentIps)) {
         if ($blockType == 'deny') {
             $block = true;
         }
     } else {
         if ($blockType == 'allow') {
             $block = true;
         }
     }
     $input = \JFactory::getApplication()->input;
     if ($ezset->app->isAdmin()) {
         if (isset($_GET[$ezset->params->get('adminSecureCode')]) || $input->get('task') == 'login' && $input->get('option') == 'com_login') {
             $block = false;
         }
     }
     if (!\JFactory::getUser()->guest && $ezset->app->isAdmin()) {
         $block = false;
     }
     if ($block) {
         header('HTTP/1.1 404');
         die;
     }
 }
示例#9
0
 /**
  * onRouterBeforeRouteMatch
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onRouterBeforeRouteMatch(Event $event)
 {
     /** @var MainRouter $router */
     $router = $event['router'];
     $routing = $this->unidev->loadRouting();
     foreach ($routing as $name => $route) {
         $name = $this->unidev->name . '@' . $name;
         $pattern = ArrayHelper::getValue($route, 'pattern');
         $variables = ArrayHelper::getValue($route, 'variables', array());
         $allowMethods = ArrayHelper::getValue($route, 'method', array());
         if (isset($route['controller'])) {
             $route['extra']['controller'] = $route['controller'];
         }
         if (isset($route['action'])) {
             $route['extra']['action'] = $route['action'];
         }
         if (isset($route['hook'])) {
             $route['extra']['hook'] = $route['hook'];
         }
         $route['extra']['package'] = $this->unidev->name;
         $router->addRoute(new Route($name, $pattern, $variables, $allowMethods, $route));
     }
 }
示例#10
0
文件: test.php 项目: lyrasoft/earth
<?php

/**
 * Part of Windwalker project.
 *
 * @copyright  Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
 * @license    GNU General Public License version 2 or later.
 */
use Windwalker\Utilities\ArrayHelper;
/*
 * Windwalker Web Dev Config
 * -------------------------------------
 * Things you config here will be used in web environment with dev mode.
 */
return ArrayHelper::merge(include __DIR__ . '/web.php', ['packages' => [], 'providers' => ['error' => false], 'routing' => ['files' => []], 'middlewares' => [], 'configs' => [200 => WINDWALKER_ETC . '/dev/config.yml'], 'listeners' => []]);
示例#11
0
文件: web.php 项目: lyrasoft/earth
<?php

/**
 * Part of Windwalker project.
 *
 * @copyright  Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
 * @license    GNU General Public License version 2 or later.
 */
use Windwalker\Utilities\ArrayHelper;
/*
 * Windwalker Web Config
 * -------------------------------------
 * Things you config here will be used in web environment.
 */
return ArrayHelper::merge(include __DIR__ . '/windwalker.php', ['packages' => [], 'providers' => [], 'routing' => ['files' => ['web' => WINDWALKER_ETC . '/routing.yml']], 'middlewares' => [], 'configs' => [], 'listeners' => [500 => \Windwalker\Listener\SystemListener::class], 'error' => ['handlers' => ['log' => \Windwalker\Core\Error\Handler\ErrorLogHandler::class]]]);
示例#12
0
 /**
  * Build route by raw url.
  *
  * @param array &$queries
  *
  * @return  array
  */
 public function buildByRaw(&$queries)
 {
     if (empty($queries['view'])) {
         return array();
     }
     foreach ($this->routes as $view => $map) {
         $vars = $map->getVariables();
         if (ArrayHelper::getValue($vars, 'controller') == $queries['view']) {
             unset($queries['view']);
             return $this->generate($view, $map);
             break;
         }
     }
     return array();
 }
 /**
  * testSetByPath
  *
  * @return  void
  *
  * @covers \Windwalker\Utilities\ArrayHelper::setByPath
  */
 public function testSetByPath()
 {
     $data = array();
     // One level
     $return = ArrayHelper::setByPath($data, 'flower', 'sakura');
     $this->assertEquals('sakura', $data['flower']);
     $this->assertTrue($return);
     // Multi-level
     ArrayHelper::setByPath($data, 'foo.bar', 'test');
     $this->assertEquals('test', $data['foo']['bar']);
     // Separator
     ArrayHelper::setByPath($data, 'foo/bar', 'play', '/');
     $this->assertEquals('play', $data['foo']['bar']);
     // Type
     ArrayHelper::setByPath($data, 'cloud/fly', 'bird', '/', 'stdClass');
     $this->assertEquals('bird', $data['cloud']->fly);
     // False
     $return = ArrayHelper::setByPath($data, '', 'goo');
     $this->assertFalse($return);
     // Fix path
     ArrayHelper::setByPath($data, 'double..separators', 'value');
     $this->assertEquals('value', $data['double']['separators']);
     $this->assertExpectedException(function () {
         ArrayHelper::setByPath($data, 'a.b', 'c', '.', 'Non\\Exists\\Class');
     }, new \InvalidArgumentException(), 'Type or class: Non\\Exists\\Class not exists');
 }
 /**
  * Event after deleted.
  *
  * @param  boolean  $result  The result of deleted.
  *
  * @return  void
  */
 public function onAfterDelete(&$result)
 {
     if (!$result) {
         return;
     }
     $parentTable = $this->parentTable;
     $dataset = $this->deleteTempDataset;
     if ($dataset instanceof \Traversable) {
         $dataset = iterator_to_array($dataset);
     }
     foreach ((array) $dataset as $data) {
         $parentTable->reset();
         $parentTable->bind($data);
         /** @var AbstractRelationHandler $relation */
         foreach ($parentTable->_relation->getRelations() as $relation) {
             $field = $relation->getField();
             $parentTable->{$field} = ArrayHelper::getValue($data, $field);
         }
         $parentTable->_relation->delete();
     }
     $this->deleteTempDataset = null;
 }
 /**
  * doExecute
  *
  * @return mixed
  * 
  * @throws \Exception
  * @throws \Throwable
  */
 protected function doExecute()
 {
     // Get primary key from form data
     $pk = ArrayHelper::getValue((array) $this->data, $this->keyName);
     // If primary key not exists, this is a new record.
     $this->isNew = !$pk;
     $data = $this->getDataObject();
     $data->bind($this->data);
     // Process pre save hook, you may add your own logic in this method
     $this->preSave($data);
     // Just dave it.
     $this->doSave($data);
     // Process post save hook, you may add your own logic in this method
     $this->postSave($data);
     return true;
 }
示例#16
0
 /**
  * appendWhereOr
  *
  * @param   mixed|callable $conditions
  *
  * @return  static
  */
 public function orHaving($conditions)
 {
     $query = $this->db->getQuery(true);
     if (is_callable($conditions)) {
         $conditions($query);
         $having = $query->having->getElements();
         foreach ($query->getBounded() as $key => $bound) {
             $this->bind($key, $bound->value, $bound->dataType, $bound->lengeh, $bound->driverOptions);
         }
     } else {
         $having = (array) $conditions;
         $having = ArrayHelper::flatten($having);
     }
     $having = $query->element('()', $having, ' OR ');
     return $this->having($having);
 }
示例#17
0
<?php

/**
 * Part of Windwalker project.
 *
 * @copyright  Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
 * @license    GNU General Public License version 2 or later.
 */
use Windwalker\Utilities\ArrayHelper;
/*
 * Windwalker Console Config
 * -------------------------------------
 * Things you config here will be used in console environment.
 */
return ArrayHelper::merge(include __DIR__ . '/windwalker.php', ['packages' => ['system' => \Windwalker\SystemPackage\SystemPackage::class], 'providers' => [], 'console' => ['commands' => []], 'configs' => [], 'listeners' => []]);
示例#18
0
    /**
     * getUser
     *
     * @param string $name
     * @param string $label
     * @param string $value
     * @param array  $option
     *
     * @return  string
     */
    public function getUser($name, $label, $value = '', $option = array())
    {
        $left = ArrayHelper::getValue($option, 'left', 3);
        $right = ArrayHelper::getValue($option, 'right', 7);
        $placeholder = ArrayHelper::getValue($option, 'placeholder', $label);
        $disabled = ArrayHelper::getValue($option, 'disabled') ? 'disabled' : '';
        $readonly = ArrayHelper::getValue($option, 'readonly') ? 'readonly' : '';
        return <<<USER
<div class="form-group">
    <label for="input-category" class="col-lg-{$left} control-label">{$label}</label>

    <div class="col-lg-{$right}">
        <div class="input-group">
            {$this->getInput($name, $value, $placeholder, $disabled, $readonly)}

            <span class="input-group-btn">
                <button class="btn btn-primary" type="button"><i class="glyphicon glyphicon-user"></i></button>
            </span>
        </div>
    </div>
</div>
USER;
    }
示例#19
0
{{-- Part of Front project. --}}

<?php 
$socialLogin = (array) $app->get('social_login');
$socialLogin = \Windwalker\Utilities\ArrayHelper::getColumn($socialLogin, 'enabled');
$socialLogin = in_array(true, $socialLogin);
?>

@extends($warderExtends)

@section('content')
    <style>
        #social-login-buttons {
            text-align: center;
        }
        #social-login-buttons button.btn {
            width: 300px;
        }
    </style>
    <div class="container warder-page login-page">
        <div class="row">

            @section('login-content')
                <form id="user-form" class="form-horizontal" action="{{ $router->html('login') }}" method="POST" enctype="multipart/form-data">
                    <div class="col-md-12" style="margin-top: 50px">

                        @yield('login-desc')

                        <div class="row">
                            <div class="col-md-6 {{ $socialLogin ? null : 'col-md-offset-3' }} login-form-wrapper">
                                {!! $form->renderFields() !!}
示例#20
0
 /**
  * backbone
  *
  * @param bool  $noConflict
  * @param array $options
  *
  * @return  void
  */
 public static function backbone($noConflict = false, $options = array())
 {
     $asset = static::getAsset();
     if (!static::inited(__METHOD__)) {
         JQueryScript::core(ArrayHelper::getValue($options, 'jquery_no_conflict', false));
         static::underscore(ArrayHelper::getValue($options, 'jquery_no_conflict', true));
         $asset->addScript(static::phoenixName() . '/js/core/backbone.min.js');
     }
     if (!static::inited(__METHOD__, (bool) $noConflict) && $noConflict) {
         $asset->internalScript(';var backbone = Backbone.noConflict();');
     }
 }
示例#21
0
 /**
  * Method to test merge
  *
  * @covers \Windwalker\Utilities\ArrayHelper::merge
  *
  * @return void
  */
 public function testMerge()
 {
     $data1 = array('green' => 'Hulk', 'red' => 'empty', 'human' => array('dark' => 'empty', 'black' => array('male' => 'empty', 'female' => 'empty', 'no-gender' => 'empty')));
     $data2 = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('female' => 'Black Widow', 'male' => 'Loki')));
     $expected = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'green' => 'Hulk', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('male' => 'Loki', 'female' => 'Black Widow', 'no-gender' => 'empty')));
     $expected2 = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'green' => 'Hulk', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('male' => 'Loki', 'female' => 'Black Widow')));
     $this->assertEquals($expected, ArrayHelper::merge($data1, $data2));
     $this->assertEquals($expected2, ArrayHelper::merge($data1, $data2, false));
 }
示例#22
0
 /**
  * dump
  *
  * @return  void
  */
 public static function dump()
 {
     $list = static::getList();
     $ids = ArrayHelper::getColumn($list, 'id');
     $content = implode(',', $ids);
     File::write(static::getTempPath(), $content);
 }
示例#23
0
    /**
     * highlight
     *
     * @param  string  $selector
     * @param  string  $text
     * @param  array   $options
     *
     * @see  http://bartaz.github.io/sandbox.js/jquery.highlight.html
     *
     * @return  void
     */
    public static function highlight($selector = null, $text = null, $options = array())
    {
        $args = get_defined_vars();
        $asset = static::getAsset();
        if (!static::inited(__METHOD__)) {
            JQueryScript::core();
            $asset->addScript(static::phoenixName() . '/js/jquery/jquery.highlight.js');
        }
        if (!static::inited(__METHOD__, $args) && $selector && $text) {
            if (is_array($text)) {
                $text = implode(' ', $text);
            }
            $defaultOptions = array('element' => 'mark', 'className' => 'phoenix-highlight');
            $options = $asset::getJSObject(ArrayHelper::merge($defaultOptions, $options));
            $js = <<<JS
// Highlight Text
jQuery(document).ready(function(\$)
{
\t\$('{$selector}').highlight('{$text}', {$options});
});
JS;
            $asset->internalScript($js);
        }
    }
示例#24
0
 /**
  * Method to test getTree().
  *
  * @return void
  *
  * @covers Windwalker\Record\NestedRecord::getTree
  */
 public function testGetTree()
 {
     $tree = $this->instance->getTree(1);
     $ids = array(1, 6, 2, 4, 3, 5, 7);
     $this->assertEquals($ids, ArrayHelper::getColumn($tree, 'id'));
 }
示例#25
0
    /**
     * formValidation
     *
     * @param string $selector
     * @param array  $options
     *
     * @return  void
     */
    public static function formValidation($selector = '#admin-form', $options = array())
    {
        if (!static::inited(__METHOD__)) {
            static::core();
            static::addJS(static::phoenixName() . '/js/string/punycode.min.js');
            static::addJS(static::phoenixName() . '/js/phoenix/validation.min.js');
        }
        if (!static::inited(__METHOD__, get_defined_vars())) {
            $defaultOptions = array('scroll' => array('enabled' => true, 'offset' => -100, 'duration' => 1000));
            $options = static::getJSObject(ArrayHelper::merge($defaultOptions, $options));
            static::translate('phoenix.message.validation.required');
            static::translate('phoenix.message.validation.failure');
            $js = <<<JS
// Chosen select
jQuery(document).ready(function(\$)
{
\t\$('{$selector}').validation({$options});
});
JS;
            static::internalJS($js);
        }
    }
 /**
  * Resolve alias.
  *
  * @param   string $class Controller class.
  *
  * @return  string Alias name.
  */
 public function resolveAlias($class)
 {
     return ArrayHelper::getValue($this->aliases, $class, $class);
 }
示例#27
0
文件: dev.php 项目: lyrasoft/earth
<?php

/**
 * Part of Windwalker project.
 *
 * @copyright  Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
 * @license    GNU General Public License version 2 or later.
 */
use Windwalker\Utilities\ArrayHelper;
/*
 * Windwalker Web Dev Config
 * -------------------------------------
 * Things you config here will be used in web environment with dev mode.
 */
return ArrayHelper::merge(include __DIR__ . '/web.php', ['packages' => ['_debugger' => \Windwalker\Debugger\DebuggerPackage::class], 'providers' => ['whoops' => \Windwalker\Core\Provider\WhoopsProvider::class], 'routing' => ['files' => ['dev' => WINDWALKER_ETC . '/dev/routing.yml']], 'middlewares' => [], 'configs' => [200 => WINDWALKER_ETC . '/dev/config.yml'], 'listeners' => []]);