3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * DbTable based preference persistence adapter * * @package ManipleCore_Prefs * @uses Zefram_Db_Table * @uses Zend_Serializer * @author xemlock * @version 2014-07-30 */ class ManipleCore_Prefs_Adapter_DbTable implements ManipleCore_Prefs_AdapterInterface { /** * @var ManipleCore_Prefs_Adapter_DbTable_UserPrefs */ protected $_table; /** * @var Zend_Serializer_Adapter_Interface */ protected $_serializer; /** * Constructor. * * @param Zefram_Db_Table_FactoryInterface $factory * @param Zend_Serializer_Adapter_Interface|string $serializer * @return void */ public function __construct(Zefram_Db_Table_FactoryInterface $factory, $serializer = null) { $this->_table = $factory->getTable('ManipleCore_Prefs_Adapter_DbTable_UserPrefs'); if ($serializer !== null) { if (!$serializer instanceof Zend_Serializer_Adapter_Interface) { $serializer = Zend_Serializer::factory($serializer); } $this->_serializer = $serializer; } } /** * Load user preference from database. * * @param int|string $userId * @param string $name * @return mixed */ public function loadUserPref($userId, $name) { $name = (string) $name; $row = $this->_table->fetchRow(array( 'user_id = ?' => $userId, 'pref_name = ?' => $name, )); if ($row) { return $this->_unserialize($row->pref_value); } return null; } /** * Load user preferences matching given prefix or, if none given, * all user preferences. * * @param int|string $userId * @param string $prefix OPTIONAL * @return array */ public function loadUserPrefs($userId, $prefix = null) { $where = array('user_id = ?' => $userId); if ($prefix !== null) { $prefix = str_replace(array('%', '_', '^', '[', ']'), '', $prefix); $where['pref_name LIKE ?'] = $prefix . '%'; } $prefs = array(); foreach ($this->_table->fetchAll($where) as $row) { $prefs[$row->pref_name] = $this->_unserialize($row->pref_value); } return $prefs; } /** * Save single user preference. * * @param int|string $userId * @param string $name * @param mixed $value * @return ManipleCore_Prefs_Adapter_DbTable */ public function saveUserPref($userId, $name, $value) { $name = (string) $name; $this->_table->delete(array( 'user_id = ?' => $userId, 'pref_name = ?' => $name, )); $this->_table->insert(array( 'user_id' => $userId, 'pref_name' => $name, 'pref_value' => $this->_serialize($value), )); return $this; } /** * Save multiple user preferences. * * @param int|string $userId * @param array $prefs * @return ManipleCore_Prefs_Adapter_DbTable */ public function saveUserPrefs($userId, array $prefs) { $this->_table->delete(array( 'user_id = ?' => $userId, 'pref_name IN (?)' => array_map('strval', array_keys($prefs)), )); foreach ($prefs as $name => $value) { $name = (string) $name; $this->_table->insert(array( 'user_id' => $userId, 'pref_name' => $name, 'pref_value' => $this->_serialize($value), )); } return $this; } /** * @param mixed $value * @return mixed */ protected function _unserialize($value) { if ($this->_serializer) { try { $value = $this->_serializer->unserialize($value); } catch (Exception $e) { $value = null; } } return $value; } /** * @param mixed $value * @return string */ protected function _serialize($value) { if ($this->_serializer) { $value = $this->_serializer->serialize($value); } elseif (is_bool($value)) { $value = (int) $value; } elseif (is_float($value)) { // do not cast to float, as during conversion from float to string // E notation is used for big numbers $value = sprintf('%F', $value); } return (string) $value; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I5KMt
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   DECLARE_CLASS                                            'maniplecore_prefs_adapter_dbtable'
  168     1      > RETURN                                                   1

Class ManipleCore_Prefs_Adapter_DbTable:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 18
filename:       /in/I5KMt
function name:  __construct
number of ops:  19
compiled vars:  !0 = $factory, !1 = $serializer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   34     2        INIT_METHOD_CALL                                         !0, 'getTable'
          3        SEND_VAL_EX                                              'ManipleCore_Prefs_Adapter_DbTable_UserPrefs'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_OBJ                                               '_table'
          6        OP_DATA                                                  $3
   36     7        TYPE_CHECK                                  1020          !1
          8      > JMPZ                                                     ~4, ->18
   37     9    >   INSTANCEOF                                       ~5      !1, 'Zend_Serializer_Adapter_Interface'
         10        BOOL_NOT                                         ~6      ~5
         11      > JMPZ                                                     ~6, ->16
   38    12    >   INIT_STATIC_METHOD_CALL                                  'Zend_Serializer', 'factory'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $7      
         15        ASSIGN                                                   !1, $7
   40    16    >   ASSIGN_OBJ                                               '_serializer'
         17        OP_DATA                                                  !1
   42    18    > > RETURN                                                   null

End of function __construct

Function loaduserpref:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I5KMt
function name:  loadUserPref
number of ops:  20
compiled vars:  !0 = $userId, !1 = $name, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   53     2        CAST                                          6  ~3      !1
          3        ASSIGN                                                   !1, ~3
   54     4        FETCH_OBJ_R                                      ~5      '_table'
          5        INIT_METHOD_CALL                                         ~5, 'fetchRow'
   55     6        INIT_ARRAY                                       ~6      !0, 'user_id+%3D+%3F'
   56     7        ADD_ARRAY_ELEMENT                                ~6      !1, 'pref_name+%3D+%3F'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0  $7      
   54    10        ASSIGN                                                   !2, $7
   58    11      > JMPZ                                                     !2, ->18
   59    12    >   INIT_METHOD_CALL                                         '_unserialize'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_OBJ_FUNC_ARG                               $9      !2, 'pref_value'
         15        SEND_FUNC_ARG                                            $9
         16        DO_FCALL                                      0  $10     
         17      > RETURN                                                   $10
   61    18    > > RETURN                                                   null
   62    19*     > RETURN                                                   null

End of function loaduserpref

Function loaduserprefs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 31
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 31
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 15
filename:       /in/I5KMt
function name:  loadUserPrefs
number of ops:  34
compiled vars:  !0 = $userId, !1 = $prefix, !2 = $where, !3 = $prefs, !4 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   74     2        INIT_ARRAY                                       ~5      !0, 'user_id+%3D+%3F'
          3        ASSIGN                                                   !2, ~5
   76     4        TYPE_CHECK                                  1020          !1
          5      > JMPZ                                                     ~7, ->15
   77     6    >   INIT_FCALL                                               'str_replace'
          7        SEND_VAL                                                 <array>
          8        SEND_VAL                                                 ''
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
   78    12        CONCAT                                           ~11     !1, '%25'
         13        ASSIGN_DIM                                               !2, 'pref_name+LIKE+%3F'
         14        OP_DATA                                                  ~11
   81    15    >   ASSIGN                                                   !3, <array>
   82    16        FETCH_OBJ_R                                      ~13     '_table'
         17        INIT_METHOD_CALL                                         ~13, 'fetchAll'
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0  $14     
         20      > FE_RESET_R                                       $15     $14, ->31
         21    > > FE_FETCH_R                                               $15, !4, ->31
   83    22    >   FETCH_OBJ_R                                      ~16     !4, 'pref_name'
         23        INIT_METHOD_CALL                                         '_unserialize'
         24        CHECK_FUNC_ARG                                           
         25        FETCH_OBJ_FUNC_ARG                               $18     !4, 'pref_value'
         26        SEND_FUNC_ARG                                            $18
         27        DO_FCALL                                      0  $19     
         28        ASSIGN_DIM                                               !3, ~16
         29        OP_DATA                                                  $19
   82    30      > JMP                                                      ->21
         31    >   FE_FREE                                                  $15
   85    32      > RETURN                                                   !3
   86    33*     > RETURN                                                   null

End of function loaduserprefs

Function saveuserpref:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I5KMt
function name:  saveUserPref
number of ops:  24
compiled vars:  !0 = $userId, !1 = $name, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   98     3        CAST                                          6  ~3      !1
          4        ASSIGN                                                   !1, ~3
   99     5        FETCH_OBJ_R                                      ~5      '_table'
          6        INIT_METHOD_CALL                                         ~5, 'delete'
  100     7        INIT_ARRAY                                       ~6      !0, 'user_id+%3D+%3F'
  101     8        ADD_ARRAY_ELEMENT                                ~6      !1, 'pref_name+%3D+%3F'
          9        SEND_VAL_EX                                              ~6
         10        DO_FCALL                                      0          
  103    11        FETCH_OBJ_R                                      ~8      '_table'
         12        INIT_METHOD_CALL                                         ~8, 'insert'
  104    13        INIT_ARRAY                                       ~9      !0, 'user_id'
  105    14        ADD_ARRAY_ELEMENT                                ~9      !1, 'pref_name'
  106    15        INIT_METHOD_CALL                                         '_serialize'
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $10     
         18        ADD_ARRAY_ELEMENT                                ~9      $10, 'pref_value'
         19        SEND_VAL_EX                                              ~9
         20        DO_FCALL                                      0          
  108    21        FETCH_THIS                                       ~12     
         22      > RETURN                                                   ~12
  109    23*     > RETURN                                                   null

End of function saveuserpref

Function saveuserprefs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/I5KMt
function name:  saveUserPrefs
number of ops:  35
compiled vars:  !0 = $userId, !1 = $prefs, !2 = $value, !3 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  118     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  120     2        FETCH_OBJ_R                                      ~4      '_table'
          3        INIT_METHOD_CALL                                         ~4, 'delete'
  121     4        INIT_ARRAY                                       ~5      !0, 'user_id+%3D+%3F'
  122     5        INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'strval'
          7        INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        ADD_ARRAY_ELEMENT                                ~5      $7, 'pref_name+IN+%28%3F%29'
         13        SEND_VAL_EX                                              ~5
         14        DO_FCALL                                      0          
  124    15      > FE_RESET_R                                       $9      !1, ->31
         16    > > FE_FETCH_R                                       ~10     $9, !2, ->31
         17    >   ASSIGN                                                   !3, ~10
  125    18        CAST                                          6  ~12     !3
         19        ASSIGN                                                   !3, ~12
  126    20        FETCH_OBJ_R                                      ~14     '_table'
         21        INIT_METHOD_CALL                                         ~14, 'insert'
  127    22        INIT_ARRAY                                       ~15     !0, 'user_id'
  128    23        ADD_ARRAY_ELEMENT                                ~15     !3, 'pref_name'
  129    24        INIT_METHOD_CALL                                         '_serialize'
         25        SEND_VAR_EX                                              !2
         26        DO_FCALL                                      0  $16     
         27        ADD_ARRAY_ELEMENT                                ~15     $16, 'pref_value'
         28        SEND_VAL_EX                                              ~15
         29        DO_FCALL                                      0          
  124    30      > JMP                                                      ->16
         31    >   FE_FREE                                                  $9
  132    32        FETCH_THIS                                       ~18     
         33      > RETURN                                                   ~18
  133    34*     > RETURN                                                   null

End of function saveuserprefs

Function _unserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Found catch point at position: 9
Branch analysis from position: 9
2 jumps found. (Code = 107) Position 1 = 10, Position 2 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I5KMt
function name:  _unserialize
number of ops:  13
compiled vars:  !0 = $value, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  139     0  E >   RECV                                             !0      
  141     1        FETCH_OBJ_R                                      ~2      '_serializer'
          2      > JMPZ                                                     ~2, ->11
  143     3    >   FETCH_OBJ_R                                      ~3      '_serializer'
          4        INIT_METHOD_CALL                                         ~3, 'unserialize'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
          8      > JMP                                                      ->11
  144     9  E > > CATCH                                       last         'Exception'
  145    10    >   ASSIGN                                                   !0, null
  148    11    > > RETURN                                                   !0
  149    12*     > RETURN                                                   null

End of function _unserialize

Function _serialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/I5KMt
function name:  _serialize
number of ops:  24
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  155     0  E >   RECV                                             !0      
  157     1        FETCH_OBJ_R                                      ~1      '_serializer'
          2      > JMPZ                                                     ~1, ->9
  158     3    >   FETCH_OBJ_R                                      ~2      '_serializer'
          4        INIT_METHOD_CALL                                         ~2, 'serialize'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
          8      > JMP                                                      ->21
  159     9    >   TYPE_CHECK                                   12          !0
         10      > JMPZ                                                     ~5, ->14
  160    11    >   CAST                                          4  ~6      !0
         12        ASSIGN                                                   !0, ~6
         13      > JMP                                                      ->21
  161    14    >   TYPE_CHECK                                   32          !0
         15      > JMPZ                                                     ~8, ->21
  164    16    >   INIT_FCALL                                               'sprintf'
         17        SEND_VAL                                                 '%25F'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $9      
         20        ASSIGN                                                   !0, $9
  166    21    >   CAST                                          6  ~11     !0
         22      > RETURN                                                   ~11
  167    23*     > RETURN                                                   null

End of function _serialize

End of class ManipleCore_Prefs_Adapter_DbTable.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.17 ms | 1412 KiB | 21 Q