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.4 Red Velvet API

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

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

Classes

  • BinaryType
  • BoolType
  • DateTimeType
  • DateType
  • DecimalType
  • FloatType
  • IntegerType
  • JsonType
  • StringType
  • TimeType
  • UuidType

Interfaces

  • ExpressionTypeInterface
  • OptionalConvertInterface

Traits

  • ExpressionTypeCasterTrait
  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         3.3.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Database\Type;
 16: 
 17: use Cake\Database\Driver;
 18: use Cake\Database\Type;
 19: use Cake\Database\TypeInterface;
 20: use InvalidArgumentException;
 21: use PDO;
 22: 
 23: /**
 24:  * Json type converter.
 25:  *
 26:  * Use to convert json data between PHP and the database types.
 27:  */
 28: class JsonType extends Type implements TypeInterface
 29: {
 30:     /**
 31:      * Identifier name for this type.
 32:      *
 33:      * (This property is declared here again so that the inheritance from
 34:      * Cake\Database\Type can be removed in the future.)
 35:      *
 36:      * @var string|null
 37:      */
 38:     protected $_name;
 39: 
 40:     /**
 41:      * Constructor.
 42:      *
 43:      * (This method is declared here again so that the inheritance from
 44:      * Cake\Database\Type can be removed in the future.)
 45:      *
 46:      * @param string|null $name The name identifying this type
 47:      */
 48:     public function __construct($name = null)
 49:     {
 50:         $this->_name = $name;
 51:     }
 52: 
 53:     /**
 54:      * Convert a value data into a JSON string
 55:      *
 56:      * @param mixed $value The value to convert.
 57:      * @param \Cake\Database\Driver $driver The driver instance to convert with.
 58:      * @return string|null
 59:      */
 60:     public function toDatabase($value, Driver $driver)
 61:     {
 62:         if (is_resource($value)) {
 63:             throw new InvalidArgumentException('Cannot convert a resource value to JSON');
 64:         }
 65: 
 66:         return json_encode($value);
 67:     }
 68: 
 69:     /**
 70:      * Convert string values to PHP arrays.
 71:      *
 72:      * @param mixed $value The value to convert.
 73:      * @param \Cake\Database\Driver $driver The driver instance to convert with.
 74:      * @return string|null|array
 75:      */
 76:     public function toPHP($value, Driver $driver)
 77:     {
 78:         return json_decode($value, true);
 79:     }
 80: 
 81:     /**
 82:      * Get the correct PDO binding type for string data.
 83:      *
 84:      * @param mixed $value The value being bound.
 85:      * @param \Cake\Database\Driver $driver The driver.
 86:      * @return int
 87:      */
 88:     public function toStatement($value, Driver $driver)
 89:     {
 90:         return PDO::PARAM_STR;
 91:     }
 92: 
 93:     /**
 94:      * Marshalls request data into a JSON compatible structure.
 95:      *
 96:      * @param mixed $value The value to convert.
 97:      * @return mixed Converted value.
 98:      */
 99:     public function marshal($value)
100:     {
101:         return $value;
102:     }
103: }
104: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
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