function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid ResultLookup', true)); $this->redirect(array('action' => 'index')); } if (!empty($this->data)) { parent::archive($id); $this->data = Set::insert($this->data, 'ResultLookup.user_id', $this->Auth->user('id')); if ($this->ResultLookup->save($this->data)) { $this->Session->setFlash(__('The ResultLookup has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The ResultLookup could not be saved. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->ResultLookup->read(null, $id); $test_id = $this->data['ResultLookup']['test_id']; $this->set('test_id', $test_id); $this->set('id', $id); } $tests = $this->ResultLookup->Test->find('list'); $this->set(compact('tests')); }
/** * Used to store a dynamic variable in the Configure instance. * * Usage: * {{{ * Configure::write('One.key1', 'value of the Configure::One[key1]'); * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); * Configure::write('One', array( * 'key1' => 'value of the Configure::One[key1]', * 'key2' => 'value of the Configure::One[key2]' * ); * * Configure::write(array( * 'One.key1' => 'value of the Configure::One[key1]', * 'One.key2' => 'value of the Configure::One[key2]' * )); * }}} * * @link http://book.cakephp.org/view/926/write * @param array $config Name of var to write * @param mixed $value Value to set for var * @return boolean True if write was successful * @access public */ public static function write($config, $value = null) { $_this =& Configure::getInstance(); if (!is_array($config)) { $config = array($config => $value); } foreach ($config as $name => $value) { if (strpos($name, '.') === false) { $_this->{$name} = $value; } else { $names = explode('.', $name, 4); switch (count($names)) { case 2: $_this->{$names[0]}[$names[1]] = $value; break; case 3: $_this->{$names[0]}[$names[1]][$names[2]] = $value; break; case 4: $names = explode('.', $name, 2); if (!isset($_this->{$names[0]})) { $_this->{$names[0]} = array(); } $_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value); break; } } } return true; }
/** * Permet d'écrire une donnée dans la session * * @param varchar $key Clée de la donnée * @param mixed $value Donnée à écrire * @return boolean Vrai si la valeur est insérée, faux sinon * @access static * @author koéZionCMS * @version 0.1 - 30/12/2011 * @see /Koezion/lib/set.php */ static function write($key, $value) { $session = Set::insert($_SESSION, $key, $value); //On insère les données et on récupère la nouvelle variable de session $_SESSION = $session; //On affecte les données à la variable de session return Set::classicExtract($_SESSION, $key) === $value; //On retourne le résultat de la fonction }
/** * @param string $path * @param mixed $data * @param bool $forUser * @return void */ public function write($path = '', $data, $forUser = true) { if (!$path) { return; } $path = $this->_getPath($path, $forUser); $__cookie = $this->_getGummCookie(); if (strpos($path, '.') === false) { $__cookie[$path] = $data; } else { $__cookie = Set::insert($__cookie, $path, $data); } $this->_storeGummCookie($__cookie); }
function _parseTrueToDefault($config) { $_this =& CaptchaConfig::getInstance(); $trueToDefault = Set::normalize($_this->trueToDefault); foreach ($trueToDefault as $path => $options) { if (Set::extract($path, $config) === true) { if (empty($options)) { $options = Set::extract($path, $_this->defaultConfig); } $config = Set::insert($config, $path, $options); } } return $config; }
/** * After find callback * @param $result array * @result $result array */ function afterFind($results) { $results2[0]['Preference'] = Configure::read('Preference'); $skip = array('user_id', 'created', 'modified', 'id'); foreach ($results[0]['Preference'] as $key => $value) { if (isset($value) && !is_null($value)) { if (!in_array($key, $skip)) { $key = str_replace('_', '.', $key); $results2[0]['Preference'] = Set::insert($results2[0]['Preference'], $key, $value); } else { $results2[0]['Preference'][$key] = $value; } } } return $results2; }
function extractHierarchicMulti($pathsAssoc, $data = null, $options = array()) { $defaultOptions = array('extractNull' => true); $options = array_merge($defaultOptions, $options); $res = array(); foreach ($pathsAssoc as $name => $paths) { $val = SetMulti::extractHierarchic($paths, $data, $options); if (!is_null($val) || $options['extractNull']) { if (is_numeric($name)) { $res[$name] = $val; } else { $res = Set::insert($res, $name, $val); } } } return $res; }
/** * Connects to the database. Options are specified in the $config instance variable. * * @return boolean Connected. * @throws MissingConnectionException */ public function connect() { if ($this->connected !== true) { if (Set::check($this->config, 'login')) { $this->config = Set::insert($this->config, 'request.uri.user', Set::get($this->config, 'login')); } if (Set::check($this->config, 'password')) { $this->config = Set::insert($this->config, 'request.uri.pass', Set::get($this->config, 'password')); } try { $this->Socket = new HttpSocket($this->config); $this->connected = true; } catch (SocketException $e) { throw new MissingConnectionException(array('class' => $e->getMessage())); } } return $this->connected; }
/** * Add a menu item * * @param string $path dot separated path in the array. * @param array $options menu options array * @return void */ public static function add($path, $options) { $pathE = explode('.', $path); $pathE = array_splice($pathE, 0, count($pathE) - 2); $parent = join('.', $pathE); if (!empty($parent) && !Set::check(self::$_items, $parent)) { $title = Inflector::humanize(end($pathE)); $o = array('title' => $title); self::_setupOptions($o); self::add($parent, $o); } self::_setupOptions($options); $current = Set::extract($path, self::$_items); if (!empty($current)) { self::_replace(self::$_items, $path, $options); } else { self::$_items = Set::insert(self::$_items, $path, $options); } }
function calcAllFormAResults($sub_num = null) { $allFormAResults = null; $allTeachers = $this->query("select id,username,name from users as User where group_id=2"); $i = 1; foreach ($allTeachers as $teacher) { $teachersResults = $this->calcFormAResults($teacher['User']['id'], $sub_num); if (!is_string($teachersResults) && isset($teachersResults)) { foreach ($teachersResults as $teachersResult) { if (!is_string($teachersResult)) { $teachersResult['teacherUserName'] = $teacher['User']['username']; $teachersResult['teacherName'] = $teacher['User']['name']; $allFormAResults = Set::insert($allFormAResults, $i++, $teachersResult); } } } } //debug($allFormAResults); return $allFormAResults; }
function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid Test', true)); $this->redirect(array('action' => 'index')); } if (!empty($this->data)) { parent::archive($id); $this->data = Set::insert($this->data, 'Test.user_id', $this->Auth->user('id')); if ($this->Test->save($this->data)) { $this->Session->setFlash(__('The Test has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The Test could not be saved. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->Test->read(null, $id); } }
function get_vol_horaire_a_attribuer_with_loop($id = 'all') { // Méthode 3 if ($id == null or $id == 'all') { // à l'aide d'une requête find all et d'une boucle $temp = $this->find('all'); $result = array(); foreach ($temp as $key => $matiere) { $matiere_id = $matiere['Matiere']['id']; $result = Set::insert($result, $matiere_id, array('h_cours' => $matiere['Matiere']['h_cours'], 'h_td' => $matiere['Matiere']['h_td'] * $matiere['Filiere']['nb_gr_td'], 'h_tp' => $matiere['Matiere']['h_tp'] * $matiere['Filiere']['nb_gr_tp'])); } return $result; } else { // à l'aide d'une requête read recursive et du calcul heure_matiere*nb_gr $this->recursive = 0; $matiere = $this->read(null, $id); $result = array('h_cours' => $matiere['Matiere']['h_cours'], 'h_td' => $matiere['Matiere']['h_td'] * $matiere['Filiere']['nb_gr_td'], 'h_tp' => $matiere['Matiere']['h_tp'] * $matiere['Filiere']['nb_gr_tp']); return $result; } }
function getBilanServiceWithSqlView($id = 'all') { // Méthode 1 : à l'aide d'une vue SQL dans la base $this->VuePersosBilanServices =& ClassRegistry::init('VuePersosBilanServices'); $this->VuePersosBilanServices->recursive = -1; if ($id == 'all' or $id == null) { $temp = $this->VuePersosBilanServices->find('all'); // ToDo : mettre en forme l'array pour avoir perso_id comme clé //$temp=Set::combine($temp, '{n}.VuePersosBilanServices.id', '{n}.VuePersosBilanServices.h_tp'); $result = array(); foreach ($temp as $key => $matieresperso) { //debug($result($matieresperso['VuePersosBilanServices']['id'])=1); //$result($matieresperso['VuePersosBilanServices']['id'])=$matieresperso['VuePersosBilanServices']['h_cours']; $result = Set::insert($result, $matieresperso['VuePersosBilanServices']['id'], array('h_cours' => $matieresperso['VuePersosBilanServices']['h_cours'], 'h_td' => $matieresperso['VuePersosBilanServices']['h_td'], 'h_tp' => $matieresperso['VuePersosBilanServices']['h_tp'])); } return $result; //return $temp; } else { $temp = $this->VuePersosBilanServices->read(null, $id); return $temp['VuePersosBilanServices']; } }
function __combine_array($arr1, $arr2) { $number = count($arr1); // find the first index for the next result foreach ($arr2 as $element2) { $test = true; foreach ($arr1 as $element1) { if ($element1 == $element2) { $test = false; break; } } if ($test) { $arr1 = Set::insert($arr1, '\\' . $number, $element2); } $number += 1; } return $arr1; }
/** * Writes value to given session variable name. * * @param mixed $name Name of variable * @param string $value Value to write * @return boolean True if the write was successful, false if the write failed * @access public */ public function write($name, $value) { if (empty($name)) { return false; } if (in_array($name, $this->watchKeys)) { trigger_error(sprintf(__('Writing session key {%s}: %s', true), $name, Debugger::exportVar($value)), E_USER_NOTICE); } $this->__overwrite($_SESSION, Set::insert($_SESSION, $name, $value)); return Set::classicExtract($_SESSION, $name) === $value; }
/** * Provides a read/write accessor for `$this->data`. Allows you * to use a syntax similar to `CakeSession` for reading post data. * * ## Reading values. * * `$request->data('Post.title');` * * When reading values you will get `null` for keys/values that do not exist. * * ## Writing values * * `$request->data('Post.title', 'New post!');` * * You can write to any value, even paths/keys that do not exist, and the arrays * will be created for you. * * @param string $name,... Dot separated name of the value to read/write * @return mixed Either the value being read, or this so you can chain consecutive writes. */ public function data($name) { $args = func_get_args(); if (count($args) == 2) { $this->data = Set::insert($this->data, $name, $args[1]); return $this; } return Set::classicExtract($this->data, $name); }
/** * Tests that HttpSocket::request (the heart of the HttpSocket) is working properly. * */ function testRequest() { $this->Socket->reset(); $this->Socket->reset(); $response = $this->Socket->request(true); $this->assertFalse($response); $tests = array(0 => array('request' => 'http://www.cakephp.org/?foo=bar', 'expectation' => array('config' => array('persistent' => false, 'host' => 'www.cakephp.org', 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30, 'request' => array('uri' => array('scheme' => 'http', 'host' => 'www.cakephp.org', 'port' => 80), 'auth' => array('method' => 'basic', 'user' => null, 'pass' => null), 'cookies' => array())), 'request' => array('method' => 'GET', 'uri' => array('scheme' => 'http', 'host' => 'www.cakephp.org', 'port' => 80, 'user' => null, 'pass' => null, 'path' => '/', 'query' => array('foo' => 'bar'), 'fragment' => null), 'auth' => array('method' => 'basic', 'user' => null, 'pass' => null), 'version' => '1.1', 'body' => '', 'line' => "GET /?foo=bar HTTP/1.1\r\n", 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n", 'raw' => "", 'cookies' => array()))), 1 => array('request' => array('uri' => array('host' => 'www.cakephp.org', 'query' => '?foo=bar'))), 2 => array('request' => 'www.cakephp.org/?foo=bar'), 3 => array('request' => array('host' => '192.168.0.1', 'uri' => 'http://www.cakephp.org/?foo=bar'), 'expectation' => array('request' => array('uri' => array('host' => 'www.cakephp.org')), 'config' => array('request' => array('uri' => array('host' => 'www.cakephp.org')), 'host' => '192.168.0.1'))), 'reset4' => array('request.uri.query' => array()), 4 => array('request' => array('header' => array('Foo@woo' => 'bar-value')), 'expectation' => array('request' => array('header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n", 'line' => "GET / HTTP/1.1\r\n"))), 5 => array('request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/'), 'expectation' => array('request' => array('header' => "Host: foo.com\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"), 'config' => array('host' => 'www.cakephp.org'))), 6 => array('request' => array('header' => "Foo: bar\r\n"), 'expectation' => array('request' => array('header' => "Foo: bar\r\n"))), 7 => array('request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me'), 'expectation' => array('request' => array('uri' => array('path' => '/search', 'query' => array('q' => 'http_socket'), 'fragment' => 'ignore-me'), 'line' => "GET /search?q=http_socket HTTP/1.1\r\n"))), 'reset8' => array('request.uri.query' => array()), 8 => array('request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')), 'expectation' => array('request' => array('method' => 'POST', 'uri' => array('path' => '/posts/add', 'fragment' => null), 'body' => "name=HttpSocket-is-released&date=today", 'line' => "POST /posts/add HTTP/1.1\r\n", 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n", 'raw' => "name=HttpSocket-is-released&date=today"))), 9 => array('request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')), 'expectation' => array('config' => array('port' => 443, 'request' => array('uri' => array('scheme' => 'https', 'port' => 443))), 'request' => array('uri' => array('scheme' => 'https', 'port' => 443)))), 10 => array('request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'), 'cookies' => array('foo' => array('value' => 'bar'))), 'expectation' => array('request' => array('header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n", 'cookies' => array('foo' => array('value' => 'bar')))))); $expectation = array(); foreach ($tests as $i => $test) { if (strpos($i, 'reset') === 0) { foreach ($test as $path => $val) { $expectation = Set::insert($expectation, $path, $val); } continue; } if (isset($test['expectation'])) { $expectation = Set::merge($expectation, $test['expectation']); } $this->Socket->request($test['request']); $raw = $expectation['request']['raw']; $expectation['request']['raw'] = $expectation['request']['line'] . $expectation['request']['header'] . "\r\n" . $raw; $r = array('config' => $this->Socket->config, 'request' => $this->Socket->request); $v = $this->assertIdentical($r, $expectation, '%s in test #' . $i . ' '); if (!$v) { debug('Result:'); debug($r); debug('Expected:'); debug($expectation); } $expectation['request']['raw'] = $raw; } $this->Socket->reset(); $request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')); $response = $this->Socket->request($request); $this->assertIdentical($this->Socket->request['body'], "name=HttpSocket-is-released&date=today"); $request = array('uri' => '*', 'method' => 'GET'); $this->expectError(new PatternExpectation('/activate quirks mode/i')); $response = $this->Socket->request($request); $this->assertFalse($response); $this->assertFalse($this->Socket->response); $this->Socket->reset(); $request = array('uri' => 'htpp://www.cakephp.org/'); $this->Socket->setReturnValue('connect', true); $this->Socket->setReturnValue('read', false); $this->Socket->_mock->_call_counts['read'] = 0; $number = mt_rand(0, 9999999); $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>"; $this->Socket->setReturnValueAt(0, 'read', $serverResponse); $this->Socket->expect('write', array("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n")); $this->Socket->expectCallCount('read', 2); $response = $this->Socket->request($request); $this->assertIdentical($response, "<h1>Hello, your lucky number is " . $number . "</h1>"); $this->Socket->reset(); $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a cookie test!</h1>"; unset($this->Socket->_mock->_actions->_at['read']); $this->Socket->_mock->_call_counts['read'] = 0; $this->Socket->setReturnValueAt(0, 'read', $serverResponse); $this->Socket->connected = true; $this->Socket->request($request); $result = $this->Socket->response['cookies']; $expect = array('foo' => array('value' => 'bar')); $this->assertEqual($result, $expect); $this->assertEqual($this->Socket->config['request']['cookies'], $expect); $this->assertFalse($this->Socket->connected); }
/** * parses nested values out of keys. * * @param array $values Values to be exploded. * @return array Array of values exploded */ protected function _parseNestedValues($values) { foreach ($values as $key => $value) { if ($value === '1') { $value = true; } if ($value === '') { $value = false; } if (strpos($key, '.') !== false) { $values = Set::insert($values, $key, $value); } else { $values[$key] = $value; } } return $values; }
/** * Tests that HttpSocket::request (the heart of the HttpSocket) is working properly. * * @return void */ public function testRequest() { $this->Socket->reset(); $response = $this->Socket->request(true); $this->assertFalse($response); $tests = array(array('request' => 'http://www.cakephp.org/?foo=bar', 'expectation' => array('config' => array('persistent' => false, 'host' => 'www.cakephp.org', 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30, 'request' => array('uri' => array('scheme' => 'http', 'host' => 'www.cakephp.org', 'port' => 80), 'cookies' => array())), 'request' => array('method' => 'GET', 'uri' => array('scheme' => 'http', 'host' => 'www.cakephp.org', 'port' => 80, 'user' => null, 'pass' => null, 'path' => '/', 'query' => array('foo' => 'bar'), 'fragment' => null), 'version' => '1.1', 'body' => '', 'line' => "GET /?foo=bar HTTP/1.1\r\n", 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n", 'raw' => "", 'cookies' => array(), 'proxy' => array(), 'auth' => array()))), array('request' => array('uri' => array('host' => 'www.cakephp.org', 'query' => '?foo=bar'))), array('request' => 'www.cakephp.org/?foo=bar'), array('request' => array('host' => '192.168.0.1', 'uri' => 'http://www.cakephp.org/?foo=bar'), 'expectation' => array('request' => array('uri' => array('host' => 'www.cakephp.org')), 'config' => array('request' => array('uri' => array('host' => 'www.cakephp.org')), 'host' => '192.168.0.1'))), 'reset4' => array('request.uri.query' => array()), array('request' => array('header' => array('Foo@woo' => 'bar-value')), 'expectation' => array('request' => array('header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n", 'line' => "GET / HTTP/1.1\r\n"))), array('request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/'), 'expectation' => array('request' => array('header' => "Host: foo.com\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"), 'config' => array('host' => 'www.cakephp.org'))), array('request' => array('header' => "Foo: bar\r\n"), 'expectation' => array('request' => array('header' => "Foo: bar\r\n"))), array('request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me'), 'expectation' => array('request' => array('uri' => array('path' => '/search', 'query' => array('q' => 'http_socket'), 'fragment' => 'ignore-me'), 'line' => "GET /search?q=http_socket HTTP/1.1\r\n"))), 'reset8' => array('request.uri.query' => array()), array('request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')), 'expectation' => array('request' => array('method' => 'POST', 'uri' => array('path' => '/posts/add', 'fragment' => null), 'body' => "name=HttpSocket-is-released&date=today", 'line' => "POST /posts/add HTTP/1.1\r\n", 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n", 'raw' => "name=HttpSocket-is-released&date=today"))), array('request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')), 'expectation' => array('config' => array('port' => 8080, 'request' => array('uri' => array('port' => 8080))), 'request' => array('uri' => array('port' => 8080), 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"))), array('request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')), 'expectation' => array('config' => array('port' => 443, 'request' => array('uri' => array('scheme' => 'https', 'port' => 443))), 'request' => array('uri' => array('scheme' => 'https', 'port' => 443), 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"))), array('request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'), 'cookies' => array('foo' => array('value' => 'bar'))), 'expectation' => array('request' => array('header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n", 'cookies' => array('foo' => array('value' => 'bar')))))); $expectation = array(); foreach ($tests as $i => $test) { if (strpos($i, 'reset') === 0) { foreach ($test as $path => $val) { $expectation = Set::insert($expectation, $path, $val); } continue; } if (isset($test['expectation'])) { $expectation = Set::merge($expectation, $test['expectation']); } $this->Socket->request($test['request']); $raw = $expectation['request']['raw']; $expectation['request']['raw'] = $expectation['request']['line'] . $expectation['request']['header'] . "\r\n" . $raw; $r = array('config' => $this->Socket->config, 'request' => $this->Socket->request); $v = $this->assertEquals($r, $expectation, 'Failed test #' . $i . ' '); $expectation['request']['raw'] = $raw; } $this->Socket->reset(); $request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')); $response = $this->Socket->request($request); $this->assertEquals($this->Socket->request['body'], "name=HttpSocket-is-released&date=today"); }
function _multiParseAttributes($data, $keys, $default = array()) { $def = array('exclude' => null, 'insertBefore' => ' ', 'insertAfter' => null, 'isolate' => false); $def = array_merge($def, $default); if ($def['isolate']) { $attrs = array(); } else { $attrs = $data; } foreach (Set::normalize($keys) as $key => $opt) { $opt = array_merge($def, (array) $opt); if (Set::check($data, $key)) { $parsed = false; $unparsed = Set::extract($key, $data); if ($unparsed !== false) { $parsed = $this->_parseAttributes($unparsed, $opt['exclude'], $opt['insertBefore'], $opt['insertAfter']); } $attrs = Set::insert($attrs, $key, $parsed); } } return $attrs; }
/** * Write a value to the $_COOKIE[$key]; * * Optional [Name.], required key, optional $value, optional $encrypt, optional $expires * $this->Cookie->write('[Name.]key, $value); * * By default all values are encrypted. * You must pass $encrypt false to store values in clear test * * You must use this method before any output is sent to the browser. * Failure to do so will result in header already sent errors. * * @param mixed $key * Key for the value * @param mixed $value * Value * @param boolean $encrypt * Set to true to encrypt value, false otherwise * @param string $expires * Can be either Unix timestamp, or date string * @access public */ function write($key, $value = null, $encrypt = true, $expires = null) { if (is_null($encrypt)) { $encrypt = true; } $this->__encrypted = $encrypt; $this->__expire($expires); if (!is_array($key)) { $key = array($key => $value); } foreach ($key as $name => $value) { if (strpos($name, '.') === false) { $this->__values[$name] = $value; $this->__write("[{$name}]", $value); } else { $names = explode('.', $name, 2); if (!isset($this->__values[$names[0]])) { $this->__values[$names[0]] = array(); } $this->__values[$names[0]] = Set::insert($this->__values[$names[0]], $names[1], $value); $this->__write('[' . implode('][', $names) . ']', $value); } } $this->__encrypted = true; }
/** * testBehaviorSaveCallbacks method * * @access public * @return void */ function testBehaviorSaveCallbacks() { $Sample = new Sample(); $record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99')); $Sample->Behaviors->attach('Test', array('beforeSave' => 'on')); $Sample->create(); $this->assertIdentical($Sample->save($record), false); $Sample->Behaviors->attach('Test', array('beforeSave' => 'off')); $Sample->create(); $this->assertIdentical($Sample->save($record), $record); $Sample->Behaviors->attach('Test', array('beforeSave' => 'test')); $Sample->create(); $this->assertIdentical($Sample->save($record), $record); $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify')); $expected = Set::insert($record, 'Sample.name', 'sample99 modified before'); $Sample->create(); $this->assertIdentical($Sample->save($record), $expected); $Sample->Behaviors->disable('Test'); $this->assertIdentical($Sample->save($record), $record); $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on')); $expected = Set::merge($record, array('Sample' => array('aftersave' => 'modified after on create'))); $Sample->create(); $this->assertIdentical($Sample->save($record), $expected); $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify')); $expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create'))); $Sample->create(); $this->assertIdentical($Sample->save($record), $expected); $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test')); $Sample->create(); $this->assertIdentical($Sample->save($record), $record); $Sample->Behaviors->attach('Test', array('afterSave' => 'test2')); $Sample->create(); $this->assertIdentical($Sample->save($record), $record); $Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off')); $Sample->recursive = -1; $record2 = $Sample->read(null, 1); $Sample->Behaviors->attach('Test', array('afterSave' => 'on')); $expected = Set::merge($record2, array('Sample' => array('aftersave' => 'modified after'))); $Sample->create(); $this->assertIdentical($Sample->save($record2), $expected); $Sample->Behaviors->attach('Test', array('afterSave' => 'modify')); $expected = Set::merge($record2, array('Sample' => array('name' => 'sample1 modified after'))); $Sample->create(); $this->assertIdentical($Sample->save($record2), $expected); }
/** * Used to store a dynamic variable in Configure. * * Usage: * {{{ * Configure::write('One.key1', 'value of the Configure::One[key1]'); * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); * Configure::write('One', array( * 'key1' => 'value of the Configure::One[key1]', * 'key2' => 'value of the Configure::One[key2]' * ); * * Configure::write(array( * 'One.key1' => 'value of the Configure::One[key1]', * 'One.key2' => 'value of the Configure::One[key2]' * )); * }}} * * @link http://book.cakephp.org/view/926/write * @param array $config Name of var to write * @param mixed $value Value to set for var * @return boolean True if write was successful */ public static function write($config, $value = null) { if (!is_array($config)) { $config = array($config => $value); } foreach ($config as $name => $value) { if (strpos($name, '.') === false) { self::$_values[$name] = $value; } else { $names = explode('.', $name, 4); switch (count($names)) { case 2: self::$_values[$names[0]][$names[1]] = $value; break; case 3: self::$_values[$names[0]][$names[1]][$names[2]] = $value; break; case 4: $names = explode('.', $name, 2); if (!isset(self::$_values[$names[0]])) { self::$_values[$names[0]] = array(); } self::$_values[$names[0]] = Set::insert(self::$_values[$names[0]], $names[1], $value); break; } } } if (isset($config['debug']) && function_exists('ini_set')) { if (self::$_values['debug']) { ini_set('display_errors', 1); } else { ini_set('display_errors', 0); } } return true; }
/** * Recursively walks the FILES array restructuring the data * into something sane and useable. * * @param string $path The dot separated path to insert $data into. * @param array $data The data to traverse/insert. * @param string $field The terminal field name, which is the top level key in $_FILES. * @return void */ protected function _processFileData($path, $data, $field) { foreach ($data as $key => $fields) { $newPath = $key; if (!empty($path)) { $newPath = $path . '.' . $key; } if (is_array($fields)) { $this->_processFileData($newPath, $fields, $field); } else { $newPath .= '.' . $field; $this->data = Set::insert($this->data, $newPath, $fields); } } }
/** * Used to store a dynamic variable in the Configure instance. * * Usage: * {{{ * Configure::write('One.key1', 'value of the Configure::One[key1]'); * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); * Configure::write('One', array( * 'key1' => 'value of the Configure::One[key1]', * 'key2' => 'value of the Configure::One[key2]' * ); * * Configure::write(array( * 'One.key1' => 'value of the Configure::One[key1]', * 'One.key2' => 'value of the Configure::One[key2]' * )); * }}} * * @link http://book.cakephp.org/view/926/write * @param array $config Name of var to write * @param mixed $value Value to set for var * @return boolean True if write was successful * @access public */ function write($config, $value = null) { $_this =& Configure::getInstance(); if (!is_array($config)) { $config = array($config => $value); } foreach ($config as $name => $value) { if (strpos($name, '.') === false) { $_this->{$name} = $value; } else { $names = explode('.', $name, 4); switch (count($names)) { case 2: $_this->{$names[0]}[$names[1]] = $value; break; case 3: $_this->{$names[0]}[$names[1]][$names[2]] = $value; break; case 4: $names = explode('.', $name, 2); if (!isset($_this->{$names[0]})) { $_this->{$names[0]} = array(); } $_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value); break; } } } if (isset($config['debug']) || isset($config['log'])) { $reporting = 0; if ($_this->debug) { if (!class_exists('Debugger')) { require LIBS . 'debugger.php'; } $reporting = E_ALL & ~E_DEPRECATED; if (function_exists('ini_set')) { ini_set('display_errors', 1); } } elseif (function_exists('ini_set')) { ini_set('display_errors', 0); } if (isset($_this->log) && $_this->log) { if (is_integer($_this->log) && !$_this->debug) { $reporting = $_this->log; } else { $reporting = E_ALL & ~E_DEPRECATED; } error_reporting($reporting); if (!class_exists('CakeLog')) { require LIBS . 'cake_log.php'; } } error_reporting($reporting); } return true; }
/** * Writes value to given session variable name. * * @param mixed $name Name of variable * @param string $value Value to write * @return boolean True if the write was successful, false if the write failed * @access public */ function write($name, $value) { $var = $this->__validateKeys($name); if (empty($var)) { return false; } if (in_array($var, $this->watchKeys)) { trigger_error('Writing session key {' . $var . '}: ' . Debugger::exportVar($value), E_USER_NOTICE); } $this->__overwrite($_SESSION, Set::insert($_SESSION, $var, $value)); return Set::extract($_SESSION, $var) === $value; }
/** * testWritingWithFunkyKeys method * * @return void */ public function testWritingWithFunkyKeys() { $set = Set::insert(array(), 'Session Test', "test"); $this->assertEquals('test', Set::extract($set, 'Session Test')); $set = Set::remove($set, 'Session Test'); $this->assertFalse(Set::check($set, 'Session Test')); $expected = array('Session Test' => array('Test Case' => 'test')); $this->assertEquals($expected, Set::insert(array(), 'Session Test.Test Case', "test")); $this->assertTrue(Set::check($expected, 'Session Test.Test Case')); }
/** * testWritingWithFunkyKeys method * * @access public * @return void */ function testWritingWithFunkyKeys() { $set = Set::insert(array(), 'Session Test', "test"); $this->assertEqual(Set::extract($set, 'Session Test'), 'test'); $set = Set::remove($set, 'Session Test'); $this->assertFalse(Set::check($set, 'Session Test')); $this->assertTrue($set = Set::insert(array(), 'Session Test.Test Case', "test")); $this->assertTrue(Set::check($set, 'Session Test.Test Case')); }
/** * Writes value to given session variable name. * * @param mixed $name Name of variable * @param string $value Value to write * @return boolean True if the write was successful, false if the write failed */ public static function write($name, $value = null) { if (!self::started() && !self::start()) { return false; } if (empty($name)) { return false; } $write = $name; if (!is_array($name)) { $write = array($name => $value); } foreach ($write as $key => $val) { self::__overwrite($_SESSION, Set::insert($_SESSION, $key, $val)); if (Set::classicExtract($_SESSION, $key) !== $val) { return false; } } return true; }
/** * Reformats data according to Xpaths in $take * * @param array $take * @param array $viewVars * * @return array */ public function inject ($take, $viewVars) { $data = array(); foreach ($take as $path => $dest) { if (is_numeric($path)) { $path = $dest; } $data = Set::insert($data, $dest, Set::extract($path, $viewVars)); } return $data; }