idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
59,300 | public function setVisible ( $ visible = true ) { if ( is_string ( $ visible ) && 'false' == strtolower ( $ visible ) ) { $ visible = false ; } $ this -> _visible = ( bool ) $ visible ; return $ this ; } | Sets whether the page should be visible or not |
59,301 | public function isVisible ( $ recursive = false ) { if ( $ recursive && isset ( $ this -> _parent ) && $ this -> _parent instanceof Page ) { if ( ! $ this -> _parent -> isVisible ( true ) ) { return false ; } } return $ this -> _visible ; } | Returns a boolean value indicating whether the page is visible |
59,302 | public function setParent ( Container $ parent = null ) { if ( $ parent === $ this ) { throw new Exception ( 'A page cannot have itself as a parent' ) ; } if ( $ parent === $ this -> _parent ) { return $ this ; } if ( null !== $ this -> _parent ) { $ this -> _parent -> removePage ( $ this ) ; } $ this -> _parent = $ pa... | Sets parent container |
59,303 | public function set ( $ property , $ value ) { if ( ! is_string ( $ property ) || empty ( $ property ) ) { throw new Exception ( 'Invalid argument: $property must be a non-empty string' ) ; } $ method = 'set' . self :: _normalizePropertyName ( $ property ) ; if ( $ method != 'setOptions' && $ method != 'setConfig' && m... | Sets the given property |
59,304 | public function get ( $ property ) { if ( ! is_string ( $ property ) || empty ( $ property ) ) { throw new Exception ( 'Invalid argument: $property must be a non-empty string' ) ; } $ method = 'get' . self :: _normalizePropertyName ( $ property ) ; if ( method_exists ( $ this , $ method ) ) { return $ this -> $ method ... | Returns the value of the given property |
59,305 | public function __isset ( $ name ) { $ method = 'get' . self :: _normalizePropertyName ( $ name ) ; if ( method_exists ( $ this , $ method ) ) { return true ; } return isset ( $ this -> _properties [ $ name ] ) ; } | Checks if a property is set |
59,306 | public function addRel ( $ relation , $ value ) { if ( is_string ( $ relation ) ) { $ this -> _rel [ $ relation ] = $ value ; } return $ this ; } | Adds a forward relation to the page |
59,307 | public function addRev ( $ relation , $ value ) { if ( is_string ( $ relation ) ) { $ this -> _rev [ $ relation ] = $ value ; } return $ this ; } | Adds a reverse relation to the page |
59,308 | public function removeRel ( $ relation ) { if ( isset ( $ this -> _rel [ $ relation ] ) ) { unset ( $ this -> _rel [ $ relation ] ) ; } return $ this ; } | Removes a forward relation from the page |
59,309 | public function removeRev ( $ relation ) { if ( isset ( $ this -> _rev [ $ relation ] ) ) { unset ( $ this -> _rev [ $ relation ] ) ; } return $ this ; } | Removes a reverse relation from the page |
59,310 | public function addAttribute ( $ key , $ value = null ) { $ this -> element -> addAttribute ( $ key , $ value ) ; return $ this ; } | Add attribute on element |
59,311 | protected function showHelp ( $ msg = '' , $ code = 0 ) { $ usage = Cli :: color ( 'USAGE:' , 'brown' ) ; $ commands = Cli :: color ( 'COMMANDS:' , 'brown' ) ; $ sOptions = Cli :: color ( 'SPECIAL OPTIONS:' , 'brown' ) ; $ pOptions = Cli :: color ( 'PUBLIC OPTIONS:' , 'brown' ) ; $ version = Cli :: color ( self :: VERS... | Shows the scripts help info with optional error message |
59,312 | public function isValid ( $ key ) { if ( ! isset ( $ this [ 'sso' ] , $ this [ 'sig' ] ) ) { return false ; } return $ this [ 'sig' ] === Secret :: create ( $ key ) -> sign ( $ this [ 'sso' ] ) ; } | Checks the validity of this QueryString s against a secret key . |
59,313 | public static function fromString ( $ query , array $ data = [ ] ) { $ url = parse_url ( $ query ) ; $ query = isset ( $ url [ 'query' ] ) ? $ url [ 'query' ] : $ url [ 'path' ] ; parse_str ( $ query , $ data ) ; return new QueryString ( $ data ) ; } | Creates a QueryString from a string . |
59,314 | static public function normalize ( array $ params ) { $ qs = http_build_query ( $ params , null , '&' ) ; if ( '' == $ qs ) { return '' ; } $ parts = array ( ) ; $ order = array ( ) ; foreach ( explode ( '&' , $ qs ) as $ param ) { if ( '' === $ param || '=' === $ param [ 0 ] ) { continue ; } $ keyValuePair = explode (... | Builds a normalized query string from the given parameters . |
59,315 | private function resolveContainer ( ) : ContainerInterface { if ( $ this -> container === null ) { $ container = $ this -> containerFactory -> build ( $ this ) ; if ( ! $ container instanceof ContainerInterface ) { throw new \ RuntimeException ( "Invalid factory result, expected ContainerInterface" ) ; } $ this -> cont... | Instantiate the container if not and return it |
59,316 | public function listAction ( Request $ request ) { $ theme = $ request -> attributes -> get ( 'synapse_theme' , $ this -> container -> get ( 'synapse' ) -> enableDefaultTheme ( ) -> getCurrentTheme ( ) ) ; $ templateCollection = $ this -> container -> get ( 'synapse.template.loader' ) -> retrieveAll ( array ( 'scope' =... | Templates listing action . |
59,317 | public function initAction ( Request $ request , $ templateType , $ contentType , $ contentId = null ) { $ templateDomain = $ this -> container -> get ( 'synapse.template.domain' ) ; $ template = empty ( $ contentId ) ? $ templateDomain -> createGlobal ( $ contentType , $ templateType ) : $ templateDomain -> createLoca... | Template init action . |
59,318 | public function editAction ( $ id , Request $ request ) { $ template = $ this -> container -> get ( 'synapse.template.orm_loader' ) -> retrieveOne ( array ( 'id' => $ id , 'scope' => TemplateInterface :: GLOBAL_SCOPE ) ) ; if ( ! $ template ) { throw new NotFoundHttpException ( sprintf ( 'No global template found for i... | Global template edition action . Requires an activated or activable theme . |
59,319 | public function addComponentAction ( $ id , $ zoneTypeId , $ componentTypeId , Request $ request ) { if ( ! $ template = $ this -> container -> get ( 'synapse.template.loader' ) -> retrieve ( $ id ) ) { throw new NotFoundHttpException ( sprintf ( 'No template found under id "%s"' , $ id ) ) ; } if ( ! $ zoneType = $ te... | Adds a component of given type id into given template id and zone type id . |
59,320 | public function getBuildableEnvironmentsByApplication ( Application $ application ) { $ region = sprintf ( self :: ENV_QUERY_REGION , $ application -> id ( ) ) ; $ dql = sprintf ( self :: DQL_BY_APPLICATION , Target :: class , Environment :: class ) ; $ query = $ this -> getEntityManager ( ) -> createQuery ( $ dql ) ->... | Get all buildable environments for an application . |
59,321 | public function clearBuildableEnvironmentsByApplication ( Application $ application ) { $ region = sprintf ( self :: ENV_QUERY_REGION , $ application -> id ( ) ) ; $ cache = $ this -> getEntityManager ( ) -> getCache ( ) ; $ cache -> getQueryCache ( $ region ) -> clear ( ) ; } | Clear cache for buildable environments for an application . |
59,322 | public function addCookie ( string $ key , $ value , \ DateTimeInterface $ expire ) { $ this -> cookies [ $ key ] = $ this -> cookieFactory -> build ( $ key , $ value , $ expire ) ; } | Adds a cookie |
59,323 | public function send ( ) { $ this -> sendCookies ( ) ; $ this -> sendHeaders ( ) ; if ( $ this -> request -> server ( 'REQUEST_METHOD' ) === 'HEAD' ) { return '' ; } echo $ this -> body ; } | Sends the response to the client |
59,324 | private function sendHeaders ( ) { if ( ! array_key_exists ( 'Content-Type' , $ this -> headers ) ) { $ this -> headers [ 'Content-Type' ] = 'text/html; charset=UTF-8' ; } $ this -> headers [ 'Content-Length' ] = strlen ( $ this -> body ) ; header ( sprintf ( 'HTTP/%s %s %s' , $ this -> request -> server ( 'SERVER_PROT... | Sends the headers to the client |
59,325 | public function getImageUrl ( $ size = 'thumbnail' ) { $ res = wp_get_attachment_image_src ( $ this -> getId ( ) , $ size ) ; return $ res && isset ( $ res [ 0 ] ) ? $ res [ 0 ] : null ; } | Get attachment image URL . |
59,326 | public function save ( ) { if ( $ this -> id ) { $ this -> id = shmop_open ( $ this -> key , $ this -> mode , $ this -> permission , $ this -> size ) ; } @ shmop_write ( $ this -> id , serialize ( $ this -> data ) , $ this -> offset ) ; return true ; } | saves the data of an entry |
59,327 | public function delete ( ) { if ( empty ( $ this -> id ) ) { $ this -> id = shmop_open ( $ this -> key , $ this -> mode , $ this -> permission , $ this -> size ) ; } @ shmop_delete ( $ this -> id ) ; @ shmop_close ( $ this -> id ) ; return true ; } | deletes the entry |
59,328 | public function validate ( Request $ request , array $ rules , array $ messages = [ ] ) { foreach ( $ rules as $ param => $ options ) { $ value = $ request -> getParam ( $ param ) ; $ this -> data [ $ param ] = $ value ; $ isRule = $ options instanceof V ; try { if ( $ isRule ) { $ options -> assert ( $ value ) ; } els... | Validate request params with the given rules |
59,329 | public function addErrors ( $ param , array $ messages ) { foreach ( $ messages as $ message ) { $ this -> errors [ $ param ] [ ] = $ message ; } return $ this ; } | Add errors for param |
59,330 | public function setDelay ( $ delay ) { if ( is_string ( $ delay ) && ctype_digit ( $ delay ) ) { $ delay = ( int ) $ delay ; } elseif ( ! is_int ( $ delay ) ) { throw new \ RuntimeException ( 'Delay should be an integer in MS.' ) ; } $ this -> delay = $ delay ; return $ this ; } | Defines how long the client should wait for the AlphaRPC instances to respond . If the time is reached the next AlphaRPC instance will be asked to execute the request . |
59,331 | public function setTimeout ( $ timeout ) { if ( is_string ( $ timeout ) && ctype_digit ( $ timeout ) ) { $ timeout = ( int ) $ timeout ; } elseif ( ! is_int ( $ timeout ) ) { throw new \ RuntimeException ( 'Unable to set timeout.' ) ; } $ this -> timeout = $ timeout ; return $ this ; } | Sets the timeout in MS . |
59,332 | public function addManager ( $ manager ) { if ( is_array ( $ manager ) ) { foreach ( $ manager as $ item ) { $ this -> managerList -> add ( $ item ) ; } return $ this ; } $ this -> managerList -> add ( $ manager ) ; return $ this ; } | Adds an address to a AlphaRPC daemon . |
59,333 | public function startRequest ( $ function , array $ params = array ( ) , $ cache = null ) { if ( $ cache !== null && ! is_string ( $ cache ) ) { throw new \ RuntimeException ( '$cache is an id for the request and should be a string or null.' ) ; } $ request = new Request ( $ function , $ params ) ; $ prioritizedManager... | Starts a request . |
59,334 | public function request ( $ function , array $ params = array ( ) , $ cache = null ) { $ request = $ this -> startRequest ( $ function , $ params , $ cache ) ; return $ this -> fetchResponse ( $ request ) ; } | Does a full request and returns the result . |
59,335 | protected function getSocket ( $ server ) { if ( isset ( $ this -> socket [ $ server ] ) ) { return $ this -> socket [ $ server ] ; } $ context = new ZMQContext ( ) ; $ socket = Socket :: create ( $ context , ZMQ :: SOCKET_REQ , $ this -> logger ) ; $ socket -> connect ( $ server ) ; $ this -> socket [ $ server ] = $ s... | Returns a socket for the given server . |
59,336 | protected function serializeParams ( array $ params ) { $ serialized = array ( ) ; foreach ( $ params as $ param ) { $ serialized [ ] = $ this -> serializer -> serialize ( $ param ) ; } return $ serialized ; } | Serializes parameters . |
59,337 | protected function sendExecuteRequest ( $ manager , Request $ request , $ cache = null ) { $ serialized = $ this -> serializeParams ( $ request -> getParams ( ) ) ; $ msg = new ExecuteRequest ( $ cache , $ request -> getFunction ( ) , $ serialized ) ; $ socket = $ this -> getSocket ( $ manager ) ; $ stream = $ socket -... | Send a request to the ClientHandler . |
59,338 | public function fetchResponse ( Request $ request , $ waitForResult = true ) { if ( $ request -> hasResponse ( ) ) { return $ request -> getResponse ( ) ; } $ timer = $ this -> getFetchTimer ( $ waitForResult ) ; $ req = new FetchRequest ( $ request -> getRequestId ( ) , $ waitForResult ) ; do { try { $ response = $ th... | Fetches the response for a request . |
59,339 | private function getManagerForRequest ( Request $ request ) { if ( ! $ request -> getManager ( ) ) { $ request -> setManager ( $ this -> managerList -> get ( ) ) ; } return $ request -> getManager ( ) ; } | Returns a manager for the Request . |
59,340 | private function decodeLockFile ( ) : array { $ data = [ ] ; $ encoder = $ this -> jsonEncoderFactory -> getEncoder ( ) ; if ( file_exists ( $ this -> rootDirectory . 'composer.lock' ) ) { $ data = $ encoder -> decode ( file_get_contents ( $ this -> rootDirectory . 'composer.lock' ) , JsonEncoder :: FORMAT ) ; } return... | Returns the decoded lock file data . |
59,341 | public function executeRule ( $ user , $ item , $ params ) { if ( $ item -> ruleName === null ) { return true ; } $ rule = $ this -> domain -> rule -> getRule ( $ item -> ruleName ) ; if ( $ rule instanceof Rule ) { return $ rule -> execute ( $ user , $ item , $ params ) ; } throw new InvalidConfigException ( "Rule not... | Executes the rule associated with the specified auth item . |
59,342 | public function install ( array $ data , $ db ) { $ this -> db = $ db ; $ this -> data = $ data ; $ this -> data [ 'step' ] = 0 ; if ( GC_CLI ) { $ this -> installCli ( ) ; return array ( ) ; } return $ this -> installHttp ( ) ; } | Performs initial system installation . Step 0 |
59,343 | protected function installHttp ( ) { $ result = array ( 'message' => '' , 'severity' => 'success' , 'redirect' => 'install/' . ( $ this -> data [ 'step' ] + 1 ) ) ; try { $ this -> start ( ) ; $ this -> process ( ) ; } catch ( Exception $ ex ) { $ result = array ( 'redirect' => '' , 'severity' => 'warning' , 'message' ... | Performs installation via classic web UI |
59,344 | protected function installCli ( ) { try { $ this -> process ( ) ; $ this -> installCliStep1 ( ) ; $ this -> installCliStep2 ( ) ; $ this -> installCliStep3 ( ) ; $ this -> cli -> line ( $ this -> getSuccessMessage ( ) ) ; } catch ( Exception $ ex ) { $ this -> cli -> error ( $ ex -> getMessage ( ) ) ; } } | Install in CLI mode |
59,345 | protected function installCliStep1 ( ) { $ this -> data [ 'step' ] = 1 ; $ this -> setCliMessage ( 'Configuring modules...' ) ; $ result = $ this -> installModules ( $ this -> data , $ this -> db ) ; if ( $ result [ 'severity' ] !== 'success' ) { throw new UnexpectedValueException ( $ result [ 'message' ] ) ; } } | Process step 1 in CLI mode |
59,346 | protected function installCliStep2 ( ) { $ title = $ this -> translation -> text ( 'Please select a demo content package (enter a number)' ) ; $ this -> data [ 'demo_handler_id' ] = $ this -> cli -> menu ( $ this -> getDemoOptions ( ) , '' , $ title ) ; if ( ! empty ( $ this -> data [ 'demo_handler_id' ] ) ) { $ this -... | Process step 2 in CLI mode |
59,347 | protected function installCliStep3 ( ) { $ this -> data [ 'step' ] = 3 ; $ result = $ this -> installFinish ( $ this -> data , $ this -> db ) ; if ( $ result [ 'severity' ] !== 'success' ) { throw new UnexpectedValueException ( $ result [ 'message' ] ) ; } } | Precess step 3 in CLI mode |
59,348 | public function installModules ( array $ data , $ db ) { $ this -> db = $ db ; $ this -> data = $ data ; try { $ this -> install_model -> installModules ( ) ; $ this -> configureModules ( ) ; return array ( 'message' => '' , 'severity' => 'success' , 'redirect' => 'install/' . ( $ this -> data [ 'step' ] + 1 ) ) ; } ca... | Installs required modules . Step 1 |
59,349 | public function installDemo ( array $ data , $ db ) { set_time_limit ( 0 ) ; $ this -> db = $ db ; $ this -> data = $ data ; $ success_result = array ( 'message' => '' , 'severity' => 'success' , 'redirect' => 'install/' . ( $ this -> data [ 'step' ] + 1 ) ) ; if ( empty ( $ data [ 'demo_handler_id' ] ) ) { return $ su... | Install a demo - content . Step 2 |
59,350 | public function installFinish ( array $ data , $ db ) { $ this -> db = $ db ; $ this -> data = $ data ; $ result = $ this -> finish ( ) ; $ errors = $ this -> getContextErrors ( ) ; if ( empty ( $ errors ) ) { if ( $ this -> getContext ( 'demo_handler_id' ) ) { $ store_id = $ this -> getContext ( 'store_id' ) ; $ this ... | Performs final tasks . Step 3 |
59,351 | protected function getDemoOptions ( ) { $ options = array ( '' => $ this -> translation -> text ( 'No demo' ) ) ; foreach ( $ this -> install_model -> getDemoHandlers ( ) as $ id => $ handler ) { $ options [ $ id ] = $ handler [ 'title' ] ; } return $ options ; } | Returns an array of demo content options |
59,352 | protected function configureModuleDevice ( ) { $ store_id = $ this -> getContext ( 'store_id' ) ; $ settings = array ( ) ; $ settings [ 'theme' ] [ $ store_id ] [ 'mobile' ] = 'mobile' ; $ settings [ 'theme' ] [ $ store_id ] [ 'tablet' ] = 'mobile' ; $ this -> module -> setSettings ( 'device' , $ settings ) ; } | Configure Device module settings |
59,353 | protected function configureModuleGaReport ( ) { $ info = $ this -> module -> getInfo ( 'ga_report' ) ; $ info [ 'settings' ] [ 'dashboard' ] = array ( 'visit_date' , 'pageview_date' , 'content_statistic' , 'top_pages' , 'source' , 'keyword' , 'audience' ) ; $ this -> module -> setSettings ( 'ga_report' , $ info [ 'set... | Configure Google Analytics Report module settings |
59,354 | public function initialize ( $ url , $ reset = true ) { if ( ( bool ) $ reset ) $ this -> reset ( ) ; $ this -> currentRequestUrl = $ url ; $ this -> state = self :: STATE_INITIALIZED ; return $ this ; } | Create a new CURL resource |
59,355 | public function setRequestHeader ( $ name , $ value ) { if ( ! is_string ( $ name ) ) throw new \ InvalidArgumentException ( 'Argument 1 expected to be string, ' . gettype ( $ name ) . ' seen.' ) ; if ( ! is_string ( $ value ) ) throw new \ InvalidArgumentException ( 'Argument 2 expected to be string, ' . gettype ( $ v... | Add a header string to the request |
59,356 | public function setCurlOpt ( $ opt , $ val ) { if ( ! is_int ( $ opt ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s::setCurlOpt - Argument 1 expected to be integer, %s seen.' , get_class ( $ this ) , gettype ( $ opt ) ) ) ; } $ this -> curlOpts [ $ opt ] = $ val ; return $ this ; } | Set CURL option |
59,357 | public function close ( ) { if ( 'resource' === gettype ( $ this -> ch ) ) curl_close ( $ this -> ch ) ; $ this -> state = self :: STATE_CLOSED ; return $ this ; } | Close the curl resource if exists |
59,358 | public function reset ( ) { $ this -> close ( ) ; $ this -> curlOpts = array ( ) ; $ this -> requestHeaders = array ( ) ; $ this -> currentRequestUrl = null ; $ this -> state = self :: STATE_NEW ; return $ this ; } | Reset to new state |
59,359 | public function curlOptSet ( $ opt ) { return isset ( $ this -> curlOpts [ $ opt ] ) || array_key_exists ( $ opt , $ this -> curlOpts ) ; } | Returns true if passed in curl option has a value |
59,360 | public function execute ( $ resetAfterExecution = false ) { $ this -> buildRequest ( ) ; $ response = new CurlPlusResponse ( curl_exec ( $ this -> ch ) , curl_getinfo ( $ this -> ch ) , curl_error ( $ this -> ch ) , $ this -> getCurlOpts ( ) ) ; if ( $ resetAfterExecution ) $ this -> reset ( ) ; return $ response ; } | Execute CURL command |
59,361 | protected function buildRequest ( ) { if ( self :: STATE_NEW === $ this -> state ) { throw new \ RuntimeException ( sprintf ( '%s::execute - Could not execute request, curl has not been initialized.' , get_class ( $ this ) ) ) ; } if ( self :: STATE_EXECUTED === $ this -> state ) $ this -> close ( ) ; if ( self :: STAT... | Attempts to set up the client for a request throws an exception if it cannot |
59,362 | public static function merge ( array $ array ) { $ result = array ( ) ; foreach ( $ array as $ config ) { if ( is_string ( $ config ) ) { if ( ! file_exists ( $ config ) ) { continue ; } $ config = require ( $ config ) ; } if ( ! is_array ( $ config ) ) { continue ; } $ result = self :: mergeArray ( $ result , $ config... | Merges the given configurations into a single configuration array . |
59,363 | public function parent ( Int $ index = 1 ) : stdClass { return $ this -> _layer ( $ this -> debug , $ index , $ index + 1 ) ; } | Parent Debug Data |
59,364 | protected function resolveDumpPath ( ) { $ path = $ this -> basePath . '/' . $ this -> dumpPath ; $ this -> ensureDirectory ( $ path ) ; return realpath ( $ path ) . '/' . $ this -> dumpFile ; } | Returns the path to the dump - file . |
59,365 | protected function normalizeOptions ( $ options ) { $ result = array ( ) ; foreach ( $ options as $ name => $ value ) { $ result [ ] = "--$name=\"$value\"" ; } return implode ( ' ' , $ result ) ; } | Normalizes the given options to a string |
59,366 | protected function getDb ( ) { if ( isset ( $ this -> _db ) ) { return $ this -> _db ; } else { if ( ( $ db = Yii :: app ( ) -> getComponent ( $ this -> connectionID ) ) === null ) { throw new CException ( sprintf ( 'Failed to get database connection. Component %s not found.' , $ this -> connectionID ) ) ; } return $ t... | Returns the database connection component . |
59,367 | public function get ( $ name ) { if ( ! $ this -> attributeExists ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribute does not exist!' ) ; } if ( ! $ this -> attributeGet ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribute get is disabled!' ) ; } i... | Return an attribute value if allowed by attribute getter |
59,368 | public function set ( $ name , $ val , $ validate = TRUE ) { if ( ! $ this -> attributeExists ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribute does not exist!' ) ; } if ( ! $ this -> attributeSet ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribu... | Set an attribute value if allowed by attribute setter |
59,369 | public function reset ( $ name ) { if ( ! $ this -> attributeExists ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribute does not exist!' ) ; } if ( ! $ this -> attributeReset ( $ name ) ) { throw new Exception ( get_called_class ( ) . '->' . $ name . ' attribute reset is disabled!' )... | Reset an attribute value to its default |
59,370 | public function resetPK ( $ val = FALSE ) { if ( $ val === FALSE ) { $ this -> reset ( static :: $ pk ) ; } else { $ this -> attributeValues [ static :: $ pk ] = $ val ; } } | Reset the primary key to default or set to a specific value |
59,371 | public function cast ( $ name , $ val ) { if ( is_null ( $ val ) ) { return $ val ; } switch ( @ static :: $ attributes [ $ name ] [ 'type' ] ) { case self :: TYPE_INT : $ val = ( int ) $ val ; break ; case self :: TYPE_STRING : $ val = ( string ) $ val ; break ; case self :: TYPE_BOOL : $ val = ( bool ) $ val ; break ... | Cast a value for an attribute datatype |
59,372 | public function create ( $ exclude = array ( ) , & $ db = FALSE ) { $ create = $ this -> createColumnsAndValues ( $ exclude ) ; if ( $ db === FALSE ) { $ db = & $ this -> getDbMaster ( ) ; } $ query = $ db -> prepare ( ' INSERT INTO `' . static :: $ dbTable . '` (' . $ create [ 'columns' ] . ') VALUES ( ' . $ create ... | Create object in the database |
59,373 | public function createOrUpdate ( $ update , $ exclude = array ( ) , & $ db = FALSE ) { $ create = $ this -> createColumnsAndValues ( $ exclude ) ; $ updateVals = NULL ; foreach ( $ update as $ column => $ value ) { $ updateVals .= ', `' . $ column . '` = ' ; $ updateVals .= is_array ( $ value ) ? $ value [ 0 ] : $ valu... | Create or update an object in the database if it already exists |
59,374 | private function createColumnsAndValues ( & $ exclude ) { if ( ! $ this -> attributeHasValue ( static :: $ pk ) ) { $ exclude [ ] = static :: $ pk ; } $ columns = NULL ; $ values = NULL ; foreach ( static :: $ attributes as $ name => $ attribute ) { if ( in_array ( $ name , $ exclude ) ) { continue ; } if ( ! $ this ->... | Generate create query columns and values |
59,375 | private function transformValue ( $ name , $ attribute , & $ exclude ) { $ value = $ this -> iget ( $ name ) ; if ( is_null ( $ value ) || ( isset ( $ attribute [ 'null' ] ) && $ attribute [ 'null' ] && $ value === '' ) ) { $ this -> iset ( $ name , NULL ) ; $ value = 'NULL' ; $ exclude [ ] = $ name ; } else { switch (... | Apply any attribute value transformations for SQL query |
59,376 | private function bindAttributes ( & $ query , $ exclude = array ( ) ) { foreach ( array_keys ( static :: $ attributes ) as $ name ) { if ( in_array ( $ name , $ exclude ) ) { continue ; } $ query -> bindValue ( ':' . $ name , $ this -> iget ( $ name ) ) ; } } | Bind object attribute values to the query |
59,377 | private function executeCreateUpdateQuery ( & $ query ) { try { $ query -> execute ( ) ; return TRUE ; } catch ( \ PDOException $ e ) { switch ( $ e -> getCode ( ) ) { case 23000 : if ( preg_match ( '/Duplicate entry \'(.*?)\' for key \'(.*?)\'/' , $ e -> getMessage ( ) , $ match ) ) { $ name = $ this -> attributeExist... | Execute create or update query and cope with an exception |
59,378 | public function read ( $ pkValue = FALSE , & $ db = FALSE ) { try { if ( $ pkValue !== FALSE ) { $ this -> iset ( static :: $ pk , $ pkValue ) ; } if ( $ db === FALSE ) { $ db = & $ this -> getDbSlave ( ) ; } $ query = $ db -> prepare ( ' SELECT * FROM `' . static :: $ dbTable . '` WHERE ' . static :: $ pk . ' = :p... | Read an object from the database populating the object attributes |
59,379 | public function readAttribute ( $ name ) { $ this -> iset ( $ name , $ this -> getValue ( array ( 'select' => $ name , 'where' => array ( array ( static :: $ pk , $ this -> iget ( static :: $ pk ) ) ) ) ) ) ; } | Read and set a single object attribute from the database |
59,380 | public function update ( $ exclude = array ( ) , & $ db = FALSE ) { if ( $ db === FALSE ) { $ db = & $ this -> getDbMaster ( ) ; } $ old = FALSE ; if ( $ this -> changelog ( 'update' ) ) { $ old = static :: _Read ( $ this -> get ( static :: $ pk ) , $ db ) ; } $ exclude [ ] = static :: $ pk ; $ values = NULL ; foreach ... | Update an object in the database |
59,381 | public function hookTransactions ( Resource \ Db & $ parent , Resource \ Db & $ child = NULL ) { if ( ! $ child ) { $ child = & $ this -> getResource ( 'db' ) ; } if ( $ parent -> getTransactionCount ( ) > 0 && $ parent -> addTransactionHook ( $ child ) ) { $ child -> beginTransaction ( ) ; } } | Hook any database queries into another database transaction so that the queries are commited and rolled back at the same point |
59,382 | public function toXML ( $ attributes = FALSE ) { $ class = str_replace ( '\\' , '_' , str_replace ( 'sonic\\model\\' , '' , strtolower ( get_called_class ( ) ) ) ) ; $ doc = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ node = $ doc -> createElement ( $ class ) ; $ doc -> appendChild ( $ node ) ; $ arr = $ this -> toArray ... | Return a DOM tree with object attributes |
59,383 | public function toJSON ( $ attributes = FALSE , $ addClass = FALSE ) { $ arr = $ this -> toArray ( $ attributes ) ; if ( $ addClass ) { $ arr [ 'class' ] = str_replace ( '\\' , '_' , str_replace ( 'sonic\\model\\' , '' , strtolower ( get_called_class ( ) ) ) ) ; } return json_encode ( $ arr ) ; } | Return a JSON encoded string with object attributes |
59,384 | public function fromArray ( $ attributes , $ removeClass = FALSE , $ validate = TRUE , $ required = array ( ) , $ valid = array ( ) ) { if ( $ removeClass ) { $ arr = array ( ) ; $ class = strtolower ( $ this -> getClass ( ) ) ; foreach ( array_keys ( static :: $ attributes ) as $ name ) { if ( isset ( $ attributes [ $... | Populate object attributes from an array |
59,385 | public function getChildren ( $ class , $ recursive = FALSE , $ index = FALSE , $ key = FALSE , $ params = array ( ) ) { $ children = self :: _getChildren ( $ class , $ this -> iget ( self :: $ pk ) , $ recursive , $ key , $ params ) ; if ( $ index ) { $ children = static :: _getChildrenIndex ( $ children ) ; } return ... | Return child objects matching class type |
59,386 | public function getValue ( $ params , $ fetchMode = \ PDO :: FETCH_ASSOC , & $ db = FALSE ) { if ( $ db === FALSE ) { $ db = & self :: _getDbSlave ( ) ; } $ params [ 'from' ] = '`' . static :: $ dbTable . '`' ; return $ db -> getValue ( $ params , $ fetchMode ) ; } | Return a single row |
59,387 | public function & getResource ( $ name ) { if ( ! isset ( $ this -> resources [ $ name ] ) ) { $ bln = FALSE ; return $ bln ; } return $ this -> resources [ $ name ] ; } | Return a class resource reference |
59,388 | public function setResource ( $ name , $ resource ) { $ obj = & Sonic :: getResource ( $ resource ) ; if ( ! $ obj ) { return FALSE ; } $ this -> setResourceObj ( $ name , $ obj ) ; return TRUE ; } | Set an internal resource from a framework resource |
59,389 | public function setResourceObj ( $ name , & $ resource ) { $ this -> resources [ $ name ] = & $ resource ; if ( isset ( $ this -> $ name ) ) { $ this -> $ name = & $ this -> resources [ $ name ] ; } } | Set a class resource from the resource object |
59,390 | public function removeResource ( $ name ) { if ( isset ( $ this -> resources [ $ name ] ) ) { unset ( $ this -> resources [ $ name ] ) ; if ( isset ( $ this -> $ name ) ) { unset ( $ this -> $ name ) ; } } } | Remove a class resource |
59,391 | public function removeResources ( ) { foreach ( array_keys ( $ this -> resources ) as $ name ) { if ( isset ( $ this -> $ name ) ) { unset ( $ this -> $ name ) ; } } unset ( $ this -> resources ) ; } | Remove all class resources |
59,392 | public static function _attributeProperties ( $ name , $ property = FALSE ) { if ( isset ( static :: $ attributes [ $ name ] ) ) { if ( $ property ) { if ( ! isset ( static :: $ attributes [ $ name ] [ $ property ] ) ) { return FALSE ; } return static :: $ attributes [ $ name ] [ $ property ] ; } return static :: $ att... | Return an attribute parameters array or FALSE if it doesnt exist Also pass option property array to return a single attribute property |
59,393 | public static function _read ( $ params , & $ db = FALSE ) { $ obj = new static ; if ( is_array ( $ params ) ) { $ params [ 'select' ] = '*' ; $ row = static :: _getValue ( $ params , \ PDO :: FETCH_ASSOC , $ db ) ; if ( ! $ row ) { return FALSE ; } foreach ( $ row as $ name => $ val ) { if ( $ obj -> attributeExists (... | Create a new object instance and read it from the database populating the object attributes |
59,394 | public static function _count ( $ params = array ( ) , & $ db = FALSE ) { if ( isset ( $ params [ 'orderby' ] ) ) { unset ( $ params [ 'orderby' ] ) ; } if ( isset ( $ params [ 'limit' ] ) ) { unset ( $ params [ 'limit' ] ) ; } $ params [ 'select' ] = 'COUNT(*)' ; return static :: _getValue ( $ params , \ PDO :: FETCH_... | Return the number of objects in the database matching the parameters |
59,395 | public static function _exists ( $ params , & $ db = FALSE ) { if ( ! is_array ( $ params ) ) { $ params = array ( 'where' => array ( array ( static :: $ pk , $ params ) ) ) ; } return self :: _count ( $ params , $ db ) > 0 ; } | Check to see whether the object matching the parameters exists |
59,396 | public static function _getObjects ( $ params = array ( ) , $ key = FALSE , & $ db = FALSE ) { if ( ! isset ( $ params [ 'select' ] ) ) { $ params [ 'select' ] = '*' ; } $ rows = static :: _getValues ( $ params , $ db ) ; if ( $ rows === FALSE ) { return FALSE ; } return self :: _arrayToObjects ( $ rows , $ key ) ; } | Create and return an array of objects for query parameters |
59,397 | public static function _queryToObjects ( $ query , $ key = FALSE ) { $ query -> execute ( ) ; return static :: _arrayToObjects ( $ query -> fetchAll ( \ PDO :: FETCH_ASSOC ) , $ key ) ; } | Execute a PDOStatement query and convert the results into objects |
59,398 | public static function _arrayToObjects ( $ arr , $ key = FALSE ) { $ objs = new Resource \ Model \ Collection ; if ( ! $ arr ) { return $ objs ; } foreach ( $ arr as $ row ) { $ obj = new static ; foreach ( $ row as $ name => $ val ) { if ( $ obj -> attributeExists ( $ name ) ) { $ obj -> iset ( $ name , $ val , FALSE ... | Convert an array into objects |
59,399 | public static function _genQuery ( $ params , & $ db = FALSE ) { if ( ! isset ( $ params [ 'select' ] ) ) { $ params [ 'select' ] = '*' ; } if ( ! isset ( $ params [ 'from' ] ) ) { $ params [ 'from' ] = '`' . static :: $ dbTable . '`' ; } if ( $ db === FALSE ) { $ db = & self :: _getDbSlave ( ) ; } if ( ! ( $ db instan... | Generate a query and return the PDOStatement object |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.