本文整理汇总了PHP中Cake\Utility\Inflector::camelize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::camelize方法的具体用法?PHP Inflector::camelize怎么用?PHP Inflector::camelize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Inflector
的用法示例。
在下文中一共展示了Inflector::camelize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyHookMethods
/**
* Applies methods set from hooks to an object in __construct()
*
* @param string $configKey
*/
public static function applyHookMethods($configKey, &$object = null)
{
if (empty($object)) {
$object = self;
}
if ($object instanceof Table) {
$objectName = $object->alias();
} else {
$objectName = $object->name;
}
if (php_sapi_name() !== 'cli') {
$prefix = ($prefix = Router::getRequest()->param('prefix')) ? Inflector::camelize($prefix) . '.' : '';
$plugin = ($plugin = Router::getRequest()->param('plugin')) ? $plugin . '.' : '';
$objectName = $prefix . $plugin . $objectName;
$hookMethods = Configure::read($configKey . '.' . $objectName);
if (is_array(Configure::read($configKey . '.*'))) {
$hookMethods = Hash::merge(Configure::read($configKey . '.*'), $hookMethods);
}
if (is_array($hookMethods)) {
foreach ($hookMethods as $method => $values) {
if (is_callable([$object, $method])) {
foreach ($values as $name => $config) {
$object->{$method}($name, $config);
}
}
}
}
}
}
示例2: index
/**
* Index method
*
* @param string $filter Parameter to filter on
* @param string $id Id of the model to filter
*
* @return \Cake\Network\Response|void
*/
public function index($filter = null, $id = null)
{
$findOptions = ['fields' => ['id', 'name', 'description', 'created', 'modified', 'sfw', 'status', 'user_id'], 'conditions' => ['Albums.status' => 1], 'contain' => ['Users' => ['fields' => ['id', 'username', 'realname']], 'Languages' => ['fields' => ['id', 'name', 'iso639_1']], 'Projects' => ['fields' => ['id', 'name', 'ProjectsAlbums.album_id']], 'Files' => ['fields' => ['id', 'name', 'filename', 'sfw', 'AlbumsFiles.album_id'], 'conditions' => ['status' => STATUS_PUBLISHED]]], 'order' => ['created' => 'desc'], 'sortWhitelist' => ['created', 'name', 'modified']];
// Sfw condition
if (!$this->request->session()->read('seeNSFW')) {
$findOptions['conditions']['sfw'] = true;
}
// Other conditions:
if (!is_null($filter)) {
switch ($filter) {
case 'language':
$findOptions['conditions']['Languages.id'] = $id;
break;
case 'license':
$findOptions['conditions']['Licenses.id'] = $id;
break;
case 'user':
$findOptions['conditions']['Users.id'] = $id;
break;
default:
throw new \Cake\Network\Exception\NotFoundException();
}
// Get additionnal infos infos
$modelName = \Cake\Utility\Inflector::camelize(\Cake\Utility\Inflector::pluralize($filter));
$FilterModel = \Cake\ORM\TableRegistry::get($modelName);
$filterData = $FilterModel->get($id);
$this->set('filterData', $filterData);
}
$this->set('filter', $filter);
$this->paginate = $findOptions;
$this->set('albums', $this->paginate($this->Albums));
$this->set('_serialize', ['files']);
}
示例3: action
/**
* Get the action path for a given request. Primarily used by authorize objects
* that need to get information about the plugin, controller, and action being invoked.
*
* @param \Cake\Network\Request $request The request a path is needed for.
* @param string $path Path
* @return string The action path for the given request.
*/
public function action(Request $request, $path = '/:plugin/:controller/:action')
{
$plugin = empty($request['plugin']) ? null : Inflector::camelize($request['plugin']) . '/';
$path = str_replace(array(':controller', ':action', ':plugin/'), array(Inflector::camelize($request['controller']), $request['action'], $plugin), $this->_config['actionPath'] . $path);
$path = str_replace('//', '/', $path);
return trim($path, '/');
}
示例4: _jsonData
private function _jsonData($obj)
{
if (!$obj instanceof AppEntity) {
return $obj;
}
$class = $obj->getClass();
$result = [];
$result['class'] = $class;
$result['url'] = $obj->getUrl();
foreach ($obj->visibleProperties() as $key) {
$value = $obj->get($key);
$label = Inflector::camelize("label_" . $key);
if (method_exists($obj, $label)) {
$value = call_user_func([$obj, $label], $value);
}
if (isset($this->_aliases[$class][$key])) {
$key = $this->_aliases[$class][$key];
}
if (is_array($value)) {
$value = $this->_jsonList($value, $obj, $key);
unset($value['parent']);
} else {
$value = $this->_jsonCompact($value, $obj);
}
$result[$key] = $value;
}
return $result;
}
示例5: _getController
/**
* Get controller to use, either plugin controller or application controller
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if ($pluginPath) {
return parent::_getController($request, $response);
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$instance = PipingBag::get($className);
if (method_exists($instance, 'viewBuilder')) {
$instance->viewBuilder();
} else {
$instance->viewPath = null;
}
$instance->name = $controller;
$instance->setRequest($request);
$instance->response = $response;
return $instance;
}
示例6: get
/**
* Get/Create an instance from the registry.
*
* When getting an instance, if it does not already exist,
* a new instance will be created using the provide alias, and options.
*
* @param string $alias The name of the alias to get.
* @param array $options Configuration options for the type constructor.
* @return \Cake\ElasticSearch\Type
*/
public static function get($alias, array $options = [])
{
if (isset(static::$instances[$alias])) {
if (!empty($options) && static::$options[$alias] !== $options) {
throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias));
}
return static::$instances[$alias];
}
static::$options[$alias] = $options;
list(, $classAlias) = pluginSplit($alias);
$options = $options + ['name' => Inflector::underscore($classAlias)];
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
$className = App::className($options['className'], 'Model/Type', 'Type');
if ($className) {
$options['className'] = $className;
} else {
if (!isset($options['name']) && strpos($options['className'], '\\') === false) {
list(, $name) = pluginSplit($options['className']);
$options['name'] = Inflector::underscore($name);
}
$options['className'] = 'Cake\\ElasticSearch\\Type';
}
if (empty($options['connection'])) {
$connectionName = $options['className']::defaultConnectionName();
$options['connection'] = ConnectionManager::get($connectionName);
}
static::$instances[$alias] = new $options['className']($options);
return static::$instances[$alias];
}
示例7: _getController
/**
* Get controller to use, either plugin controller or application controller
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$reflection = new \ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return false;
}
return $reflection->newInstance($request, $response);
}
示例8: socialLogin
/**
* Social login link
*
* @param string $name
* @param array $options
* @return string
*/
public function socialLogin($name, $options = [])
{
if (empty($options['label'])) {
$options['label'] = 'Sign in with';
}
return $this->Html->link($this->Html->tag('i', '', ['class' => __d('Users', 'fa fa-{0}', strtolower($name))]) . __d('Users', '{0} {1}', Hash::get($options, 'label'), Inflector::camelize($name)), "/auth/{$name}", ['escape' => false, 'class' => __d('Users', 'btn btn-social btn-{0} ' . Hash::get($options, 'class') ?: '', strtolower($name))]);
}
示例9: init
/**
* Inits PO file from POT file.
*
* @param string|null $language Language code to use.
* @return int|null
*/
public function init($language = null)
{
if (!$language) {
$language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
}
if (strlen($language) < 2) {
return $this->error('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
}
$this->_paths = [APP];
if ($this->param('plugin')) {
$plugin = Inflector::camelize($this->param('plugin'));
$this->_paths = [Plugin::classPath($plugin)];
}
$response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'Locale');
$sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
if (!is_dir($targetFolder)) {
mkdir($targetFolder, 0775, true);
}
$count = 0;
$iterator = new DirectoryIterator($sourceFolder);
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile()) {
continue;
}
$filename = $fileinfo->getFilename();
$newFilename = $fileinfo->getBasename('.pot');
$newFilename = $newFilename . '.po';
$this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
$count++;
}
$this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
}
示例10: create
/**
* Create a controller for a given request/response
*
* @param \Cake\Network\Request $request The request to build a controller for.
* @param \Cake\Network\Response $response The response to use.
* @return \Cake\Controller\Controller
*/
public function create(Request $request, Response $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (isset($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (isset($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (isset($request->params['prefix'])) {
if (strpos($request->params['prefix'], '/') === false) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
} else {
$prefixes = array_map('Cake\\Utility\\Inflector::camelize', explode('/', $request->params['prefix']));
$namespace .= '/' . implode('/', $prefixes);
}
}
$firstChar = substr($controller, 0, 1);
if (strpos($controller, '\\') !== false || strpos($controller, '.') !== false || $firstChar === strtolower($firstChar)) {
return $this->missingController($request);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return $this->missingController($request);
}
$reflection = new ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return $this->missingController($request);
}
return $reflection->newInstance($request, $response, $controller);
}
示例11: beforeFind
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (!array_key_exists('getRelated', $options) || !$options['getRelated']) {
//Jen pokud se mají related stahovat
return true;
}
$attachedTables = $this->_InRelatedIndexBehavior->getTablesWithBehaviorNames();
/** @var \Cake\ORM\Table $attachedTable */
foreach ($attachedTables as $tableName) {
$modelName = Inflector::camelize($tableName);
$query->contain(['Related' . $modelName => []]);
}
$query->formatResults(function ($results) {
return $results->map(function ($row) {
$temp = $row->toArray();
$related = [];
foreach ($temp as $key => $item) {
if (preg_match('/related-.*/', $key)) {
foreach ($row->{$key} as $id => $similar) {
$table_name = explode('-', $key);
$row->{$key}[$id]->table_name = end($table_name);
}
$related = array_merge($related, $row->{$key});
unset($row->{$key});
}
}
$row->related = $related;
return $row;
});
});
return true;
}
示例12: _getAssetFile
/**
* Builds asset file path based on the provided $url.
*
* @param string $url Asset URL
* @return string|void Absolute path for asset file
*/
protected function _getAssetFile($url)
{
$parts = explode('/', $url);
$pluginPart = [];
$plugin = false;
for ($i = 0; $i < 2; $i++) {
if (!isset($parts[$i])) {
break;
}
$pluginPart[] = Inflector::camelize($parts[$i]);
$possiblePlugin = implode('/', $pluginPart);
if ($possiblePlugin && Plugin::loaded($possiblePlugin)) {
$plugin = $possiblePlugin;
$parts = array_slice($parts, $i + 1);
break;
}
}
$isAssetRequest = isset($parts[0]) && $parts[0] === 'ASSETS';
if ($isAssetRequest && Configure::read('debug')) {
$parts = array_slice($parts, 1);
} else {
$isAssetRequest = false;
}
if ($plugin && Plugin::loaded($plugin)) {
return $this->_getPluginAsset($plugin, $parts, $isAssetRequest);
} else {
return $this->_getAppAsset($parts, $isAssetRequest);
}
}
示例13: action
/**
* Get the action path for a given request. Primarily used by authorize objects
* that need to get information about the plugin, controller, and action being invoked.
*
* @param \Cake\Network\Request $request The request a path is needed for.
* @param string $path Path
* @return string The action path for the given request.
*/
public function action(Request $request, $path = '/:plugin/:prefix/:controller/:action')
{
$plugin = empty($request['plugin']) ? null : preg_replace('/\\//', '\\', Inflector::camelize($request['plugin'])) . '/';
$prefix = empty($request['prefix']) ? null : Inflector::camelize($request['prefix']) . '/';
$path = str_replace([':controller', ':action', ':plugin/', ':prefix/'], [Inflector::camelize($request['controller']), $request['action'], $plugin, $prefix], $this->_config['actionPath'] . $path);
$path = str_replace('//', '/', $path);
return trim($path, '/');
}
示例14: requestPath
/**
* Gets an ACO path for current request.
*
* @param \Cake\Network\Request $request Request instance
* @param string $path Pattern
* @return string
*/
public function requestPath(Request $request, $path = '/:plugin/:prefix/:controller/:action')
{
$plugin = empty($request['plugin']) ? null : Inflector::camelize($request['plugin']) . '/';
$prefix = empty($request->params['prefix']) ? '' : Inflector::camelize($request->params['prefix']) . '/';
$path = str_replace([':controller', ':action', ':plugin/', ':prefix/'], [Inflector::camelize($request['controller']), $request['action'], $plugin, $prefix], $path);
$path = str_replace('//', '/', $path);
return trim($path, '/');
}
示例15: loader
public function loader()
{
$this->autoRender = false;
$model = $this->request->query['model'];
$field_name = $this->request->query['field_name'];
//Entityに接続して設定値を取得
$this->__baseModel = TableRegistry::get($model);
$entity = $this->__baseModel->newEntity();
$contentsFileConfig = $entity->contentsFileConfig;
if (!empty($this->request->query['tmp_file_name'])) {
$filename = $this->request->query['tmp_file_name'];
$filepath = $contentsFileConfig['fields'][$field_name]['cacheTempDir'] . $filename;
} elseif (!empty($this->request->query['model_id'])) {
//表示条件をチェックする
$check_method_name = 'contentsFileCheck' . Inflector::camelize($field_name);
if (method_exists($this->__baseModel, $check_method_name)) {
//エラーなどの処理はTableに任せる
$this->__baseModel->{$check_method_name}($this->request->query['model_id']);
}
//attachementからデータを取得
$this->__attachmentModel = TableRegistry::get('Attachments');
$attachmentData = $this->__attachmentModel->find('all')->where(['model' => $this->request->query['model']])->where(['model_id' => $this->request->query['model_id']])->where(['field_name' => $this->request->query['field_name']])->first();
if (empty($attachmentData)) {
//404
}
$filename = $attachmentData->file_name;
$filepath = $contentsFileConfig['fields'][$field_name]['filePath'] . $attachmentData->model . '/' . $attachmentData->model_id . '/' . $attachmentData->field_name;
//通常のセットの時のみresize設定があれば見る
if (!empty($this->request->query['resize'])) {
$filepath = $this->__resizeSet($filepath, $this->request->query['resize']);
}
}
$file_ext = null;
if (preg_match('/\\.([^\\.]*)$/', $filename, $ext)) {
if ($ext[1]) {
$file_ext = strtolower($ext[1]);
}
}
$file = $filepath;
header('Content-Length: ' . filesize($file));
if (!empty($file_ext)) {
$fileContentType = $this->getFileType($file_ext);
header('Content-Type: ' . $fileContentType);
} else {
$fileContentType = $this->getMimeType($file);
header('Content-Type: ' . $fileContentType);
}
if (strstr(env('HTTP_USER_AGENT'), 'MSIE') || strstr(env('HTTP_USER_AGENT'), 'Trident')) {
$filename = mb_convert_encoding($filename, "SJIS", "UTF-8");
header('Content-Disposition: filename="' . $filename . '"');
} else {
header('Content-Disposition: filename="' . $filename . '"');
}
@ob_end_clean();
// clean
readfile($file);
}