コード例 #1
0
 /**
  * Helper function used to replace query placeholders by the real
  * params used to execute the query
  *
  * @param LoggedQuery $query
  * @return string
  */
 protected function _interpolate($query)
 {
     $params = array_map(function ($p) {
         if ($p === null) {
             return 'NULL';
         }
         return is_string($p) ? "'{$p}'" : $p;
     }, $query->params);
     return String::insert($query->query, $params);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function link($title, $url = null, array $options = array())
 {
     $url = Router::url($url, ['full' => true]);
     if ('html' == $this->getType()) {
         return parent::link($title, $url, $this->_mergeAttributes($options, $this->config('attributes.link')));
     }
     if (empty($url)) {
         return $title;
     }
     $options += ['templates' => []];
     $options['templates'] += ['link' => ':title: :url'];
     return String::insert($options['templates']['link'], compact('title', 'url'));
 }
コード例 #3
0
 /**
  * Prints calculated results
  *
  * @param array $times Array of time values
  * @return void
  */
 protected function _results($times)
 {
     $duration = array_sum($times);
     $requests = count($times);
     $this->out(String::insert(__d('debug_kit', 'Total Requests made: :requests'), compact('requests')));
     $this->out(String::insert(__d('debug_kit', 'Total Time elapsed: :duration (seconds)'), compact('duration')));
     $this->out("");
     $this->out(String::insert(__d('debug_kit', 'Requests/Second: :rps req/sec'), array('rps' => round($requests / $duration, 3))));
     $this->out(String::insert(__d('debug_kit', 'Average request time: :average-time seconds'), array('average-time' => round($duration / $requests, 3))));
     $this->out(String::insert(__d('debug_kit', 'Standard deviation of average request time: :std-dev'), array('std-dev' => round($this->_deviation($times, true), 3))));
     $this->out(String::insert(__d('debug_kit', 'Longest/shortest request: :longest sec/:shortest sec'), array('longest' => round(max($times), 3), 'shortest' => round(min($times), 3))));
     $this->out("");
 }
コード例 #4
0
 public function startup(Event $event)
 {
     if ($this->config('use_session_salt')) {
         if (!$this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) {
             $this->controller->request->session()->write('Alaxos.SpamFilterComponent.salt', String::uuid());
         }
     } elseif ($this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) {
         $this->controller->request->session()->delete('Alaxos.SpamFilterComponent.salt');
     }
     $salt = $this->get_session_salt();
     $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_today_fieldname($salt)]);
     $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_yesterday_fieldname($salt)]);
     /*
      * Pass Session salt to view in order to be available in AlaxosFormHelper
      */
     $this->controller->set('_alaxos_spam_filter_salt', $salt);
 }
コード例 #5
0
 /**
  * Get the help as formatted text suitable for output on the command line.
  *
  * @param int $width The width of the help output.
  * @return string
  */
 public function text($width = 72)
 {
     $parser = $this->_parser;
     $out = [];
     $description = $parser->description();
     if (!empty($description)) {
         $out[] = String::wrap($description, $width);
         $out[] = '';
     }
     $out[] = __d('cake_console', '<info>Usage:</info>');
     $out[] = $this->_generateUsage();
     $out[] = '';
     $subcommands = $parser->subcommands();
     if (!empty($subcommands)) {
         $out[] = __d('cake_console', '<info>Subcommands:</info>');
         $out[] = '';
         $max = $this->_getMaxLength($subcommands) + 2;
         foreach ($subcommands as $command) {
             $out[] = String::wrap($command->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
         $out[] = __d('cake_console', 'To see help on a subcommand use <info>`cake %s [subcommand] --help`</info>', $parser->command());
         $out[] = '';
     }
     $options = $parser->options();
     if (!empty($options)) {
         $max = $this->_getMaxLength($options) + 8;
         $out[] = __d('cake_console', '<info>Options:</info>');
         $out[] = '';
         foreach ($options as $option) {
             $out[] = String::wrap($option->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
     }
     $arguments = $parser->arguments();
     if (!empty($arguments)) {
         $max = $this->_getMaxLength($arguments) + 2;
         $out[] = __d('cake_console', '<info>Arguments:</info>');
         $out[] = '';
         foreach ($arguments as $argument) {
             $out[] = String::wrap($argument->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
     }
     $epilog = $parser->epilog();
     if (!empty($epilog)) {
         $out[] = String::wrap($epilog, $width);
         $out[] = '';
     }
     return implode("\n", $out);
 }
コード例 #6
0
ファイル: Email.php プロジェクト: maitrepylos/nazeweb
 /**
  * Get list of headers
  *
  * ### Includes:
  *
  * - `from`
  * - `replyTo`
  * - `readReceipt`
  * - `returnPath`
  * - `to`
  * - `cc`
  * - `bcc`
  * - `subject`
  *
  * @param array $include List of headers.
  * @return array
  */
 public function getHeaders(array $include = array())
 {
     if ($include == array_values($include)) {
         $include = array_fill_keys($include, true);
     }
     $defaults = array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), false);
     $include += $defaults;
     $headers = array();
     $relation = array('from' => 'From', 'replyTo' => 'Reply-To', 'readReceipt' => 'Disposition-Notification-To', 'returnPath' => 'Return-Path');
     foreach ($relation as $var => $header) {
         if ($include[$var]) {
             $var = '_' . $var;
             $headers[$header] = current($this->_formatAddress($this->{$var}));
         }
     }
     if ($include['sender']) {
         if (key($this->_sender) === key($this->_from)) {
             $headers['Sender'] = '';
         } else {
             $headers['Sender'] = current($this->_formatAddress($this->_sender));
         }
     }
     foreach (array('to', 'cc', 'bcc') as $var) {
         if ($include[$var]) {
             $classVar = '_' . $var;
             $headers[ucfirst($var)] = implode(', ', $this->_formatAddress($this->{$classVar}));
         }
     }
     $headers += $this->_headers;
     if (!isset($headers['X-Mailer'])) {
         $headers['X-Mailer'] = static::EMAIL_CLIENT;
     }
     if (!isset($headers['Date'])) {
         $headers['Date'] = date(DATE_RFC2822);
     }
     if ($this->_messageId !== false) {
         if ($this->_messageId === true) {
             $headers['Message-ID'] = '<' . str_replace('-', '', String::UUID()) . '@' . $this->_domain . '>';
         } else {
             $headers['Message-ID'] = $this->_messageId;
         }
     }
     if ($include['subject']) {
         $headers['Subject'] = $this->_subject;
     }
     $headers['MIME-Version'] = '1.0';
     if (!empty($this->_attachments)) {
         $headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
     } elseif ($this->_emailFormat === 'both') {
         $headers['Content-Type'] = 'multipart/alternative; boundary="' . $this->_boundary . '"';
     } elseif ($this->_emailFormat === 'text') {
         $headers['Content-Type'] = 'text/plain; charset=' . $this->_getContentTypeCharset();
     } elseif ($this->_emailFormat === 'html') {
         $headers['Content-Type'] = 'text/html; charset=' . $this->_getContentTypeCharset();
     }
     $headers['Content-Transfer-Encoding'] = $this->_getContentTransferEncoding();
     return $headers;
 }
コード例 #7
0
 /**
  * testAscii method
  *
  * @return void
  */
 public function testAscii()
 {
     $input = array(33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126);
     $result = String::ascii($input);
     $expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
     $this->assertEquals($expected, $result);
     $input = array(161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200);
     $result = String::ascii($input);
     $expected = '¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
     $this->assertEquals($expected, $result);
     $input = array(201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300);
     $result = String::ascii($input);
     $expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
     $this->assertEquals($expected, $result);
     $input = array(301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400);
     $expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500);
     $expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700);
     $expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051);
     $expected = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100);
     $expected = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1401, 1402, 1403, 1404, 1405, 1406, 1407);
     $expected = 'չպջռսվտ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615);
     $expected = 'فقكلمنهوىيًٌٍَُ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044, 10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057, 10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070, 10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078);
     $expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919, 11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11931, 11932, 11933, 11934, 11935, 11936, 11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952, 11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968, 11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984, 11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000);
     $expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116, 12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132, 12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148, 12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159);
     $expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(45601, 45602, 45603, 45604, 45605, 45606, 45607, 45608, 45609, 45610, 45611, 45612, 45613, 45614, 45615, 45616, 45617, 45618, 45619, 45620, 45621, 45622, 45623, 45624, 45625, 45626, 45627, 45628, 45629, 45630, 45631, 45632, 45633, 45634, 45635, 45636, 45637, 45638, 45639, 45640, 45641, 45642, 45643, 45644, 45645, 45646, 45647, 45648, 45649, 45650, 45651, 45652, 45653, 45654, 45655, 45656, 45657, 45658, 45659, 45660, 45661, 45662, 45663, 45664, 45665, 45666, 45667, 45668, 45669, 45670, 45671, 45672, 45673, 45674, 45675, 45676, 45677, 45678, 45679, 45680, 45681, 45682, 45683, 45684, 45685, 45686, 45687, 45688, 45689, 45690, 45691, 45692, 45693, 45694, 45695, 45696, 45697, 45698, 45699, 45700);
     $expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(65136, 65137, 65138, 65139, 65140, 65141, 65142, 65143, 65144, 65145, 65146, 65147, 65148, 65149, 65150, 65151, 65152, 65153, 65154, 65155, 65156, 65157, 65158, 65159, 65160, 65161, 65162, 65163, 65164, 65165, 65166, 65167, 65168, 65169, 65170, 65171, 65172, 65173, 65174, 65175, 65176, 65177, 65178, 65179, 65180, 65181, 65182, 65183, 65184, 65185, 65186, 65187, 65188, 65189, 65190, 65191, 65192, 65193, 65194, 65195, 65196, 65197, 65198, 65199, 65200);
     $expected = 'ﹰﹱﹲﹳﹴ﹵ﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(65201, 65202, 65203, 65204, 65205, 65206, 65207, 65208, 65209, 65210, 65211, 65212, 65213, 65214, 65215, 65216, 65217, 65218, 65219, 65220, 65221, 65222, 65223, 65224, 65225, 65226, 65227, 65228, 65229, 65230, 65231, 65232, 65233, 65234, 65235, 65236, 65237, 65238, 65239, 65240, 65241, 65242, 65243, 65244, 65245, 65246, 65247, 65248, 65249, 65250, 65251, 65252, 65253, 65254, 65255, 65256, 65257, 65258, 65259, 65260, 65261, 65262, 65263, 65264, 65265, 65266, 65267, 65268, 65269, 65270, 65271, 65272, 65273, 65274, 65275, 65276);
     $expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360, 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370);
     $expected = 'abcdefghijklmnopqrstuvwxyz';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400);
     $expected = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438);
     $expected = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(292, 275, 314, 316, 335, 44, 32, 372, 337, 345, 316, 271, 33);
     $expected = 'Ĥēĺļŏ, Ŵőřļď!';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33);
     $expected = 'Hello, World!';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(168);
     $expected = '¨';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(191);
     $expected = '¿';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(269, 105, 110, 105);
     $expected = 'čini';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(109, 111, 263, 105);
     $expected = 'moći';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(100, 114, 382, 97, 118, 110, 105);
     $expected = 'državni';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(25226, 30334, 24230, 35774, 20026, 39318, 39029);
     $expected = '把百度设为首页';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(19968, 20108, 19977, 21608, 27704, 40845);
     $expected = '一二三周永龍';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298);
     $expected = 'ԀԂԄԆԈԊԌԎԐԒ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1296, 1298);
     $expected = 'ԁԃԅԇԉԋԍԏԐԒ';
     $result = String::ascii($input);
     $this->assertEquals($expected, $result);
     $input = array(1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1415);
     $result = String::ascii($input);
     $expected = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
     $this->assertEquals($expected, $result);
     $input = array(1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415);
     $result = String::ascii($input);
     $expected = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
     $this->assertEquals($expected, $result);
     $input = array(4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293);
     $result = String::ascii($input);
     $expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
     $this->assertEquals($expected, $result);
     $input = array(7680, 7682, 7684, 7686, 7688, 7690, 7692, 7694, 7696, 7698, 7700, 7702, 7704, 7706, 7708, 7710, 7712, 7714, 7716, 7718, 7720, 7722, 7724, 7726, 7728, 7730, 7732, 7734, 7736, 7738, 7740, 7742, 7744, 7746, 7748, 7750, 7752, 7754, 7756, 7758, 7760, 7762, 7764, 7766, 7768, 7770, 7772, 7774, 7776, 7778, 7780, 7782, 7784, 7786, 7788, 7790, 7792, 7794, 7796, 7798, 7800, 7802, 7804, 7806, 7808, 7810, 7812, 7814, 7816, 7818, 7820, 7822, 7824, 7826, 7828, 7830, 7831, 7832, 7833, 7834, 7840, 7842, 7844, 7846, 7848, 7850, 7852, 7854, 7856, 7858, 7860, 7862, 7864, 7866, 7868, 7870, 7872, 7874, 7876, 7878, 7880, 7882, 7884, 7886, 7888, 7890, 7892, 7894, 7896, 7898, 7900, 7902, 7904, 7906, 7908, 7910, 7912, 7914, 7916, 7918, 7920, 7922, 7924, 7926, 7928);
     $result = String::ascii($input);
     $expected = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
     $this->assertEquals($expected, $result);
     $input = array(7681, 7683, 7685, 7687, 7689, 7691, 7693, 7695, 7697, 7699, 7701, 7703, 7705, 7707, 7709, 7711, 7713, 7715, 7717, 7719, 7721, 7723, 7725, 7727, 7729, 7731, 7733, 7735, 7737, 7739, 7741, 7743, 7745, 7747, 7749, 7751, 7753, 7755, 7757, 7759, 7761, 7763, 7765, 7767, 7769, 7771, 7773, 7775, 7777, 7779, 7781, 7783, 7785, 7787, 7789, 7791, 7793, 7795, 7797, 7799, 7801, 7803, 7805, 7807, 7809, 7811, 7813, 7815, 7817, 7819, 7821, 7823, 7825, 7827, 7829, 7830, 7831, 7832, 7833, 7834, 7841, 7843, 7845, 7847, 7849, 7851, 7853, 7855, 7857, 7859, 7861, 7863, 7865, 7867, 7869, 7871, 7873, 7875, 7877, 7879, 7881, 7883, 7885, 7887, 7889, 7891, 7893, 7895, 7897, 7899, 7901, 7903, 7905, 7907, 7909, 7911, 7913, 7915, 7917, 7919, 7921, 7923, 7925, 7927, 7929);
     $result = String::ascii($input);
     $expected = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
     $this->assertEquals($expected, $result);
     $input = array(8486, 8490, 8491, 8498);
     $result = String::ascii($input);
     $expected = 'ΩKÅℲ';
     $this->assertEquals($expected, $result);
     $input = array(969, 107, 229, 8526);
     $result = String::ascii($input);
     $expected = 'ωkåⅎ';
     $this->assertEquals($expected, $result);
     $input = array(8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8579);
     $result = String::ascii($input);
     $expected = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
     $this->assertEquals($expected, $result);
     $input = array(8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8580);
     $result = String::ascii($input);
     $expected = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
     $this->assertEquals($expected, $result);
     $input = array(9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414, 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423);
     $result = String::ascii($input);
     $expected = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
     $this->assertEquals($expected, $result);
     $input = array(9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441, 9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449);
     $result = String::ascii($input);
     $expected = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
     $this->assertEquals($expected, $result);
     $input = array(11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278, 11279, 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293, 11294, 11295, 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308, 11309, 11310);
     $result = String::ascii($input);
     $expected = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
     $this->assertEquals($expected, $result);
     $input = array(11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327, 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343, 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358);
     $result = String::ascii($input);
     $expected = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
     $this->assertEquals($expected, $result);
     $input = array(11392, 11394, 11396, 11398, 11400, 11402, 11404, 11406, 11408, 11410, 11412, 11414, 11416, 11418, 11420, 11422, 11424, 11426, 11428, 11430, 11432, 11434, 11436, 11438, 11440, 11442, 11444, 11446, 11448, 11450, 11452, 11454, 11456, 11458, 11460, 11462, 11464, 11466, 11468, 11470, 11472, 11474, 11476, 11478, 11480, 11482, 11484, 11486, 11488, 11490);
     $result = String::ascii($input);
     $expected = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
     $this->assertEquals($expected, $result);
     $input = array(11393, 11395, 11397, 11399, 11401, 11403, 11405, 11407, 11409, 11411, 11413, 11415, 11417, 11419, 11421, 11423, 11425, 11427, 11429, 11431, 11433, 11435, 11437, 11439, 11441, 11443, 11445, 11447, 11449, 11451, 11453, 11455, 11457, 11459, 11461, 11463, 11465, 11467, 11469, 11471, 11473, 11475, 11477, 11479, 11481, 11483, 11485, 11487, 11489, 11491);
     $result = String::ascii($input);
     $expected = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
     $this->assertEquals($expected, $result);
     $input = array(64256, 64257, 64258, 64259, 64260, 64261, 64262, 64275, 64276, 64277, 64278, 64279);
     $result = String::ascii($input);
     $expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
     $this->assertEquals($expected, $result);
 }
コード例 #8
0
ファイル: Validation.php プロジェクト: maitrepylos/nazeweb
 /**
  * Checks the filesize
  *
  * @param string|array $check Value to check.
  * @param string $operator See `Validation::comparison()`.
  * @param int|string $size Size in bytes or human readable string like '5MB'.
  * @return bool Success
  */
 public static function fileSize($check, $operator = null, $size = null)
 {
     if (is_array($check) && isset($check['tmp_name'])) {
         $check = $check['tmp_name'];
     }
     if (is_string($size)) {
         $size = String::parseFileSize($size);
     }
     $filesize = filesize($check);
     return static::comparison($filesize, $operator, $size);
 }
コード例 #9
0
ファイル: I18n.php プロジェクト: ripzappa0924/carte0.0.1
 /**
  * Auxiliary function to parse a symbol from a locale definition file
  *
  * @param string $string Symbol to be parsed
  * @return string parsed symbol
  */
 protected function _parseLiteralValue($string)
 {
     $string = $string[1];
     if (substr($string, 0, 2) === $this->_escape . 'x') {
         $delimiter = $this->_escape . 'x';
         return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
     }
     if (substr($string, 0, 2) === $this->_escape . 'd') {
         $delimiter = $this->_escape . 'd';
         return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
     }
     if ($string[0] === $this->_escape && isset($string[1]) && is_numeric($string[1])) {
         $delimiter = $this->_escape;
         return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
     }
     if (substr($string, 0, 3) === 'U00') {
         $delimiter = 'U00';
         return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
     }
     if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) {
         return String::ascii(array(hexdec($match[1])));
     }
     return $string;
 }
コード例 #10
0
ファイル: Debugger.php プロジェクト: ripzappa0924/carte0.0.1
 /**
  * Takes a processed array of data from an error and displays it in the chosen format.
  *
  * @param string $data
  * @return void
  */
 public function outputError($data)
 {
     $defaults = array('level' => 0, 'error' => 0, 'code' => 0, 'description' => '', 'file' => '', 'line' => 0, 'context' => array(), 'start' => 2);
     $data += $defaults;
     $files = $this->trace(array('start' => $data['start'], 'format' => 'points'));
     $code = '';
     $file = null;
     if (isset($files[0]['file'])) {
         $file = $files[0];
     } elseif (isset($files[1]['file'])) {
         $file = $files[1];
     }
     if ($file) {
         $code = $this->excerpt($file['file'], $file['line'] - 1, 1);
     }
     $trace = $this->trace(array('start' => $data['start'], 'depth' => '20'));
     $insertOpts = array('before' => '{:', 'after' => '}');
     $context = array();
     $links = array();
     $info = '';
     foreach ((array) $data['context'] as $var => $value) {
         $context[] = "\${$var} = " . $this->exportVar($value, 3);
     }
     switch ($this->_outputFormat) {
         case false:
             $this->_data[] = compact('context', 'trace') + $data;
             return;
         case 'log':
             $this->log(compact('context', 'trace') + $data);
             return;
     }
     $data['trace'] = $trace;
     $data['id'] = 'cakeErr' . uniqid();
     $tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]);
     if (isset($tpl['links'])) {
         foreach ($tpl['links'] as $key => $val) {
             $links[$key] = String::insert($val, $data, $insertOpts);
         }
     }
     if (!empty($tpl['escapeContext'])) {
         $context = h($context);
     }
     $infoData = compact('code', 'context', 'trace');
     foreach ($infoData as $key => $value) {
         if (empty($value) || !isset($tpl[$key])) {
             continue;
         }
         if (is_array($value)) {
             $value = implode("\n", $value);
         }
         $info .= String::insert($tpl[$key], array($key => $value) + $data, $insertOpts);
     }
     $links = implode(' ', $links);
     if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
         return call_user_func($tpl['callback'], $data, compact('links', 'info'));
     }
     echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
 }
コード例 #11
0
ファイル: UuidType.php プロジェクト: maitrepylos/nazeweb
 /**
  * Generate a new UUID
  *
  * @return string A new primary key value.
  */
 public function newId()
 {
     return String::uuid();
 }
コード例 #12
0
 /**
  * Simulates direct writing to a system file by creating the file in /tmp
  * using default credentials, then shelling a `mv` to the desired location
  * as root.
  *
  * @param string $file Full path to the file to write.
  * @param string $content Containing file body.
  * @return boolean True if the write is successful
  */
 protected function _writeSystemFile($file, $content)
 {
     $this->_log("Writing system file");
     $tempFile = '/tmp/' . String::uuid();
     $fh = new File($tempFile, true);
     $fh->write($content);
     // Move the tempfile
     if (!$this->shell("mv {$tempFile} {$file}", 'root')) {
         $this->_error("* Error moving {$tempFile} to {$file}");
         return false;
     }
     $this->_log("* Successfully wrote {$file}");
     return true;
 }
コード例 #13
0
ファイル: RenameString.php プロジェクト: cakephp/upgrade
 /**
  * Just a testing method
  *
  * @return void
  */
 public function testing()
 {
     Hash::extract();
     $alias = String::uuid();
     $full = \Cake\Utility\String::truncate($param1, $param2);
 }
コード例 #14
0
 /**
  * Set the cookie in the response.
  *
  * Also sets the request->params['_csrfToken'] so the newly minted
  * token is available in the request data.
  *
  * @param \Cake\Network\Request $request The request object.
  * @param \Cake\Network\Response $response The response object.
  */
 protected function _setCookie(Request $request, Response $response)
 {
     $value = Security::hash(String::uuid(), 'sha1', true);
     $request->params['_csrfToken'] = $value;
     $response->cookie(['name' => $this->_config['cookieName'], 'value' => $value, 'expiry' => $this->_config['expiry'], 'path' => $request->base, 'secure' => $this->_config['secure']]);
 }
コード例 #15
0
ファイル: Shell.php プロジェクト: maitrepylos/nazeweb
 /**
  * Wrap a block of text.
  * Allows you to set the width, and indenting on a block of text.
  *
  * ### Options
  *
  * - `width` The width to wrap to. Defaults to 72
  * - `wordWrap` Only wrap on words breaks (spaces) Defaults to true.
  * - `indent` Indent the text with the string provided. Defaults to null.
  *
  * @param string $text Text the text to format.
  * @param int|array $options Array of options to use, or an integer to wrap the text to.
  * @return string Wrapped / indented text
  * @see String::wrap()
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapText
  */
 public function wrapText($text, $options = [])
 {
     return String::wrap($text, $options);
 }
コード例 #16
0
ファイル: FileLog.php プロジェクト: maitrepylos/nazeweb
 /**
  * Sets protected properties based on config provided
  *
  * @param array $config Configuration array
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     if (!empty($this->_config['path'])) {
         $this->_path = $this->_config['path'];
     }
     if (Configure::read('debug') && !is_dir($this->_path)) {
         mkdir($this->_path, 0775, true);
     }
     if (!empty($this->_config['file'])) {
         $this->_file = $this->_config['file'];
         if (substr($this->_file, -4) !== '.log') {
             $this->_file .= '.log';
         }
     }
     if (!empty($this->_config['size'])) {
         if (is_numeric($this->_config['size'])) {
             $this->_size = (int) $this->_config['size'];
         } else {
             $this->_size = String::parseFileSize($this->_config['size']);
         }
     }
 }
コード例 #17
0
ファイル: UploaderBehavior.php プロジェクト: eripoll/webiplan
 public function getUploadPath(Entity $entity, $path, $extension)
 {
     $replace = array('%uuid' => String::uuid(), '%id' => $entity->id, '%y' => date('Y'), '%m' => date('m'), '/' => DS);
     $path = $this->_config['assets_dir'] . DS . Inflector::tableize($entity->source()) . DS . strtr($path, $replace) . '.' . $extension;
     return $path;
 }
コード例 #18
0
ファイル: String.php プロジェクト: maitrepylos/nazeweb
 /**
  * Cleans up a String::insert() formatted string with given $options depending on the 'clean' key in
  * $options. The default method used is text but html is also available. The goal of this function
  * is to replace all whitespace and unneeded markup around placeholders that did not get replaced
  * by String::insert().
  *
  * @param string $str String to clean.
  * @param array $options Options list.
  * @return string
  * @see String::insert()
  */
 public static function cleanInsert($str, array $options)
 {
     $clean = $options['clean'];
     if (!$clean) {
         return $str;
     }
     if ($clean === true) {
         $clean = array('method' => 'text');
     }
     if (!is_array($clean)) {
         $clean = array('method' => $options['clean']);
     }
     switch ($clean['method']) {
         case 'html':
             $clean += array('word' => '[\\w,.]+', 'andText' => true, 'replacement' => '');
             $kleenex = sprintf('/[\\s]*[a-z]+=(")(%s%s%s[\\s]*)+\\1/i', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'));
             $str = preg_replace($kleenex, $clean['replacement'], $str);
             if ($clean['andText']) {
                 $options['clean'] = array('method' => 'text');
                 $str = String::cleanInsert($str, $options);
             }
             break;
         case 'text':
             $clean += array('word' => '[\\w,.]+', 'gap' => '[\\s]*(?:(?:and|or)[\\s]*)?', 'replacement' => '');
             $kleenex = sprintf('/(%s%s%s%s|%s%s%s%s)/', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'), $clean['gap'], $clean['gap'], preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'));
             $str = preg_replace($kleenex, $clean['replacement'], $str);
             break;
     }
     return $str;
 }
コード例 #19
0
ファイル: FixtureTask.php プロジェクト: maitrepylos/nazeweb
 /**
  * Generate String representation of Records
  *
  * @param \Cake\Database\Schema\Table $table Table schema array
  * @param int $recordCount The number of records to generate.
  * @return array Array of records to use in the fixture.
  */
 protected function _generateRecords(Table $table, $recordCount = 1)
 {
     $records = [];
     for ($i = 0; $i < $recordCount; $i++) {
         $record = [];
         foreach ($table->columns() as $field) {
             $fieldInfo = $table->column($field);
             $insert = '';
             switch ($fieldInfo['type']) {
                 case 'integer':
                 case 'float':
                     $insert = $i + 1;
                     break;
                 case 'string':
                 case 'binary':
                     $isPrimary = in_array($field, $table->primaryKey());
                     if ($isPrimary) {
                         $insert = String::uuid();
                     } else {
                         $insert = "Lorem ipsum dolor sit amet";
                         if (!empty($fieldInfo['length'])) {
                             $insert = substr($insert, 0, (int) $fieldInfo['length'] - 2);
                         }
                     }
                     break;
                 case 'timestamp':
                     $insert = time();
                     break;
                 case 'datetime':
                     $insert = date('Y-m-d H:i:s');
                     break;
                 case 'date':
                     $insert = date('Y-m-d');
                     break;
                 case 'time':
                     $insert = date('H:i:s');
                     break;
                 case 'boolean':
                     $insert = 1;
                     break;
                 case 'text':
                     $insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
                     $insert .= " Convallis morbi fringilla gravida,";
                     $insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
                     $insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
                     $insert .= " vestibulum massa neque ut et, id hendrerit sit,";
                     $insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
                     $insert .= " duis vestibulum nunc mattis convallis.";
                     break;
             }
             $record[$field] = $insert;
         }
         $records[] = $record;
     }
     return $records;
 }
コード例 #20
0
 /**
  * Função auxiliar para montar a estrutura HTML do flexslider.
  * @param array $slides Um array com as informações de cada slide.
  * Formato:
  * $slides = array(
  * 				0 => array(
  *     					'img_src' => '/my/img/source/file.jpg'
  *          			'img_title' => 'The Image Title',
  *             			'img_description' => 'This is the description of the awesome image',
  *          			'img_options' => array(the_options),
  *             			'img_link' => 'http://www.thecoolwebsite.com/',
  *                		'link_options' => array(the_options),
  *                  	'li_options' => array(the_options),
  *          			  ),
  *               ....
  * );
  * 'img_src': É o caminho da imagem a partir de webroot/img.
  * 'img_options': Opções para a imagem (html tag <img>). Mesmo formato para a função HtmlHelper::image().
  * 'img_title': O título da imagem.
  * 'img_description': A descrição da imagem.
  * 'img_link': A url para onde o link irá apontar.
  * 'link_options': Opções para o link (html tag <a>). Mesmo formato para a função HtmlHelper::link().
  * 'li_options': Opções para a tag li. Quando for necessário uma configuração diferente para um slide (li) específico, use esta opção. Esta opção sobrescreve a opção global para tag li. array de opções como em HtmlHelper::tag().
  * 
  * @param  array $options Um array com opções de configuração.
  * Formato:
  * $options = array(
  * 				'div' => array(the_options),
  *     			'ul' => array(the_options),
  *        		'li' => array(the_options),
  *        		'slide_template' => ':link_image<p class='my_class'>:description</p>',
  *          	'webroot' => 'site',
  * );
  * 'div': array de opções como em HtmlHelper::tag().
  * 'ul': array de opções como em HtmlHelper::tag().
  * 'li': array de opções como em HtmlHelper::tag().
  * 'webroot': string, 'app' ou 'site', para escolher de qual webroot será lido a imagem. Se é do app ou se é do plugin Site.
  * 'slide_template': a formatação do li, caso precise alterá-lo. Padrão ':image'. Não informar <li></li>.
  * Em slide_template há "variáveis" que podem ser usadas, sendo elas:
  * :link_image Um exemplo de saída seria <a href="/to/my/page"><img src="/myimg.jpg"></a>
  * :image  <img src="/myimg.jpg">
  * :description Uma string para ser usada como descrição.
  * :title Uma string para ser usada como título.
  * @throws  InvalidArgumentException Caso $slides[x]['img_src'] esteja vazio, ele lança uma exception.
  * @return  string Toda a estrutura do flexslider em HTML com cada slide de acordo com os valores informados por parâmetro.
  */
 public function flexslider($slides, $options = array())
 {
     // validações iniciais
     if (!isset($options['slide_template'])) {
         $options['slide_template'] = ':image';
     }
     if (!isset($options['li'])) {
         $options['li'] = array();
     }
     if (!isset($options['webroot'])) {
         $options['webroot'] = 'site';
     }
     switch ($options['webroot']) {
         case 'app':
             $webDir = '';
             break;
         case 'site':
         default:
             $webDir = 'Site.';
     }
     $options['div'] = $this->checkFlexSliderDivOptions($options);
     $options['ul'] = $this->checkFlexSliderUlOptions($options);
     // gera o <li> primeiro
     $liHtml = '';
     foreach ($slides as $slide) {
         // verifica se existe opções para a tag <img>, senão existe, cria um array vazio para não dar problema.
         if (!isset($slide['img_options'])) {
             $slide['img_options'] = array();
         }
         // verifica se existe opções para a tag <a>, senão existe, cria um array com a opção escape => false. Se existe ele faz um merge com a opção escape => false.
         if (!isset($slide['link_options'])) {
             $slide['link_options'] = array('escape' => false);
         } else {
             $slide['link_options'] = Hash::merge($slide['link_options'], array('escape' => false));
         }
         // verifica se existe descrição, senão existe, cria uma string vazia.
         if (!isset($slide['img_description'])) {
             $slide['img_description'] = '';
         }
         // verifica se existe titulo, senão existe, cria uma string vazia.
         if (!isset($slide['img_title'])) {
             $slide['img_title'] = '';
         }
         // verifica se existe opção específica para o slide(li). Se existe, junta essas opções com as opções globais e guarda para ser usado ao criar o elemento li. Senão, guarda as opções globais para serem usadas.
         if (isset($slide['li_options'])) {
             $liOptions = array_merge($options['li'], $slide['li_options']);
         } else {
             $liOptions = $options['li'];
         }
         $image = $this->Html->image($webDir . $slide['img_src'], $slide['img_options']);
         if (isset($slide['image_link'])) {
             $image_link = $this->Html->link($image, $slide['image_link'], $slide['link_options']);
         } else {
             $image_link = '';
         }
         $liContent = String::insert($options['slide_template'], array('image' => $image, 'image_link' => $image_link, 'description' => $slide['img_description'], 'title' => $slide['img_title']));
         $liHtml .= $this->Html->tag('li', $liContent, $liOptions);
     }
     // depois gera o <ul> e coloca os <li> dentro do <ul>
     $ulHtml = $this->Html->tag('ul', $liHtml, $options['ul']);
     // depois gera a <div> final e coloca o <ul> dentro dela.
     $generatedHtml = $this->Html->tag('div', $ulHtml, $options['div']);
     // finished!
     return $generatedHtml;
 }
コード例 #21
0
ファイル: Security.php プロジェクト: maitrepylos/nazeweb
 /**
  * Generate authorization hash.
  *
  * @return string Hash
  */
 public static function generateAuthKey()
 {
     return Security::hash(String::uuid());
 }
コード例 #22
0
ファイル: StringTest.php プロジェクト: maitrepylos/nazeweb
 /**
  * testparseFileSizeException
  *
  * @expectedException InvalidArgumentException
  * @return void
  */
 public function testparseFileSizeException()
 {
     String::parseFileSize('bogus', false);
 }