예제 #1
0
 /**
  * Test removing multiple values.
  *
  * @return void
  */
 public function testRemoveMulti()
 {
     $data = static::articleData();
     $result = Hash::remove($data, '{n}.Article.title');
     $this->assertFalse(isset($result[0]['Article']['title']));
     $this->assertFalse(isset($result[1]['Article']['title']));
     $result = Hash::remove($data, '{n}.Article.{s}');
     $this->assertFalse(isset($result[0]['Article']['id']));
     $this->assertFalse(isset($result[0]['Article']['user_id']));
     $this->assertFalse(isset($result[0]['Article']['title']));
     $this->assertFalse(isset($result[0]['Article']['body']));
     $data = [0 => ['Item' => ['id' => 1, 'title' => 'first']], 1 => ['Item' => ['id' => 2, 'title' => 'second']], 2 => ['Item' => ['id' => 3, 'title' => 'third']], 3 => ['Item' => ['id' => 4, 'title' => 'fourth']], 4 => ['Item' => ['id' => 5, 'title' => 'fifth']]];
     $result = Hash::remove($data, '{n}.Item[id=/\\b2|\\b4/]');
     $expected = [0 => ['Item' => ['id' => 1, 'title' => 'first']], 2 => ['Item' => ['id' => 3, 'title' => 'third']], 4 => ['Item' => ['id' => 5, 'title' => 'fifth']]];
     $this->assertEquals($expected, $result);
     $data[3]['testable'] = true;
     $result = Hash::remove($data, '{n}[testable].Item[id=/\\b2|\\b4/].title');
     $expected = [0 => ['Item' => ['id' => 1, 'title' => 'first']], 1 => ['Item' => ['id' => 2, 'title' => 'second']], 2 => ['Item' => ['id' => 3, 'title' => 'third']], 3 => ['Item' => ['id' => 4], 'testable' => true], 4 => ['Item' => ['id' => 5, 'title' => 'fifth']]];
     $this->assertEquals($expected, $result);
 }
예제 #2
0
파일: Session.php 프로젝트: cakephp/cakephp
 /**
  * Removes a variable from session.
  *
  * @param string $name Session variable to remove
  * @return void
  */
 public function delete($name)
 {
     if ($this->check($name)) {
         $this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
     }
 }
예제 #3
0
 /**
  * Delete a cookie value
  *
  * You must use this method before any output is sent to the browser.
  * Failure to do so will result in header already sent errors.
  *
  * Deleting a top level key will delete all keys nested within that key.
  * For example deleting the `User` key, will also delete `User.email`.
  *
  * @param string $key Key of the value to be deleted
  * @return void
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::delete
  */
 public function delete($key)
 {
     $this->_load($key);
     $this->_values = Hash::remove($this->_values, $key);
     $parts = explode('.', $key);
     $top = $parts[0];
     if (isset($this->_values[$top])) {
         $this->_write($top, $this->_values[$top]);
     } else {
         $this->_delete($top);
     }
 }
예제 #4
0
파일: Configure.php 프로젝트: lhas/pep
 /**
  * Used to delete a variable from Configure.
  *
  * Usage:
  * ```
  * Configure::delete('Name'); will delete the entire Configure::Name
  * Configure::delete('Name.key'); will delete only the Configure::Name[key]
  * ```
  *
  * @param string $var the var to be deleted
  * @return void
  * @link http://book.cakephp.org/3.0/en/development/configuration.html#deleting-configuration-data
  */
 public static function delete($var)
 {
     static::$_values = Hash::remove(static::$_values, $var);
 }
 /**
  * Extract from the request the given field and return it.
  *
  * @param  string $field name of the field to be extracted from the upload(s).
  * @return array|false
  */
 protected function _uploadArrayPer($field = '')
 {
     if (empty($field)) {
         $field = $this->_upField;
     }
     $data = $this->request->data;
     $uploadArray = Hash::get($data, 'UploadDocuments.file.' . $field);
     $data = Hash::remove($data, 'UploadDocuments.file' . $field);
     if (empty($uploadArray)) {
         return false;
     }
     $data = Hash::insert($data, 'UploadDocuments.file', $uploadArray);
     return $data;
 }
예제 #6
0
파일: Setting.php 프로젝트: crabstudio/app
 /**
  * Used to cache delete a key from Setting.
  *
  * Usage:
  * ```
  * Setting::delete('Name'); will delete the entire Setting::Name
  * Setting::delete('Name.key'); will delete only the Setting::Name[key]
  * ```
  *
  * @param string $key the key to be deleted
  * @return void
  */
 public static function delete($key)
 {
     self::$_data = Hash::remove(self::$_data, $key);
 }
예제 #7
0
 /**
  * Remove the data at the specified path from the tool set
  * 
  * @param string $path
  * @return array
  */
 public function remove($path)
 {
     return Hash::remove($this->_tools, $path);
 }
예제 #8
0
파일: env.php 프로젝트: themogwi/app
<?php

use Cake\Utility\Hash;
use josegonzalez\Dotenv\Loader;
$config = [];
if (!env('APP_NAME')) {
    $dotenv = new Loader([__DIR__ . DS . '.env', __DIR__ . DS . '.env.default']);
    $dotenv->setFilters(['josegonzalez\\Dotenv\\Filter\\LowercaseKeyFilter', 'josegonzalez\\Dotenv\\Filter\\UppercaseFirstKeyFilter', 'josegonzalez\\Dotenv\\Filter\\UnderscoreArrayFilter', function ($data) {
        $keys = ['Debug' => 'debug', 'Emailtransport' => 'EmailTransport', 'Database' => 'Datasources.default', 'Test.database' => 'Datasources.test', 'Test' => null, 'Cache.duration' => null, 'Cache.cakemodel' => 'Cache._cake_model_', 'Cache.cakecore' => 'Cache._cake_core_'];
        foreach ($keys as $key => $newKey) {
            if ($newKey === null) {
                $data = Hash::remove($data, $key);
                continue;
            }
            $value = Hash::get($data, $key);
            $data = Hash::remove($data, $key);
            $data = Hash::insert($data, $newKey, $value);
        }
        return $data;
    }]);
    $dotenv->parse();
    $dotenv->filter();
    $config = $dotenv->toArray();
}
return $config;
예제 #9
0
 /**
  * Used to read and delete a variable from Configure.
  *
  * This is primarily used during bootstrapping to move configuration data
  * out of configure into the various other classes in CakePHP.
  *
  * @param string $var The key to read and remove.
  * @return array|null
  */
 public static function consume($var)
 {
     $simple = strpos($var, '.') === false;
     if ($simple && !isset(static::$_values[$var])) {
         return null;
     }
     if ($simple) {
         $value = static::$_values[$var];
         unset(static::$_values[$var]);
         return $value;
     }
     $value = Hash::get(static::$_values, $var);
     static::$_values = Hash::remove(static::$_values, $var);
     return $value;
 }
예제 #10
0
 /**
  * Test removing multiple values.
  *
  * @return void
  */
 public function testRemoveMulti()
 {
     $data = static::articleData();
     $result = Hash::remove($data, '{n}.Article.title');
     $this->assertFalse(isset($result[0]['Article']['title']));
     $this->assertFalse(isset($result[1]['Article']['title']));
     $result = Hash::remove($data, '{n}.Article.{s}');
     $this->assertFalse(isset($result[0]['Article']['id']));
     $this->assertFalse(isset($result[0]['Article']['user_id']));
     $this->assertFalse(isset($result[0]['Article']['title']));
     $this->assertFalse(isset($result[0]['Article']['body']));
     $data = array(0 => array('Item' => array('id' => 1, 'title' => 'first')), 1 => array('Item' => array('id' => 2, 'title' => 'second')), 2 => array('Item' => array('id' => 3, 'title' => 'third')), 3 => array('Item' => array('id' => 4, 'title' => 'fourth')), 4 => array('Item' => array('id' => 5, 'title' => 'fifth')));
     $result = Hash::remove($data, '{n}.Item[id=/\\b2|\\b4/]');
     $expected = array(0 => array('Item' => array('id' => 1, 'title' => 'first')), 2 => array('Item' => array('id' => 3, 'title' => 'third')), 4 => array('Item' => array('id' => 5, 'title' => 'fifth')));
     $this->assertEquals($expected, $result);
 }
예제 #11
0
 /**
  * Delete a cookie value
  *
  * Optional [Name.], required key
  * $this->Cookie->delete('Name.key);
  *
  * You must use this method before any output is sent to the browser.
  * Failure to do so will result in header already sent errors.
  *
  * This method will delete both the top level and 2nd level cookies set.
  * For example assuming that $name = App, deleting `User` will delete
  * both `App[User]` and any other cookie values like `App[User][email]`
  * This is done to clean up cookie storage from before 2.4.3, where cookies
  * were stored inconsistently.
  *
  * @param string $key Key of the value to be deleted
  * @return void
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::delete
  */
 public function delete($key)
 {
     $cookieName = $this->config('name');
     if (empty($this->_values[$cookieName])) {
         $this->read();
     }
     if (strpos($key, '.') === false) {
         if (isset($this->_values[$cookieName][$key]) && is_array($this->_values[$cookieName][$key])) {
             foreach ($this->_values[$cookieName][$key] as $idx => $val) {
                 $this->_delete("[{$key}][{$idx}]");
             }
         }
         $this->_delete("[{$key}]");
         unset($this->_values[$cookieName][$key]);
         return;
     }
     $names = explode('.', $key, 2);
     if (isset($this->_values[$cookieName][$names[0]])) {
         $this->_values[$cookieName][$names[0]] = Hash::remove($this->_values[$cookieName][$names[0]], $names[1]);
     }
     $this->_delete('[' . implode('][', $names) . ']');
 }
예제 #12
0
 /**
  * Removes a variable from session.
  *
  * @param string $name Session variable to remove
  * @return bool Success
  */
 public static function delete($name)
 {
     if (static::check($name)) {
         static::_overwrite($_SESSION, Hash::remove($_SESSION, $name));
         return !static::check($name);
     }
     return false;
 }
예제 #13
0
파일: Nav.php 프로젝트: UnionCMS/Core
 /**
  * Remove a menu item.
  *
  * @param string $path dot separated path in the array.
  * @return void
  */
 public static function remove($path)
 {
     self::$_items = Hash::remove(self::$_items, $path);
 }
예제 #14
0
 public function section()
 {
     $settings = TableRegistry::get('Settings');
     $users = TableRegistry::get('Users');
     $sectionForm = new SectionForm();
     $session = $this->request->session();
     $now = Time::now();
     $user = $users->get($this->Auth->user('id'));
     if ($this->request->is('get')) {
         $apiId = $settings->get('10')->text;
         $apiToken = $settings->get('11')->text;
         $apiBase = $settings->get('12')->text;
         if (empty($user->osm_secret) || !$session->check('OSM.Secret')) {
             $this->Flash->error(__('Please link your account first'));
             return $this->redirect(['action' => 'link']);
         } else {
             $userOsmId = $user->osm_user_id;
             $userOsmSecret = $user->osm_secret . $session->read('OSM.Secret');
         }
         $http = new Client(['host' => $apiBase, 'scheme' => 'https']);
         $url = '/api.php?action=getUserRoles';
         $response = $http->post($url, ['userid' => $userOsmId, 'secret' => $userOsmSecret, 'token' => $apiToken, 'apiid' => $apiId]);
         if ($response->isOk()) {
             $body = $response->json;
             $this->set(compact('body'));
             $body = Hash::remove($body, '{n}.sectionConfig');
             $body = Hash::remove($body, '{n}.permissions');
             $hsec = Hash::combine($body, '{n}.sectionid', '{n}.sectionname');
             $this->set(compact('hsec'));
         } else {
             $this->Flash->error(__('There was a request error, please try again.'));
             return $this->redirect(['action' => 'home']);
         }
     }
     if ($this->request->is('post')) {
         $osmSection = $this->request->data['osm_section'];
         $usrData = ['osm_section_id' => $osmSection, 'osm_linked' => 2];
         $users->patchEntity($user, $usrData);
         if ($users->save($user)) {
             $this->Flash->success(__('You have selected your OSM section.'));
             if (!empty($user->osm_current_term) && $user->osm_term_end > $now) {
                 return $this->redirect(['action' => 'home']);
             } else {
                 return $this->redirect(['action' => 'term']);
             }
         } else {
             $this->Flash->error(__('The user could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('sectionForm'));
 }