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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.2
      • 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
    • Event
    • Filesystem
    • Form
    • I18n
      • Formatter
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
      • Http
        • Adapter
        • Auth
        • FormData
      • Session
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Constraint
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

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

Interfaces

  • OptionalConvertInterface
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
 11:  * @link          http://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Database\Type;
 16: 
 17: use Cake\Core\Exception\Exception;
 18: use Cake\Database\Driver;
 19: use Cake\Database\Driver\Sqlserver;
 20: use Cake\Database\Type;
 21: use Cake\Database\TypeInterface;
 22: use PDO;
 23: 
 24: /**
 25:  * Binary type converter.
 26:  *
 27:  * Use to convert binary data between PHP and the database types.
 28:  */
 29: class BinaryType extends Type implements TypeInterface
 30: {
 31: 
 32:     /**
 33:      * Identifier name for this type
 34:      *
 35:      * @var string|null
 36:      */
 37:     protected $_name = null;
 38: 
 39:     /**
 40:      * Constructor
 41:      *
 42:      * @param string|null $name The name identifying this type
 43:      */
 44:     public function __construct($name = null)
 45:     {
 46:         $this->_name = $name;
 47:     }
 48: 
 49:     /**
 50:      * Convert binary data into the database format.
 51:      *
 52:      * Binary data is not altered before being inserted into the database.
 53:      * As PDO will handle reading file handles.
 54:      *
 55:      * @param string|resource $value The value to convert.
 56:      * @param \Cake\Database\Driver $driver The driver instance to convert with.
 57:      * @return string|resource
 58:      */
 59:     public function toDatabase($value, Driver $driver)
 60:     {
 61:         return $value;
 62:     }
 63: 
 64:     /**
 65:      * Convert binary into resource handles
 66:      *
 67:      * @param null|string|resource $value The value to convert.
 68:      * @param \Cake\Database\Driver $driver The driver instance to convert with.
 69:      * @return resource|null
 70:      * @throws \Cake\Core\Exception\Exception
 71:      */
 72:     public function toPHP($value, Driver $driver)
 73:     {
 74:         if ($value === null) {
 75:             return null;
 76:         }
 77:         if (is_string($value) && $driver instanceof Sqlserver) {
 78:             $value = pack('H*', $value);
 79:         }
 80:         if (is_string($value)) {
 81:             return fopen('data:text/plain;base64,' . base64_encode($value), 'rb');
 82:         }
 83:         if (is_resource($value)) {
 84:             return $value;
 85:         }
 86:         throw new Exception(sprintf('Unable to convert %s into binary.', gettype($value)));
 87:     }
 88: 
 89:     /**
 90:      * Get the correct PDO binding type for Binary data.
 91:      *
 92:      * @param mixed $value The value being bound.
 93:      * @param \Cake\Database\Driver $driver The driver.
 94:      * @return int
 95:      */
 96:     public function toStatement($value, Driver $driver)
 97:     {
 98:         return PDO::PARAM_LOB;
 99:     }
100: 
101:     /**
102:      * Marshalls flat data into PHP objects.
103:      *
104:      * Most useful for converting request data into PHP objects
105:      * that make sense for the rest of the ORM/Database layers.
106:      *
107:      * @param mixed $value The value to convert.
108:      *
109:      * @return mixed Converted value.
110:      */
111:     public function marshal($value)
112:     {
113:         return $value;
114:     }
115: }
116: 
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