CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.2 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class JsonConfig

JSON engine allows Configure to load configuration values from files containing JSON strings.

An example JSON file would look like::

{
    "debug": false,
    "App": {
        "namespace": "MyApp"
    },
    "Security": {
        "salt": "its-secret"
    }
}
Namespace: Cake\Core\Configure\Engine

Property Summary

  • $_extension protected
    string

    File extension.

  • $_path protected
    string

    The path this engine finds files on.

Method Summary

  • __construct() public

    Constructor for JSON Config file reading.

  • _getFilePath() protected

    Get file path

  • dump() public

    Converts the provided $data into a JSON string that can be used saved into a file and loaded later.

  • read() public

    Read a config file and return its contents.

Method Detail

__construct() ¶ public

__construct(string|null $path = null)

Constructor for JSON Config file reading.

Parameters
string|null $path optional

The path to read config files from. Defaults to CONFIG.

_getFilePath() ¶ protected

_getFilePath(string $key, bool $checkExists = false): string

Get file path

Parameters
string $key

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

bool $checkExists optional

Whether to check if file exists. Defaults to false.

Returns
string
Throws
Cake\Core\Exception\CakeException
When files don't exist or when files contain '..' as this could lead to abusive reads.

dump() ¶ public

dump(string $key, array $data): bool

Converts the provided $data into a JSON string that can be used saved into a file and loaded later.

Parameters
string $key

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

array $data

Data to dump.

Returns
bool

read() ¶ public

read(string $key): array

Read a config file and return its contents.

Files with . in the name will be treated as values in plugins. Instead of reading from the initialized path, plugin keys will be located using Plugin::path().

Parameters
string $key

The identifier to read from. If the key has a . it will be treated as a plugin prefix.

Returns
array
Throws
Cake\Core\Exception\CakeException
When files don't exist or when files contain '..' (as this could lead to abusive reads) or when there is an error parsing the JSON string.

Property Detail

$_extension ¶ protected

File extension.

Type
string

$_path ¶ protected

The path this engine finds files on.

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs