当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeNumber类代码示例

本文整理汇总了PHP中CakeNumber的典型用法代码示例。如果您正苦于以下问题:PHP CakeNumber类的具体用法?PHP CakeNumber怎么用?PHP CakeNumber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CakeNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: standardFormat

 /**
  * Transforms $number into a standard format.
  *
  * 	12345.67	=	12,346
  *
  * @param integer $number The number to format.
  * @param string $before The text to put in front of the number Default is ''.
  * @param integer $places The number to decimal places to show. Default is 0.
  * @return string The formated number.
  * @access public
  * @static
  */
 public static function standardFormat($number, $before = '', $places = 0)
 {
     if ($places === 0) {
         $number = round($number);
     }
     return CakeNumber::format($number, array('before' => $before, 'places' => $places));
 }
开发者ID:quentinhill,项目名称:bedrock,代码行数:19,代码来源:BedrockNumber.php

示例2: unzip

 /**
  * キャビネットファイルのUnzip
  *
  * @param Model $model CabinetFile
  * @param array $cabinetFile CabinetFileデータ
  * @return bool
  * @throws InternalErrorException
  */
 public function unzip(Model $model, $cabinetFile)
 {
     $model->begin();
     try {
         // テンポラリフォルダにunzip
         $zipPath = WWW_ROOT . $cabinetFile['UploadFile']['file']['path'] . $cabinetFile['UploadFile']['file']['id'] . DS . $cabinetFile['UploadFile']['file']['real_file_name'];
         //debug($zipPath);
         App::uses('UnZip', 'Files.Utility');
         $unzip = new UnZip($zipPath);
         $tmpFolder = $unzip->extract();
         if ($tmpFolder === false) {
             throw new InternalErrorException('UnZip Failed.');
         }
         $parentCabinetFolder = $model->find('first', ['conditions' => ['CabinetFileTree.id' => $cabinetFile['CabinetFileTree']['parent_id']]]);
         // unzipされたファイル拡張子のバリデーション
         // unzipされたファイルのファイルサイズバリデーション
         $files = $tmpFolder->findRecursive();
         $unzipTotalSize = 0;
         foreach ($files as $file) {
             //
             $unzipTotalSize += filesize($file);
             // ここでは拡張子だけチェックする
             $extension = pathinfo($file, PATHINFO_EXTENSION);
             if (!$model->isAllowUploadFileExtension($extension)) {
                 // NG
                 $model->validationErrors = [__d('cabinets', 'Unzip failed. Contains does not allow file format.')];
                 return false;
             }
         }
         // ルームファイルサイズ制限
         $maxRoomDiskSize = Current::read('Space.room_disk_size');
         if ($maxRoomDiskSize !== null) {
             // nullだったらディスクサイズ制限なし。null以外ならディスクサイズ制限あり
             // 解凍後の合計
             // 現在のルームファイルサイズ
             $roomId = Current::read('Room.id');
             $roomFileSize = $model->getTotalSizeByRoomId($roomId);
             if ($roomFileSize + $unzipTotalSize > $maxRoomDiskSize) {
                 $model->validationErrors[] = __d('cabinets', 'Failed to expand. The total size exceeds the limit.<br />' . 'The total size limit is %s (%s left).', CakeNumber::toReadableSize($roomFileSize + $unzipTotalSize), CakeNumber::toReadableSize($maxRoomDiskSize));
                 return false;
             }
         }
         // 再帰ループで登録処理
         list($folders, $files) = $tmpFolder->read(true, false, true);
         foreach ($files as $file) {
             $this->_addFileFromPath($model, $parentCabinetFolder, $file);
         }
         foreach ($folders as $folder) {
             $this->_addFolderFromPath($model, $parentCabinetFolder, $folder);
         }
     } catch (Exception $e) {
         return $model->rollback($e);
     }
     $model->commit();
     return true;
 }
开发者ID:NetCommons3,项目名称:Cabinets,代码行数:64,代码来源:CabinetUnzipBehavior.php

示例3: startup

 /**
  * Called after the Controller::beforeFilter() and before the controller action
  *
  * @param Controller $controller Controller with components to startup
  * @return void
  */
 public function startup(Controller $controller)
 {
     // ファイルアップロード等で post_max_size を超えると $_POSTが空っぽになるため、このタイミングでエラー表示
     $contentLength = Hash::get($_SERVER, 'CONTENT_LENGTH');
     if ($contentLength > CakeNumber::fromReadableSize(ini_get('post_max_size'))) {
         $message = __d('files', 'FileUpload.post_max_size.over');
         $controller->NetCommons->setFlashNotification($message, array('class' => 'danger', 'interval' => NetCommonsComponent::ALERT_VALIDATE_ERROR_INTERVAL));
         $controller->redirect($controller->referer());
     }
 }
开发者ID:s-nakajima,项目名称:files,代码行数:16,代码来源:FileUploadComponent.php

示例4: numberCurrency

 /**
  * Number format by market with currency code
  *
  * @param $market_id
  * @param $number
  * @param bool $no_symbol
  * @return string
  */
 public function numberCurrency($market_id, $number, $no_symbol = false)
 {
     if ($market_id == 5) {
         $currency = 'GBP';
     } elseif ($market_id == 7 || $market_id == 8 || $market_id == 9) {
         $currency = 'EUR';
     } else {
         $currency = 'USD';
     }
     if ($no_symbol) {
         $options = ['before' => false, 'after' => false, 'places' => 2];
     } else {
         $options = ['places' => 2];
     }
     return CakeNumber::currency($number, $currency, $options);
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:24,代码来源:AppHelper.php

示例5: addMedia

 /**
  * Add media file
  *
  * @param array $requestData Array of POST data. Will contain form data as well as uploaded files.
  *
  * @return bool
  * @throws CakeException
  */
 public function addMedia(array $requestData)
 {
     if (CakeNumber::fromReadableSize(ini_get('post_max_size')) < env('CONTENT_LENGTH')) {
         throw new CakeException(__d('hurad', 'File could not be uploaded. please increase "post_max_size" in php.ini'));
     }
     $this->set($requestData);
     if ($this->validates()) {
         $prefix = uniqid() . '_';
         $uploadInfo = $requestData['Media']['media_file'];
         $path = date('Y') . DS . date('m');
         if ($uploadInfo['error']) {
             throw new CakeException($this->getUploadErrorMessages($uploadInfo['error']));
         }
         $folder = new Folder(WWW_ROOT . 'files' . DS . $path, true, 0755);
         if (!is_writable(WWW_ROOT . 'files')) {
             throw new CakeException(__d('hurad', '%s is not writable', WWW_ROOT . 'files'));
         }
         if (!move_uploaded_file($uploadInfo['tmp_name'], $folder->pwd() . DS . $prefix . $uploadInfo['name'])) {
             throw new CakeException(__d('hurad', 'File could not be uploaded. Please, try again.'));
         }
         $file = new File($folder->pwd() . DS . $prefix . $uploadInfo['name']);
         $requestData['Media']['user_id'] = CakeSession::read('Auth.User.id');
         $requestData['Media']['name'] = $prefix . $uploadInfo['name'];
         $requestData['Media']['original_name'] = $uploadInfo['name'];
         $requestData['Media']['mime_type'] = $file->mime();
         $requestData['Media']['size'] = $file->size();
         $requestData['Media']['extension'] = $file->ext();
         $requestData['Media']['path'] = $path;
         $requestData['Media']['web_path'] = Configure::read('General.site_url') . '/' . 'files' . '/' . $path . '/' . $prefix . $uploadInfo['name'];
         $this->create();
         if ($this->save($requestData)) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:hurad,项目名称:hurad,代码行数:47,代码来源:Media.php

示例6: __construct

 /**
  * 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 = CakeNumber::fromReadableSize($this->_config['size']);
         }
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:28,代码来源:FileLog.php

示例7: currency

	function currency($number, $currency = null, $options = array()) {
		// App::uses('BakewellNumber', 'Utility');
		// return BakewellNumber::currency($number, $currency, $options);
		App::uses('CakeNumber', 'Utility');
		return CakeNumber::currency($number, $currency, $options);
	}
开发者ID:ayurved,项目名称:AdyaAyurveda,代码行数:6,代码来源:AppModel.php

示例8: beforeValidate

 /**
  * Called during validation operations, before validation. Please note that custom
  * validation rules can be defined in $validate.
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if validate operation should continue, false to abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
  * @see Model::save()
  */
 public function beforeValidate($options = array())
 {
     $postMaxSize = CakeNumber::fromReadableSize(ini_get('post_max_size'));
     $uploadMaxFilesize = CakeNumber::fromReadableSize(ini_get('upload_max_filesize'));
     $maxUploadSize = CakeNumber::toReadableSize($postMaxSize > $uploadMaxFilesize ? $uploadMaxFilesize : $postMaxSize);
     $this->validate = Hash::merge($this->validate, array(self::INPUT_NAME => array('uploadError' => array('rule' => array('uploadError'), 'message' => array('Error uploading file'))), 'name' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'slug' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'path' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'on' => 'create')), 'extension' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'mimetype' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false)), 'size' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false)), 'role_type' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true)), 'number_of_downloads' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'))), 'status' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.')))));
     return parent::beforeValidate($options);
 }
开发者ID:s-nakajima,项目名称:FileDevs,代码行数:17,代码来源:FileModel_bk.php

示例9: addFormat

 /**
  * @see: CakeNumber::addFormat()
  *
  * @param string $formatName The format name to be used in the future.
  * @param array $options The array of options for this format.
  * @return void
  * @see NumberHelper::currency()
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::addFormat
  */
 public function addFormat($formatName, $options)
 {
     return $this->_engine->addFormat($formatName, $options);
 }
开发者ID:gilyaev,项目名称:framework-bench,代码行数:13,代码来源:NumberHelper.php

示例10: define

if (CakePlugin::loaded('I18n')) {
    App::uses('I18nRoute', 'I18n.Routing/Route');
    Router::defaultRouteClass('I18nRoute');
    Configure::write('Config.language', Configure::read('L10n.language'));
    Configure::write('Config.languages', Configure::read('L10n.languages'));
    if (!defined('DEFAULT_LANGUAGE')) {
        define('DEFAULT_LANGUAGE', Configure::read('L10n.language'));
    }
}
/**
 * Configure `CakeNumber` currencies.
 */
if (class_exists('CakeNumber')) {
    CakeNumber::defaultCurrency(Common::read('L10n.currency', 'USD'));
    foreach (Common::read('L10n.currencies', array()) as $currencyName => $currencyFormat) {
        CakeNumber::addFormat($currencyName, $currencyFormat);
    }
}
if (!function_exists('__t')) {
    /**
     * Translates different type of strings depending on the number of arguments it is passed and their types. Supports:
     *
     *  - all of `__()`, `__n()`, `__d()`, `__dn()`
     *  - placeholders for `String::insert()`
     *
     * Examples:
     *
     * 	- __t('Hello world!')
     * 	- __t('Hello :name!', array('name' => 'world'))
     * 	- __t('Hello mate!', 'Hello mates!', 2)
     * 	- __t(':salutation mate!', ':salutation mates!', 2, array('salutation' => 'Hello'))
开发者ID:gourmet,项目名称:common,代码行数:31,代码来源:bootstrap.php

示例11: array

<?php

Cache::config('default', array('engine' => 'File'));
// load all Plugins
CakePlugin::loadAll();
//Configuring Filters
Configure::write('Dispatcher.filters', array('AssetDispatcher', 'CacheDispatcher'));
// config the log
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array('engine' => 'FileLog', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug'));
CakeLog::config('error', array('engine' => 'FileLog', 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error'));
// Configure currency for BRAZIL
App::uses('CakeNumber', 'Utility');
CakeNumber::addFormat('BRR', array('before' => 'R$ ', 'thousands' => '.', 'decimals' => ',', 'zero' => 'R$ 0,00', 'after' => false));
CakeNumber::addFormat('BR', array('before' => null, 'thousands' => '.', 'decimals' => ',', 'after' => false));
/* function check route 
 ex:  if (checkRoute('pages#home')) {}  */
function checkRoute($route = null)
{
    list($controller, $action) = explode('#', $route);
    $params = Router::getParams();
    return $params['controller'] == $controller && $params['action'] == $action;
}
function mostraMes($m)
{
    switch ($m) {
        case 01:
        case 1:
            $mes = "Janeiro";
            break;
        case 02:
开发者ID:lucassmacedo,项目名称:Controle-Caixa-CakePHP,代码行数:31,代码来源:bootstrap.php

示例12: array

 * 		array('callable' => $aFunction, 'on' => 'before', 'priority' => 9), // A valid PHP callback type to be called on beforeDispatch
 *		array('callable' => $anotherMethod, 'on' => 'after'), // A valid PHP callback type to be called on afterDispatch
 *
 * ));
 */
Configure::write('Dispatcher.filters', array('AssetDispatcher', 'CacheDispatcher'));
/**
 * Configures default file logging options
 */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array('engine' => 'File', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug'));
CakeLog::config('error', array('engine' => 'File', 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error'));
App::uses('CakeTime', 'Utility');
App::uses('CakeNumber', 'Utility');
CakeNumber::addFormat('EUR', array('wholeSymbol' => ' &#8364;', 'wholePosition' => 'after', 'fractionSymbol' => false, 'fractionPosition' => 'after', 'zero' => 0, 'places' => 0, 'thousands' => ' ', 'decimals' => ',', 'negative' => '-', 'escape' => false));
CakeNumber::defaultCurrency('USD');
/**
 * All available languages in format (except the default which is defined in constants.php):
 * ISO-639-1 => ISO-639-2
 * napriklad 'sk' => 'slo'
 *
 * @see ISO link: http://www.loc.gov/standards/iso639-2/php/code_list.php
 */
function availableLocals()
{
    return array();
}
/**
 * Return local in format ISO-639-2.
 *
 * @param string $lang locale ISO-639-1
开发者ID:magooemp,项目名称:eramba,代码行数:31,代码来源:bootstrap.php

示例13: testMultibyteFormat

 /**
  * testMultibyteFormat
  *
  * @return void
  */
 public function testMultibyteFormat()
 {
     $value = '5199100.0006';
     $result = $this->Number->format($value, array('thousands' => '&nbsp;', 'decimals' => '&amp;', 'places' => 3, 'escape' => false, 'before' => ''));
     $expected = '5&nbsp;199&nbsp;100&amp;001';
     $this->assertEquals($expected, $result);
     $value = 1000.45;
     $result = $this->Number->format($value, array('thousands' => ',,', 'decimals' => '.a', 'escape' => false));
     $expected = '$1,,000.a45';
     $this->assertEquals($expected, $result);
     $value = 519919827593784.0;
     $this->Number->addFormat('RUR', array('thousands' => 'ø€ƒ‡™', 'decimals' => '(§.§)', 'escape' => false, 'wholeSymbol' => '€', 'wholePosition' => 'after'));
     $result = $this->Number->currency($value, 'RUR');
     $expected = '519ø€ƒ‡™919ø€ƒ‡™827ø€ƒ‡™593ø€ƒ‡™784(§.§)00€';
     $this->assertEquals($expected, $result);
     $value = '13371337.1337';
     $result = CakeNumber::format($value, array('thousands' => '- |-| /-\\ >< () |2 -', 'decimals' => '- £€€† -', 'before' => ''));
     $expected = '13- |-| /-\\ &gt;&lt; () |2 -371- |-| /-\\ &gt;&lt; () |2 -337- £€€† -13';
     $this->assertEquals($expected, $result);
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:25,代码来源:CakeNumberTest.php

示例14: main

 /**
  * Override main() for help message hook
  *
  * @access public
  */
 public function main()
 {
     $path = $this->path;
     $Folder = new Folder($path, true);
     $fileSufix = date('Ymd\\_His') . '.sql';
     $file = $path . $fileSufix;
     if (!is_writable($path)) {
         trigger_error('The path "' . $path . '" isn\'t writable!', E_USER_ERROR);
     }
     $this->out("Backing up...\n");
     $File = new File($file);
     $db = ConnectionManager::getDataSource($this->dataSourceName);
     $config = $db->config;
     $this->connection = "default";
     foreach ($db->listSources() as $table) {
         $table = str_replace($config['prefix'], '', $table);
         // $table = str_replace($config['prefix'], '', 'dinings');
         $ModelName = Inflector::classify($table);
         if (in_array($ModelName, $this->excluidos)) {
             continue;
         }
         $Model = ClassRegistry::init($ModelName);
         $Model->virtualFields = array();
         $DataSource = $Model->getDataSource();
         $this->Schema = new CakeSchema(array('connection' => $this->connection));
         $cakeSchema = $db->describe($table);
         // $CakeSchema = new CakeSchema();
         $this->Schema->tables = array($table => $cakeSchema);
         $File->write("\n/* Drop statement for {$table} */\n");
         $File->write("\nSET foreign_key_checks = 0;\n\n");
         #$File->write($DataSource->dropSchema($this->Schema, $table) . "\n");
         $File->write($DataSource->dropSchema($this->Schema, $table));
         $File->write("SET foreign_key_checks = 1;\n");
         $File->write("\n/* Backuping table schema {$table} */\n");
         $File->write($DataSource->createSchema($this->Schema, $table) . "\n");
         $File->write("/* Backuping table data {$table} */\n");
         unset($valueInsert, $fieldInsert);
         $rows = $Model->find('all', array('recursive' => -1));
         $quantity = 0;
         $File->write($this->separador . "\n");
         if (count($rows) > 0) {
             $fields = array_keys($rows[0][$ModelName]);
             $values = array_values($rows);
             $count = count($fields);
             for ($i = 0; $i < $count; $i++) {
                 $fieldInsert[] = $DataSource->name($fields[$i]);
             }
             $fieldsInsertComma = implode(', ', $fieldInsert);
             foreach ($rows as $k => $row) {
                 unset($valueInsert);
                 for ($i = 0; $i < $count; $i++) {
                     $valueInsert[] = $DataSource->value(utf8_encode($row[$ModelName][$fields[$i]]), $Model->getColumnType($fields[$i]), false);
                 }
                 $query = array('table' => $DataSource->fullTableName($table), 'fields' => $fieldsInsertComma, 'values' => implode(', ', $valueInsert));
                 $File->write($DataSource->renderStatement('create', $query) . ";\n");
                 $quantity++;
             }
         }
         $this->out('Model "' . $ModelName . '" (' . $quantity . ')');
     }
     $this->out("Backup: " . $file);
     $this->out("Peso:: " . CakeNumber::toReadableSize(filesize($file)));
     $File->close();
     if (class_exists('ZipArchive') && filesize($file) > 100) {
         $zipear = $this->in('Deseas zipear este backup', null, 's');
         $zipear = strtolower($zipear);
         if ($zipear === 's') {
             $this->hr();
             $this->out('Zipping...');
             $zip = new ZipArchive();
             $zip->open($file . '.zip', ZIPARCHIVE::CREATE);
             $zip->addFile($file, $fileSufix);
             $zip->close();
             $this->out("Peso comprimido: " . CakeNumber::toReadableSize(filesize($file . '.zip')));
             $this->out("Listo!");
             if (file_exists($file . '.zip') && filesize($file) > 10) {
                 unlink($file);
             }
             $this->out("Database Backup Successful.\n");
         }
     }
 }
开发者ID:oxicode,项目名称:cakephp-modo-mantenimiento,代码行数:87,代码来源:BackupShell.php

示例15: validateRoomFileSizeLimit

 /**
  * NetCommons3のシステム管理→一般設定で許可されているルーム容量内かをチェックするバリデータ
  *
  * @param Model $model Model
  * @param array $check バリデートする値
  * @return bool|string 容量内: true, 容量オーバー: string エラーメッセージ
  */
 public function validateRoomFileSizeLimit(Model $model, $check)
 {
     $field = $this->_getField($check);
     $roomId = Current::read('Room.id');
     $maxRoomDiskSize = Current::read('Space.room_disk_size');
     if ($maxRoomDiskSize === null) {
         return true;
     }
     $size = $check[$field]['size'];
     $roomTotalSize = $this->getTotalSizeByRoomId($model, $roomId);
     if ($roomTotalSize + $size < $maxRoomDiskSize) {
         return true;
     } else {
         $roomsLanguage = ClassRegistry::init('Room.RoomsLanguage');
         $data = $roomsLanguage->find('first', ['conditions' => ['room_id' => $roomId, 'language_id' => Current::read('Language.id')]]);
         $roomName = $data['RoomsLanguage']['name'];
         // ファイルサイズをMBとかkb表示に
         $message = __d('files', 'Total file size uploaded to the %s, exceeded the limit. The limit is %s(%s left).', $roomName, CakeNumber::toReadableSize($maxRoomDiskSize), CakeNumber::toReadableSize($maxRoomDiskSize - $roomTotalSize));
         return $message;
     }
 }
开发者ID:s-nakajima,项目名称:files,代码行数:28,代码来源:UploadFileValidateBehavior.php


注:本文中的CakeNumber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。