CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • IniConfig
  • JsonConfig
  • PhpConfig
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         2.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Core\Configure\Engine;
 16: 
 17: use Cake\Core\Configure\ConfigEngineInterface;
 18: use Cake\Core\Configure\FileConfigTrait;
 19: use Cake\Core\Exception\Exception;
 20: 
 21: /**
 22:  * PHP engine allows Configure to load configuration values from
 23:  * files containing simple PHP arrays.
 24:  *
 25:  * Files compatible with PhpConfig should return an array that
 26:  * contains all of the configuration data contained in the file.
 27:  *
 28:  * An example configuration file would look like::
 29:  *
 30:  * ```
 31:  * <?php
 32:  * return [
 33:  *     'debug' => 0,
 34:  *     'Security' => [
 35:  *         'salt' => 'its-secret'
 36:  *     ],
 37:  *     'App' => [
 38:  *         'namespace' => 'App'
 39:  *     ]
 40:  * ];
 41:  * ```
 42:  *
 43:  * @see Cake\Core\Configure::load() for how to load custom configuration files.
 44:  */
 45: class PhpConfig implements ConfigEngineInterface
 46: {
 47: 
 48:     use FileConfigTrait;
 49: 
 50:     /**
 51:      * File extension.
 52:      *
 53:      * @var string
 54:      */
 55:     protected $_extension = '.php';
 56: 
 57:     /**
 58:      * Constructor for PHP Config file reading.
 59:      *
 60:      * @param string|null $path The path to read config files from. Defaults to CONFIG.
 61:      */
 62:     public function __construct($path = null)
 63:     {
 64:         if ($path === null) {
 65:             $path = CONFIG;
 66:         }
 67:         $this->_path = $path;
 68:     }
 69: 
 70:     /**
 71:      * Read a config file and return its contents.
 72:      *
 73:      * Files with `.` in the name will be treated as values in plugins. Instead of
 74:      * reading from the initialized path, plugin keys will be located using Plugin::path().
 75:      *
 76:      * Setting a `$config` variable is deprecated. Use `return` instead.
 77:      *
 78:      * @param string $key The identifier to read from. If the key has a . it will be treated
 79:      *  as a plugin prefix.
 80:      * @return array Parsed configuration values.
 81:      * @throws \Cake\Core\Exception\Exception when files don't exist or they don't contain `$config`.
 82:      *  Or when files contain '..' as this could lead to abusive reads.
 83:      */
 84:     public function read($key)
 85:     {
 86:         $file = $this->_getFilePath($key, true);
 87: 
 88:         $config = null;
 89: 
 90:         $return = include $file;
 91:         if (is_array($return)) {
 92:             return $return;
 93:         }
 94: 
 95:         if ($config === null) {
 96:             throw new Exception(sprintf('Config file "%s" did not return an array', $key . '.php'));
 97:         }
 98:         deprecationWarning(sprintf(
 99:             'PHP configuration files like "%s" should not set `$config`. Instead return an array.',
100:             $key . '.php'
101:         ));
102: 
103:         return $config;
104:     }
105: 
106:     /**
107:      * Converts the provided $data into a string of PHP code that can
108:      * be used saved into a file and loaded later.
109:      *
110:      * @param string $key The identifier to write to. If the key has a . it will be treated
111:      *  as a plugin prefix.
112:      * @param array $data Data to dump.
113:      * @return bool Success
114:      */
115:     public function dump($key, array $data)
116:     {
117:         $contents = '<?php' . "\n" . 'return ' . var_export($data, true) . ';';
118: 
119:         $filename = $this->_getFilePath($key);
120: 
121:         return file_put_contents($filename, $contents) > 0;
122:     }
123: }
124: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs