idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
32,100 | public function move ( $ direct = null , $ id = null , $ delta = 1 ) { $ this -> loadModel ( 'CakeLdap.ConfigSync' ) ; if ( ! $ this -> ConfigSync -> getFlagTreeSubordinateEnable ( ) ) { throw new InternalErrorException ( __d ( 'cake_ldap' , 'The database does not contain information on the tree view' ) ) ; } $ this -> Move -> moveItem ( $ direct , $ id , $ delta ) ; } | Action move . Used to move employee to new position . |
32,101 | public function drop ( ) { $ this -> loadModel ( 'CakeLdap.ConfigSync' ) ; if ( ! $ this -> ConfigSync -> getFlagTreeSubordinateEnable ( ) ) { throw new InternalErrorException ( __d ( 'cake_ldap' , 'The database does not contain information on the tree view' ) ) ; } $ this -> Move -> dropItem ( ) ; } | Action drop . Used to drag and drop employee to new position include new manager . |
32,102 | public static function hydrateImageInfo ( ImageInterface $ image , $ path ) { $ imageSize = getimagesize ( $ path ) ; $ finfo = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ image -> setMimeType ( $ finfo -> file ( $ path ) ) ; if ( $ image -> getMimeType ( ) == 'text/html' ) { $ image -> setMimeType ( 'image/svg+xml' ) ; } $ image -> setExtension ( ( new MimeType ) -> extensionToMimeType ( $ image -> getMimeType ( ) ) ) ; $ image -> setWeight ( filesize ( $ path ) ) ; $ image -> setWidth ( $ imageSize [ 0 ] ) ; $ image -> setHeight ( $ imageSize [ 1 ] ) ; return $ image ; } | Hydrate image info |
32,103 | public function defineImagePath ( ImageInterface $ image , $ prefix = '' ) { return $ this -> definePath ( $ image -> getId ( ) , $ image -> getTitle ( ) , $ image -> getExtension ( ) , $ prefix ) ; } | define final relative path from image |
32,104 | public function getImageSource ( ImageInterface $ image ) { $ path = $ this -> getAbsolutePath ( $ image -> getPath ( ) ) ; if ( ! is_file ( $ path ) ) { throw new IOException ( sprintf ( 'Not found image source "%s"' , $ image -> getId ( ) ) ) ; } return file_get_contents ( $ path ) ; } | get source image |
32,105 | protected function convertToObject ( $ arrayElements ) { $ objects = array ( ) ; foreach ( $ arrayElements as $ key => $ value ) { $ object = new \ stdClass ( ) ; $ object -> name = $ key ; $ object -> value = $ value ; $ objects [ ] = $ object ; } return $ objects ; } | Utility method for converting an associative array into an array of php stdClass objects . Both array keys and array values will be conveted to object properties . |
32,106 | private function getFieldType ( $ field ) : ? string { if ( $ field === null ) { return null ; } $ fieldType = gettype ( $ field ) ; if ( $ fieldType === 'object' ) { $ classNameArray = explode ( '\\' , get_class ( $ field ) ) ; if ( count ( $ classNameArray ) === 0 ) { return null ; } $ fieldType = mb_strtolower ( $ classNameArray [ count ( $ classNameArray ) - 1 ] ) ; } return $ fieldType ; } | Returns the field type of the provided field . |
32,107 | public function getName ( ) { return $ this -> getCachedProperty ( 'name' , function ( ) { return trim ( $ this -> query ( 'atom:name' , self :: SINGLE | self :: REQUIRED ) -> textContent ) ; } ) ; } | Return person name . |
32,108 | public function setName ( $ value ) { $ element = $ this -> query ( 'atom:name' , self :: SINGLE ) ; if ( null === $ element ) { $ element = $ this -> getDomElement ( ) -> ownerDocument -> createElementNS ( $ this -> ns ( ) , 'name' ) ; $ this -> getDomElement ( ) -> appendChild ( $ element ) ; } $ element -> nodeValue = $ value ; $ this -> setCachedProperty ( 'name' , $ value ) ; return $ this ; } | Set person name . |
32,109 | public function send ( $ to , $ subject , $ message , $ from = 'default' , $ headerExtra = [ ] , $ html = true ) { if ( ! is_null ( $ this -> method ) ) { if ( is_string ( $ this -> method ) && ( 'swift' == $ this -> method ) ) { return $ this -> _swiftMail ( $ to , is_string ( $ from ) ? $ this -> from [ $ from ] : $ from , $ subject , $ message , [ ] , $ html ) ; } else { return call_user_func ( $ this -> method , $ to , is_string ( $ from ) ? $ this -> from [ $ from ] : $ from , $ subject , $ message , [ ] , $ headerExtra , $ html ) ; } } return $ this -> _mail ( $ to , is_string ( $ from ) ? $ this -> from [ $ from ] : $ from , $ subject , $ message , [ ] , $ headerExtra , $ html ) ; } | Send simple message with no attachments |
32,110 | public static function ord ( $ char , & $ bytes = null ) { $ firstByte = substr ( $ char , 0 , 1 ) ; $ firstByteCode = ord ( $ firstByte ) ; $ bytes = 0 ; while ( $ firstByteCode >> 7 & 0x01 ) { $ bytes ++ ; $ firstByteCode <<= 1 ; } if ( $ bytes === 0 ) { return ord ( $ firstByte ) ; } $ unicodeOrd = ( ( ord ( $ firstByte ) << ( $ bytes + 1 ) ) & 0xFF ) >> ( $ bytes + 1 ) ; for ( $ i = 1 ; $ i < $ bytes ; $ i ++ ) { $ unicodeOrd <<= 6 ; $ byte = ord ( substr ( $ char , $ i , 1 ) ) & 0b00111111 ; $ unicodeOrd |= $ byte ; } return $ unicodeOrd ; } | Get char code |
32,111 | public static function ordStr ( $ string ) { $ codes = array ( ) ; $ encoding = mb_detect_encoding ( $ string ) ; $ size = mb_strlen ( $ string , $ encoding ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { $ char = mb_substr ( $ string , $ i , 1 , $ encoding ) ; $ codes [ ] = static :: ord ( $ char ) ; } return $ codes ; } | Get char codes from string |
32,112 | public function destroy ( $ id ) { $ address = Address :: findOrFail ( $ id ) ; $ this -> authorize ( 'manage' , $ address ) ; $ address -> delete ( ) ; return fractal ( $ id , new DeletedTransformer ( ) ) -> withResourceName ( 'deletedAddress' ) -> respond ( ) ; } | Delete an Address object |
32,113 | public function store ( Request $ request ) { $ rules = [ "address" => "required|max:256" , "country" => "required" , "label" => "required|max:50" , "municipality" => "required|max:128" , "postcode" => 'required|regex:/^[0-9]{5}(-\d{4})?$/' , "stateProvince" => "required" , ] ; $ request -> validate ( $ this -> addPolymorphicRules ( $ rules , 'addressable' , $ request -> addressableType ) ) ; $ address = new Address ( ) ; $ address -> addressable_id = $ request -> addressableId ; $ address -> addressable_type = $ request -> addressableType ; $ address -> label = $ request -> label ; $ address -> address = $ request -> address ; $ address -> municipality = $ request -> municipality ; $ address -> state_province = $ request -> stateProvince ; $ address -> postcode = $ request -> postcode ; $ address -> country = $ request -> country ; $ this -> authorize ( 'manage' , $ address ) ; $ address -> save ( ) ; return fractal ( $ address , new AddressTransformer ( ) ) -> withResourceName ( 'address' ) -> respond ( ) ; } | Store a newly created Address |
32,114 | public function update ( Request $ request , $ id ) { $ rules = [ "address" => "required|max:256" , "country" => "required" , "label" => "required|max:50" , "municipality" => "required|max:128" , "postcode" => 'required|regex:/^[0-9]{5}(-\d{4})?$/' , "stateProvince" => "required" , ] ; $ request -> validate ( $ this -> addPolymorphicRules ( $ rules , 'addressable' , $ request -> addressableType ) ) ; $ address = Address :: findOrFail ( $ id ) ; $ this -> authorize ( 'manage' , $ address ) ; $ address -> label = $ request -> label ; $ address -> address = $ request -> address ; $ address -> municipality = $ request -> municipality ; $ address -> state_province = $ request -> stateProvince ; $ address -> postcode = $ request -> postcode ; $ address -> country = $ request -> country ; $ address -> save ( ) ; return fractal ( $ address , new AddressTransformer ( ) ) -> withResourceName ( 'address' ) -> respond ( ) ; } | Update an Address |
32,115 | public function findByTokenApiCode ( $ token_api ) { $ model = $ this -> createModel ( ) ; $ result = $ model -> newQuery ( ) -> where ( 'token_api' , '=' , $ token_api ) -> get ( ) ; if ( ( $ count = $ result -> count ( ) ) > 1 ) { throw new \ RuntimeException ( "Found [$count] users with the same token api." ) ; } if ( ! $ user = $ result -> first ( ) ) { throw new UserNotFoundException ( "A user was not found with the given token api." ) ; } return $ user ; } | Finds a user by the given token api code . |
32,116 | public function getImages ( ) { $ images = array ( ) ; $ image = $ this -> getImage ( ) ; if ( ! empty ( $ image ) ) { $ images [ $ image ] = $ image ; } $ screenshotsPath = $ this -> getFilePath ( ) . self :: SCREENSHOT_PATH ; $ files = array ( ) ; if ( is_dir ( $ screenshotsPath ) ) { $ files = scandir ( $ screenshotsPath ) ; } foreach ( $ files as $ file ) { $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; if ( $ ext === 'gif' || $ ext === 'jpg' || $ ext === 'png' ) { $ images [ '/theme/images/screenshots/' . $ file ] = '/theme/images/screenshots/' . $ file ; } } return $ images ; } | getImages permet de recuperer les images depuis le filer |
32,117 | public function add ( PriorityQueueItem $ item ) { $ priority = $ item -> getPriority ( ) ; if ( ! isset ( $ this -> items [ $ priority ] ) ) { $ this -> items [ $ priority ] = array ( $ item ) ; } else { $ this -> items [ $ priority ] [ ] = $ item ; } return $ this ; } | Adds a new item to the priority queue . |
32,118 | protected function mergeItems ( ) { ksort ( $ this -> items ) ; $ this -> mergedItems = array ( ) ; foreach ( $ this -> items as $ items ) { $ this -> mergedItems = array_merge ( $ this -> mergedItems , $ items ) ; } return $ this ; } | Merges the items of the priority queue to one single list paying attention to the priorities . The result is written to the mergedItems property . |
32,119 | public function run ( ) { if ( $ job = $ this -> pop ( ) ) { list ( $ route , $ payload , $ execution ) = $ job ; $ result = $ this -> runJob ( $ route , $ payload ) ; if ( $ result === false ) { if ( $ execution > 1 ) { $ this -> push ( $ route , $ payload , 0 , $ execution - 1 ) ; } else { $ this -> trigger ( self :: EVENT_FAIL , new Event ( [ 'route' => $ route , 'payload' => $ payload ] ) ) ; } } return $ result !== false ; } } | Run top of job in queue . |
32,120 | public static function getInstance ( ) { $ arguments = func_get_args ( ) ; $ arguments = array_shift ( $ arguments ) ; $ callerSignature = get_called_class ( ) ; if ( self :: $ strict === true ) { if ( is_array ( $ arguments ) ) { $ crc = [ ] ; foreach ( $ arguments as $ argument ) { if ( ! is_object ( $ argument ) ) { $ crc [ ] = $ argument ; } } } else { $ crc = $ arguments ; } $ identifier = md5 ( $ callerSignature . serialize ( $ crc ) ) ; } else { $ identifier = md5 ( $ callerSignature ) ; } if ( ! isset ( self :: $ instances [ $ identifier ] ) ) { $ instance = self :: genericInstantiate ( $ callerSignature , $ arguments ) ; self :: $ instances [ $ identifier ] = $ instance ; } else { $ instance = self :: $ instances [ $ identifier ] ; } return $ instance ; } | Instance getter for singleton instances |
32,121 | protected static function getRegistry ( ) { if ( self :: $ registry === null ) { self :: $ registry = Doozr_Registry :: getInstance ( ) ; } return self :: $ registry ; } | Getter for registry |
32,122 | public function getPaths ( ) : array { $ paths = [ ] ; foreach ( $ this -> finder -> getNamespaces ( ) as $ namespace ) { $ name = ( $ namespace !== FileViewFinder :: DEFAULT_NAMESPACE ) ? $ namespace : null ; foreach ( $ this -> finder -> getPaths ( $ namespace ) as $ path ) { $ paths [ ] = new TemplatePath ( $ path , $ name ) ; } } return $ paths ; } | Get the template directories . |
32,123 | public static function getFormValue ( $ name , $ default = '' ) { $ val = filter_input ( INPUT_GET , $ name , FILTER_CALLBACK , array ( 'options' => array ( 'COREPOS\\common\\FormLib' , 'filterCallback' ) ) ) ; if ( $ val === null ) { $ val = filter_input ( INPUT_POST , $ name , FILTER_CALLBACK , array ( 'options' => array ( 'COREPOS\\common\\FormLib' , 'filterCallback' ) ) ) ; } if ( $ val === null ) { $ val = $ default ; } return $ val ; } | Safely fetch a form value |
32,124 | public function remove ( string $ key ) { $ file = $ this -> file ; if ( file_exists ( $ file ) ) { $ data = unserialize ( $ this -> decrypt ( file_get_contents ( $ file ) ) ) ; if ( is_array ( $ data ) && isset ( $ data [ $ key ] ) ) { unset ( $ data [ $ key ] ) ; $ data = $ this -> encrypt ( serialize ( $ data ) ) ; return file_put_contents ( $ file , $ data ) ; } } return false ; } | Remove key from cache file |
32,125 | public function delete ( ) { $ file = $ this -> file ; if ( file_exists ( $ file ) ) return Filesystem :: delete ( $ file ) ; return false ; } | Delete cache file |
32,126 | public function assign ( string $ key , $ value , bool $ overwrite = false ) { $ file = $ this -> file ; if ( file_exists ( $ file ) ) { $ data = unserialize ( $ this -> decrypt ( file_get_contents ( $ file ) ) ) ; if ( is_array ( $ data ) ) { if ( isset ( $ data [ $ key ] ) ) { if ( $ overwrite == true ) { $ data [ $ key ] = $ value ; $ data = $ this -> encrypt ( serialize ( $ data ) ) ; return file_put_contents ( $ file , $ data ) ; } return false ; } else { $ data [ $ key ] = $ value ; $ data = $ this -> encrypt ( serialize ( $ data ) ) ; return file_put_contents ( $ file , $ data ) ; } } } $ data = $ this -> encrypt ( serialize ( [ $ key => $ value ] ) ) ; file_put_contents ( $ file , $ data ) ; return false ; } | Assign new item to key |
32,127 | public function retrieve ( string $ key ) { $ file = $ this -> file ; if ( file_exists ( $ file ) ) { $ data = unserialize ( $ this -> decrypt ( file_get_contents ( $ file ) ) ) ; if ( isset ( $ data [ $ key ] ) ) { return $ data [ $ key ] ; } } return null ; } | Retrieve cached value |
32,128 | public function details ( ) { $ file = $ this -> file ; if ( file_exists ( $ file ) ) { $ data = unserialize ( $ this -> decrypt ( file_get_contents ( $ file ) ) ) ; return [ 'records' => count ( $ data ) , 'size' => round ( filesize ( $ file ) / 1024 , 1 ) , 'updated_at' => date ( 'Y-m-d h:i:s' , filemtime ( $ file ) ) ] ; } return null ; } | Get cache details |
32,129 | private function instance ( $ ds ) { $ path = Config :: get ( 'app.dir' ) . Config :: get ( 'hibernate.cache.storage' ) ; if ( ! is_dir ( $ path ) ) mkdir ( $ path , 0777 , true ) ; if ( ! is_dir ( $ path ) ) throw new CachePermissionException ; $ this -> file = $ path . $ ds . 'hibernate.dat' ; } | Prepare the cache |
32,130 | protected function process ( $ filename , $ uuid ) { $ configuration = $ this -> readFile ( $ filename , $ uuid ) ; $ directives = array ( self :: DIRECTIVE_INCLUDE => false , self :: DIRECTIVE_REQUIRE => true , ) ; foreach ( $ directives as $ directive => $ strict ) { $ extracted = $ this -> extractDirectives ( $ directive , $ configuration ) ; foreach ( $ extracted [ 1 ] as $ index => $ include ) { $ includeFilename = realpath ( dirname ( $ filename ) . DIRECTORY_SEPARATOR . $ include ) ; if ( $ includeFilename !== false ) { $ content = $ this -> readFile ( $ includeFilename ) ; } elseif ( $ strict === false ) { $ content = '{}' ; } else { throw new Doozr_Configuration_Exception ( 'The file "' . $ filename . '" could not be included. Sure it exists?' ) ; } $ configuration = str_replace ( '"' . $ extracted [ 0 ] [ $ index ] . '"' , $ content , $ configuration ) ; } } $ variables = array ( 'DOOZR_APP_ROOT' => str_replace ( '\\' , '\\\\' , DOOZR_APP_ROOT ) , 'DOOZR_DOCUMENT_ROOT' => str_replace ( '\\' , '\\\\' , DOOZR_DOCUMENT_ROOT ) , 'DOOZR_DIRECTORY_TEMP' => str_replace ( '\\' , '\\\\' , DOOZR_DIRECTORY_TEMP ) , 'DOOZR_NAMESPACE_FLAT' => DOOZR_NAMESPACE_FLAT , ) ; foreach ( $ variables as $ variable => $ value ) { $ configuration = str_replace ( '{{' . $ variable . '}}' , $ value , $ configuration ) ; } return $ configuration ; } | Process the filename and return content for it parsed and complete . |
32,131 | protected function extractDirectives ( $ directive , $ content ) { $ pattern = '/{{' . $ directive . '\(?([\w\.]*)\)?}}/' ; preg_match_all ( $ pattern , $ content , $ result ) ; return $ result ; } | Returns the extracted directives of a passed string . |
32,132 | protected function readFile ( $ filename , $ uuid = null ) { if ( $ this -> getCache ( ) === true ) { if ( $ uuid === null ) { $ uuid = md5 ( $ filename ) ; } try { $ content = $ this -> getCacheService ( ) -> read ( $ uuid ) ; if ( $ content !== null && $ content != '' ) { return $ content ; } } catch ( Doozr_Cache_Service_Exception $ e ) { } } $ content = $ this -> getFilesystem ( ) -> read ( $ filename ) ; if ( $ this -> getCache ( ) === true ) { $ this -> getCacheService ( ) -> create ( $ uuid , $ content ) ; } return $ content ; } | Reads a configuration file . When caching is enabled it will try to read the configuration from cache . If this fails it will try to read from filesystem and storages it to cache afterwards . |
32,133 | public function run ( $ args ) { if ( ! isset ( $ args [ 0 ] ) || ! $ args [ 0 ] ) { return $ this -> error ( '&require-package-or-repository' ) ; } $ args = $ this -> parseArgs ( $ args ) ; $ this -> noMount = in_array ( '--no-mount' , $ args ) ; if ( $ this -> noMount ) { $ args = array_values ( array_diff ( $ args , [ '--no-mount' ] ) ) ; } if ( isset ( $ args [ 0 ] ) && $ this -> isUrl ( $ args [ 0 ] ) ) { return $ this -> cloneByRepositoryUrl ( $ args ) ; } if ( isset ( $ args [ 0 ] ) && $ this -> isPackageName ( $ args [ 0 ] ) ) { return $ this -> cloneByPackageName ( $ args ) ; } return "> Producer: Malformed url or package name.\n" ; } | Run clone command . |
32,134 | private function cloneByRepositoryUrl ( $ args ) { $ repositoryUrl = $ args [ 0 ] ; $ projectName = isset ( $ args [ 1 ] ) ? $ args [ 1 ] : $ this -> getProjectNameByRepositoryUrl ( $ repositoryUrl ) ; if ( ! $ this -> existsRepositoryUrl ( $ repositoryUrl ) ) { return 'Repository url not exists!' ; } if ( $ this -> existsProjectName ( $ projectName ) ) { return "> Producer: Project '{$this->projectsDir}/{$projectName}' already exists during clone.\n" ; } $ this -> info ( "Clone by repository url '{$repositoryUrl}'" ) ; $ this -> exec ( 'clone' , 'clone-by-repository-url' , [ $ repositoryUrl , $ projectName ] ) ; if ( $ this -> noMount ) { return ; } $ packageName = $ this -> getProjectPackageName ( $ projectName , $ repositoryUrl ) ; if ( ! $ this -> existsPackageName ( $ packageName ) ) { return $ this -> exec ( 'clone' , 'mount-unknown-package-as-project' , [ $ packageName , $ projectName ] ) ; } if ( ! $ this -> existsRootComposerJson ( ) ) { $ this -> createRootComposerJson ( ) ; } return $ this -> exec ( 'clone' , 'mount-require-package-as-project' , [ $ packageName , $ projectName ] ) ; } | Clone repository by url . |
32,135 | private function cloneByPackageName ( $ args ) { $ packageName = $ args [ 0 ] ; if ( ! $ this -> existsPackageName ( $ packageName ) ) { $ args [ 0 ] = 'https://github.com/' . $ packageName ; return $ this -> cloneByRepositoryUrl ( $ args ) ; } $ projectName = isset ( $ args [ 1 ] ) ? $ args [ 1 ] : basename ( $ packageName ) ; if ( $ this -> existsProjectName ( $ projectName ) ) { return "> Producer: Project directory '{$this->projectsDir}/{$projectName}' already exists.\n" ; } if ( ! $ this -> existsRootComposerJson ( ) ) { $ this -> createRootComposerJson ( ) ; } $ devFlag = in_array ( $ packageName , $ this -> devPackages ) ? '--dev' : '' ; $ this -> exec ( 'clone' , 'require-package' , [ $ packageName , $ devFlag ] ) ; $ composerJson = $ this -> cwd . '/vendor/' . $ packageName . '/composer.json' ; if ( ! file_exists ( $ composerJson ) ) { return "> Producer: Package not found.\n" ; } $ json = json_decode ( file_get_contents ( $ composerJson ) ) ; $ repositoryUrl = null ; if ( isset ( $ json -> repositories ) ) { foreach ( $ json -> repositories as $ item ) { if ( $ item -> type == 'git' ) { $ repositoryUrl = $ item -> url ; break ; } } } if ( ! $ repositoryUrl ) { return "> Producer: Repository not found on composer.json.\n" ; } if ( ! $ this -> existsRepositoryUrl ( $ repositoryUrl ) ) { return 'Repository url not exists!' ; } return $ this -> exec ( 'clone' , 'clone' , [ $ repositoryUrl , $ packageName , $ projectName ] ) ; } | Clone repository by package name . |
32,136 | public function getMaxPosition ( int $ pageId ) : int { return $ this -> connection -> query ( 'SELECT IFNULL(MAX([position]), 0) position FROM %table WHERE [pageId] = %i' , $ this -> getTableName ( ) , $ pageId ) -> fetch ( ) -> position ; } | Vrati nejvetsi pozici |
32,137 | public static function setupServerId ( string $ serverId ) { $ local = Splash :: local ( ) ; $ local -> setServerId ( $ serverId ) ; Splash :: reboot ( ) ; } | Setup Local Splash Module for Current Server |
32,138 | public function getConnectorFromManager ( string $ webserviceId ) { $ manager = $ this -> get ( 'splash.connectors.manager' ) ; $ serverId = $ manager -> hasWebserviceConfiguration ( $ webserviceId ) ; if ( ! $ serverId ) { return false ; } $ connector = $ manager -> get ( $ webserviceId ) ; if ( ! $ connector ) { return false ; } self :: setupPhpOptions ( ) ; self :: setupServerId ( $ serverId ) ; return $ connector ; } | Validate Connector Action Exists |
32,139 | public static function hasPublicAction ( AbstractConnector $ connector , string $ connectorName , string $ action ) { if ( empty ( $ connector ) || empty ( $ action ) ) { return false ; } $ profile = $ connector -> getProfile ( ) ; if ( ! isset ( $ profile [ 'name' ] ) || ( strtolower ( $ connectorName ) != strtolower ( $ profile [ 'name' ] ) ) ) { return false ; } $ connectorActions = $ connector -> getPublicActions ( ) ; if ( ! isset ( $ connectorActions [ strtolower ( $ action ) ] ) || empty ( $ connectorActions [ strtolower ( $ action ) ] ) ) { return false ; } return $ connectorActions [ strtolower ( $ action ) ] ; } | Validate Connector Public Action Exists |
32,140 | public static function hasSecuredAction ( AbstractConnector $ connector , string $ connectorName , string $ action ) { if ( empty ( $ connector ) || empty ( $ action ) ) { return false ; } $ profile = $ connector -> getProfile ( ) ; if ( ! isset ( $ profile [ 'name' ] ) || ( strtolower ( $ connectorName ) != strtolower ( $ profile [ 'name' ] ) ) ) { return false ; } $ connectorActions = $ connector -> getSecuredActions ( ) ; if ( ! isset ( $ connectorActions [ strtolower ( $ action ) ] ) || empty ( $ connectorActions [ strtolower ( $ action ) ] ) ) { return false ; } return $ connectorActions [ strtolower ( $ action ) ] ; } | Validate Connector Secured Action Exists |
32,141 | private function connectAndCreate ( $ server , $ type , $ username , $ password , $ database ) { $ conn = ADONewConnection ( $ this -> isPDO ( $ type ) ? 'pdo' : $ type ) ; $ conn -> SetFetchMode ( ADODB_FETCH_BOTH ) ; $ conn = $ this -> setConnectTimeout ( $ conn , $ type ) ; $ connected = $ conn -> Connect ( $ this -> getDSN ( $ server , $ type , false ) , $ username , $ password , $ database ) ; $ conn = $ this -> clearConnectTimeout ( $ conn , $ type ) ; if ( $ connected ) { $ this -> last_connect_error = false ; $ adapter = $ this -> getAdapter ( strtolower ( $ type ) ) ; $ stillok = $ conn -> Execute ( $ adapter -> createNamedDB ( $ database ) ) ; if ( ! $ stillok ) { $ this -> last_connect_error = $ conn -> ErrorMsg ( ) ; $ this -> connections [ $ database ] = false ; return false ; } $ conn -> Execute ( $ adapter -> useNamedDB ( $ database ) ) ; $ conn -> SelectDB ( $ database ) ; $ this -> connections [ $ database ] = $ conn ; return true ; } else { $ this -> last_connect_error = $ conn -> ErrorMsg ( ) ; $ this -> connections [ $ database ] = false ; return false ; } } | Try connecting without specifying a database and then creating the requested database |
32,142 | public function isConnected ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } if ( isset ( $ this -> connections [ $ which_connection ] ) && is_object ( $ this -> connections [ $ which_connection ] ) ) { return true ; } else { return false ; } } | Verify object is connected to the database |
32,143 | private function setDBorSchema ( $ db_name ) { if ( strtolower ( $ this -> connectionType ( $ db_name ) ) === 'postgres9' ) { $ adapter = $ this -> getAdapter ( $ this -> connectionType ( $ db_name ) ) ; $ selectDbQuery = $ adapter -> useNamedDB ( $ db_name ) ; return $ this -> connections [ $ db_name ] -> Execute ( $ selectDbQuery ) ; } return $ this -> connections [ $ db_name ] -> SelectDB ( $ db_name ) ; } | Abstraction leaks here . Changing the connection s default DB or SCHEMA via query works but calling SelectDB on the underying ADOdb object is sometimes necessary to update the object s internal state appropriately . This makes postgres a special case where the SCHEMA should change but DB should not . |
32,144 | public function queryAll ( $ query_text ) { $ ret = true ; foreach ( $ this -> connections as $ db_name => $ con ) { $ ret = $ this -> query ( $ query_text , $ db_name ) ; } return $ ret ; } | Execute a query on all connected databases |
32,145 | public function numRows ( $ result_object , $ which_connection = '' ) { if ( ! is_object ( $ result_object ) ) { return false ; } if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } return $ result_object -> RecordCount ( ) ; } | Get number of rows in a result set |
32,146 | public function dataSeek ( $ result_object , $ rownum , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } return $ result_object -> Move ( ( int ) $ rownum ) ; } | Move result cursor to specified record |
32,147 | public function fetchArray ( $ result_object , $ which_connection = '' ) { if ( is_null ( $ result_object ) ) return false ; if ( $ result_object === false ) return false ; if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ ret = $ result_object -> fields ; if ( $ result_object ) { $ result_object -> MoveNext ( ) ; } return $ ret ; } | Get next record from a result set |
32,148 | public function fetchField ( $ result_object , $ index , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } return $ result_object -> FetchField ( $ index ) ; } | Get a column name by index |
32,149 | public function commitTransaction ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } return $ this -> connections [ $ which_connection ] -> CommitTrans ( ) ; } | Finish a transaction |
32,150 | public function rollbackTransaction ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } return $ this -> connections [ $ which_connection ] -> RollbackTrans ( ) ; } | Abort a transaction |
32,151 | public function transfer ( $ source_db , $ select_query , $ dest_db , $ insert_query ) { $ result = $ this -> query ( $ select_query , $ source_db ) ; if ( ! $ result ) { return false ; } if ( $ this -> numRows ( $ result ) == 0 ) { return true ; } $ numFields = $ this -> numFields ( $ result , $ source_db ) ; $ prep = $ insert_query . ' VALUES(' ; $ arg_sets = array ( ) ; $ big_query = $ insert_query . ' VALUES ' ; $ big_values = '' ; $ big_args = array ( ) ; while ( $ row = $ this -> fetchArray ( $ result , $ source_db ) ) { $ big_values .= '(' ; $ args = array ( ) ; for ( $ i = 0 ; $ i < $ numFields ; $ i ++ ) { $ type = strtolower ( $ this -> fieldType ( $ result , $ i , $ source_db ) ) ; $ row [ $ i ] = $ this -> sanitizeValue ( $ row [ $ i ] , $ type ) ; $ args [ ] = $ row [ $ i ] ; $ big_args [ ] = $ row [ $ i ] ; $ big_values .= '?' ; if ( $ i < $ numFields - 1 ) { $ big_values .= ',' ; } } $ arg_sets [ ] = $ args ; if ( count ( $ arg_sets ) < 500 ) { $ big_values .= '),' ; } else { $ big_values = '' ; $ big_args = array ( ) ; } } $ big_values = substr ( $ big_values , 0 , strlen ( $ big_values ) - 1 ) ; $ prep .= str_repeat ( '?,' , count ( $ arg_sets [ 0 ] ) ) ; $ prep = substr ( $ prep , 0 , strlen ( $ prep ) - 1 ) . ')' ; if ( count ( $ arg_sets ) < 500 ) { $ this -> lockTimeout ( 5 , $ dest_db ) ; $ big_prep = $ this -> prepare ( $ big_query . $ big_values , $ dest_db ) ; $ bigR = $ this -> execute ( $ big_prep , $ big_args , $ dest_db ) ; return ( $ bigR ) ? true : false ; } else { return $ this -> executeAsTransaction ( $ prep , $ arg_sets , $ dest_db ) ; } } | Copy a table from one database to another not necessarily on the same server or format . |
32,152 | public function executeAsTransaction ( $ query , $ arg_sets , $ which_connection = '' ) { $ which_connection = $ which_connection === '' ? $ this -> default_db : $ which_connection ; $ ret = true ; $ statement = $ this -> prepare ( $ query , $ which_connection ) ; $ this -> startTransaction ( $ which_connection ) ; $ this -> lockTimeout ( 5 , $ which_connection ) ; foreach ( $ arg_sets as $ args ) { if ( ! $ this -> execute ( $ statement , $ args , $ which_connection ) ) { $ ret = false ; break ; } } if ( $ ret === true ) { $ this -> commitTransaction ( $ which_connection ) ; } else { $ this -> rollbackTransaction ( $ which_connection ) ; } return $ ret ; } | Execute a statement repeatedly as transaction . Commit if all statements succeed . Otherwise roll back . |
32,153 | public function fieldType ( $ result_object , $ index , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ fld = $ result_object -> FetchField ( $ index ) ; $ dbtype = $ this -> connectionType ( $ which_connection ) ; if ( strtolower ( $ dbtype ) === 'mysqli' ) { $ meta = $ this -> connections [ $ which_connection ] -> MetaType ( $ fld -> type ) ; switch ( $ meta ) { case 'C' : case 'X' : $ fld -> type = 'varchar' ; break ; case 'B' : case 'X' : $ fld -> type = 'blob' ; break ; case 'D' : case 'T' : $ fld -> type = 'datetime' ; break ; case 'R' : case 'I' : $ fld -> type = 'int' ; break ; case 'N' : $ fld -> type = 'numeric' ; break ; } } return $ fld -> type ; } | Get column type |
32,154 | public function hour ( $ field , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ conn = $ this -> connections [ $ which_connection ] ; return $ conn -> SQLDate ( "H" , $ field ) ; } | Get the hour from a datetime |
32,155 | public function week ( $ field , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ conn = $ this -> connections [ $ which_connection ] ; return $ conn -> SQLDate ( "W" , $ field ) ; } | Get the week number from a datetime |
32,156 | public function tableExists ( $ table_name , $ which_connection = '' ) { if ( isset ( $ this -> structure_cache [ $ which_connection ] ) && isset ( $ this -> structure_cache [ $ which_connection ] [ $ table_name ] ) ) { return true ; } $ conn = $ this -> getNamedConnection ( $ which_connection ) ; if ( ! is_object ( $ conn ) ) { return false ; } $ cols = $ conn -> MetaColumns ( $ table_name ) ; if ( $ cols === false ) { return false ; } return true ; } | Check whether the given table exists |
32,157 | public function getViewDefinition ( $ view_name , $ which_connection = '' ) { $ which_connection = ( $ which_connection === '' ) ? $ this -> default_db : $ which_connection ; if ( ! $ this -> isView ( $ view_name , $ which_connection ) ) { return false ; } $ adapter = $ this -> getAdapter ( $ this -> connectionType ( $ which_connection ) ) ; return $ adapter -> getViewDefinition ( $ view_name , $ this , $ which_connection ) ; } | Get SQL definition of a view |
32,158 | public function tableDefinition ( $ table_name , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } if ( isset ( $ this -> structure_cache [ $ which_connection ] ) && isset ( $ this -> structure_cache [ $ which_connection ] [ $ table_name ] ) ) { return $ this -> structure_cache [ $ which_connection ] [ $ table_name ] ; } $ conn = $ this -> connections [ $ which_connection ] ; $ cols = $ conn -> MetaColumns ( $ table_name ) ; if ( is_array ( $ cols ) ) { $ return = array_reduce ( $ cols , function ( $ carry , $ c ) { if ( is_object ( $ c ) ) { $ carry [ $ c -> name ] = $ c -> type ; } return $ carry ; } , array ( ) ) ; return $ return ; } return false ; } | Get the table s definition |
32,159 | public function detailedDefinition ( $ table_name , $ which_connection = '' ) { $ which_connection = ( $ which_connection === '' ) ? $ this -> default_db : $ which_connection ; $ conn = $ this -> connections [ $ which_connection ] ; $ cols = $ conn -> MetaColumns ( $ table_name ) ; $ return = array ( ) ; if ( is_array ( $ cols ) ) { foreach ( $ cols as $ c ) { $ return [ $ c -> name ] = $ this -> columnToArray ( $ c ) ; } return $ return ; } return false ; } | More detailed table definition |
32,160 | public function defaultDatabase ( $ which_connection = '' ) { $ which_connection = $ which_connection === '' ? $ this -> default_db : $ which_connection ; $ adapter = $ this -> getAdapter ( $ this -> connectionType ( $ which_connection ) ) ; if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } if ( count ( $ this -> connections ) == 0 ) { return false ; } $ query = $ adapter -> defaultDatabase ( ) ; $ ret = false ; $ try = $ this -> query ( $ query , $ which_connection ) ; if ( $ try && $ this -> num_rows ( $ try ) > 0 ) { $ row = $ this -> fetch_row ( $ try ) ; $ ret = $ row [ 'dbname' ] ; } return $ ret ; } | Get current default database for a given connection |
32,161 | public function currency ( $ which_connection = '' ) { $ which_connection = $ which_connection === '' ? $ this -> default_db : $ which_connection ; $ adapter = $ this -> getAdapter ( $ this -> connectionType ( $ which_connection ) ) ; return $ adapter -> currency ( ) ; } | Get database s currency type |
32,162 | public function sep ( $ which_connection = '' ) { $ which_connection = $ which_connection === '' ? $ this -> default_db : $ which_connection ; $ adapter = $ this -> getAdapter ( $ this -> connectionType ( $ which_connection ) ) ; if ( $ adapter == null ) { return '.' ; } return $ adapter -> sep ( ) ; } | Get database scope separator |
32,163 | public function error ( $ which_connection = '' ) { $ con = $ this -> getNamedConnection ( $ which_connection ) ; if ( ! is_object ( $ con ) ) { if ( $ this -> last_connect_error ) { return $ this -> last_connect_error ; } return 'No database connection' ; } return $ con -> ErrorMsg ( ) ; } | Get last error message |
32,164 | public function insertID ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ con = $ this -> connections [ $ which_connection ] ; return $ con -> Insert_ID ( ) ; } | Get auto incremented ID from last insert |
32,165 | public function affectedRows ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ con = $ this -> connections [ $ which_connection ] ; return $ con -> Affected_Rows ( ) ; } | Check how many rows the last query affected |
32,166 | public function getValue ( $ sql , $ input_array = array ( ) , $ which_connection = '' ) { $ res = $ this -> execute ( $ sql , $ input_array , $ which_connection ) ; if ( $ res && $ this -> numRows ( $ res ) > 0 ) { $ row = $ this -> fetchRow ( $ res ) ; return $ row [ 0 ] ; } elseif ( $ res && $ this -> numRows ( $ res ) == 0 ) { return false ; } else { if ( $ this -> throw_on_fail ) { throw new \ Exception ( 'Record not found' ) ; } else { return false ; } } } | Get a value directly from a query without verifying rows exist and fetching one |
32,167 | public function logger ( $ str ) { if ( is_object ( $ this -> QUERY_LOG ) && method_exists ( $ this -> QUERY_LOG , 'debug' ) ) { $ this -> QUERY_LOG -> debug ( $ str ) ; return true ; } return false ; } | Log a string to the query log . |
32,168 | public function matchingColumns ( $ table1 , $ table2 , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ definition1 = $ this -> tableDefinition ( $ table1 , $ which_connection ) ; $ definition2 = $ this -> tableDefinition ( $ table2 , $ which_connection ) ; if ( ! is_array ( $ definition1 ) || ! is_array ( $ definition2 ) ) { return array ( ) ; } $ matches = array_filter ( array_keys ( $ definition1 ) , function ( $ col_name ) use ( $ definition2 ) { return isset ( $ definition2 [ $ col_name ] ) ? true : false ; } ) ; return $ matches ; } | Get column names common to both tables |
32,169 | public function getMatchingColumns ( $ table1 , $ which_connection1 , $ table2 , $ which_connection2 ) { $ def1 = $ this -> tableDefinition ( $ table1 , $ which_connection1 ) ; $ def2 = $ this -> tableDefinition ( $ table2 , $ which_connection2 ) ; $ ret = array_reduce ( array_keys ( $ def1 ) , function ( $ carry , $ column_name ) use ( $ def2 ) { if ( isset ( $ def2 [ $ column_name ] ) ) { $ carry .= $ column_name . ',' ; } return $ carry ; } , '' ) ; if ( $ ret === '' ) { return false ; } else { return substr ( $ ret , 0 , strlen ( $ ret ) - 1 ) ; } } | Get list of columns that exist in both tables |
32,170 | public function cacheTableDefinition ( $ table , $ definition , $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } if ( ! isset ( $ this -> structure_cache [ $ which_connection ] ) ) { $ this -> structure_cache [ $ which_connection ] = array ( ) ; } $ this -> structure_cache [ $ which_connection ] [ $ table ] = $ definition ; return true ; } | Cache a table definition to avoid future lookups |
32,171 | public function clearTableCache ( $ which_connection = '' ) { if ( $ which_connection == '' ) { $ which_connection = $ this -> default_db ; } $ this -> structure_cache [ $ which_connection ] = array ( ) ; return true ; } | Clear cached table definitions |
32,172 | public function safeInClause ( $ arr , $ args = array ( ) , $ dummy_value = - 999999 ) { if ( count ( $ arr ) == 0 ) { $ arr = array ( $ dummy_value ) ; } $ args = array_merge ( $ args , $ arr ) ; $ inStr = str_repeat ( '?,' , count ( $ arr ) ) ; $ inStr = substr ( $ inStr , 0 , strlen ( $ inStr ) - 1 ) ; return array ( $ inStr , $ args ) ; } | Build an SQL IN clause from an array |
32,173 | function add ( string $ name , string $ namespace = '\\CismonX\\CaptchaQueue\\Rules' ) { if ( isset ( $ this -> _formulaList [ $ name ] ) ) Console :: warning ( "Overwriting formula \"$name\"." ) ; $ class_name = $ namespace . '\\' . $ name ; if ( ! class_exists ( $ class_name ) ) { Console :: warning ( "Invalid formula \"$name\"." ) ; return ; } $ this -> _formulaList [ $ name ] = new $ class_name ; self :: enable ( $ name ) ; } | Add a rule to the generator . |
32,174 | function enable ( string $ name ) { if ( ! isset ( $ this -> _formulaList [ $ name ] ) ) { Console :: warning ( "Formula \"$name\" do not exist." ) ; return ; } $ this -> _enableList = $ this -> _enableList + [ $ name ] ; } | Enable formula . |
32,175 | function disable ( string $ name ) { $ pos = array_search ( $ name , $ this -> _enableList ) ; if ( $ pos === false ) return ; unset ( $ this -> _enableList [ $ pos ] ) ; } | Disable formula . |
32,176 | function onMessage ( ProcConnection $ conn , $ data ) { if ( $ this -> _status == self :: STATUS_INIT ) return ; $ data = self :: _parseTex ( $ data ) ; if ( $ data === false ) return ; if ( $ this -> _status == self :: STATUS_FORMULA ) { $ this -> _formula = $ data ; $ this -> _id = self :: genPic ( $ data ) ; $ this -> _status = self :: STATUS_RESULT ; $ conn -> send ( $ this -> _current -> withEval ( ) ) ; } else { $ message = $ this -> _current -> getMessage ( ) ; msg_send ( Captcha :: getQueue ( ) , 1 , [ $ this -> _id , $ message , $ data ] ) ; if ( msg_stat_queue ( Captcha :: getQueue ( ) ) [ 'msg_qnum' ] < Config :: get ( 'CAPTCHA_CACHE_MAX' ) ) { $ this -> generate ( ) ; } else { $ this -> _status = self :: STATUS_INIT ; } } } | Call when process output message . |
32,177 | static function genPic ( $ formula ) { $ id = uniqid ( ) ; Tex2png :: create ( $ formula ) -> saveTo ( Config :: get ( 'CAPTCHA_PIC_PATH' ) . $ id ) -> generate ( ) ; self :: handleImg ( $ id ) ; return $ id ; } | Generate PNG using Tex2png with TeX formatted formula . |
32,178 | protected static function handleImg ( $ id ) { $ img = new \ Imagick ( Config :: get ( 'CAPTCHA_PIC_PATH' ) . $ id ) ; $ img -> swirlImage ( mt_rand ( 15 , 25 ) ) ; $ img -> motionBlurImage ( 1.5 , 3 , mt_rand ( 0 , 360 ) ) ; $ img -> adaptiveResizeImage ( Config :: get ( 'CAPTCHA_WIDTH' ) , Config :: get ( 'CAPTCHA_HEIGHT' ) , false ) ; $ img -> addNoiseImage ( \ Imagick :: NOISE_GAUSSIAN , \ Imagick :: CHANNEL_ALL ) ; $ img -> writeImage ( Config :: get ( 'CAPTCHA_PIC_PATH' ) . $ id ) ; } | Process image to prevent captcha recognition . |
32,179 | protected static function _parseTex ( string $ data ) { preg_match ( '{\\$\\$([\\S\\s]*?)\\$\\$}' , $ data , $ matches ) ; if ( isset ( $ matches [ 0 ] ) ) { $ str = str_replace ( [ "\r" , "\n" ] , '' , $ matches [ 1 ] ) ; return $ str ; } return false ; } | Extract content from Maxima TeX output . |
32,180 | private function getCommandDefinition ( string $ serialized ) : array { if ( \ trim ( $ serialized ) === '' ) { throw new CommandSerializationException ( 'Malformed JSON serialized command: empty string' ) ; } $ definition = \ json_decode ( $ serialized , true , 512 , static :: JSON_DECODE_OPTIONS ) ; if ( $ definition === null || \ json_last_error ( ) !== \ JSON_ERROR_NONE ) { throw new CommandSerializationException ( \ sprintf ( 'Command deserialization failed due to error %s: %s' , \ json_last_error ( ) , \ lcfirst ( \ json_last_error_msg ( ) ) ) ) ; } if ( ! \ is_array ( $ definition ) || ! isset ( $ definition [ 'class' ] , $ definition [ 'payload' ] ) || \ count ( \ array_diff ( \ array_keys ( $ definition ) , [ 'class' , 'payload' ] ) ) !== 0 || ! \ is_string ( $ definition [ 'class' ] ) || ! \ is_array ( $ definition [ 'payload' ] ) ) { throw new CommandSerializationException ( 'Malformed JSON serialized command' ) ; } return $ definition ; } | Get command definition from serialization . |
32,181 | public function truncateTable ( $ table ) { $ query = "DELETE FROM $table" ; $ result = $ this -> execute ( $ query ) ; if ( $ result > 0 ) { $ this -> execute ( 'VACUUM' ) ; return TRUE ; } return FALSE ; } | Deletes all records from a table . |
32,182 | public function dropColumn ( $ table , $ name ) { try { $ tmpTable = $ table . '_old' ; $ this -> startTransaction ( ) ; $ this -> copyTable ( $ table , $ tmpTable , [ $ name ] ) ; $ this -> dropTable ( $ tmpTable ) ; $ this -> commitTransaction ( ) ; } catch ( Exception $ e ) { $ this -> rollbackTransaction ( ) ; return FALSE ; } return TRUE ; } | Removes a column from a database table . |
32,183 | public function dropForeignKey ( $ table , $ keyName ) { try { $ tmpTable = $ table . '_temp' ; $ this -> getTableForeignKeys ( $ table ) ; $ this -> startTransaction ( ) ; $ this -> copyTable ( $ table , $ tmpTable ) ; $ this -> dropTable ( $ table ) ; $ columns = $ this -> getTableColumns ( $ tmpTable ) ; $ this -> createTable ( $ table , $ columns ) ; $ this -> copyTableData ( $ tmpTable , $ table , $ columns ) ; $ this -> commitTransaction ( ) ; } catch ( Exception $ e ) { $ this -> rollbackTransaction ( ) ; return FALSE ; } return TRUE ; } | Deletes a foreign key from a table . |
32,184 | protected function copyTable ( $ table , $ tempTable = '' , array $ exclude = [ ] ) { $ query = "ALTER TABLE $table RENAME TO $tempTable" ; $ result = $ this -> modify ( $ query ) ; if ( FALSE === $ result ) { throw new DatabaseException ( 'Drop column failed' ) ; } $ columns = $ this -> getTableColumns ( $ tempTable , $ exclude ) ; $ this -> createTable ( $ table , $ columns ) ; $ this -> copyTableData ( $ table , $ tempTable , $ columns ) ; } | Copy a table . |
32,185 | public function getTableColumns ( $ table , array $ exclude = [ ] ) { $ query = "pragma table_info( $table )" ; $ result = $ this -> query ( $ query ) ; $ columns = [ ] ; foreach ( $ result as $ res ) { foreach ( $ res as $ key => $ value ) { if ( 'name' === $ key && ! in_array ( $ value , $ exclude ) ) { $ null = ' NULL' ; if ( TRUE === ( bool ) $ res [ 'notnull' ] ) { $ null = ' NOT NULL' ; } $ columns [ $ value ] = $ res [ 'type' ] . $ null ; } } } return $ columns ; } | Get a list of table columns . |
32,186 | public function copyTableData ( $ from , $ to , $ columns ) { $ cols = implode ( ', ' , array_keys ( $ columns ) ) ; $ cols = rtrim ( $ cols , ',' ) ; $ rows = $ this -> query ( "SELECT $cols FROM $to" ) ; foreach ( $ rows as $ row ) { $ query = "INSERT INTO $from ( $cols ) VALUES ( " . rtrim ( str_repeat ( '?,' , count ( $ columns ) , ',' ) ) . " )" ; $ values = [ ] ; foreach ( $ row as $ key => $ value ) { if ( in_array ( $ key , array_keys ( $ columns ) ) ) { $ values [ ] = $ row [ $ key ] ; } } $ this -> execute ( $ query , $ values ) ; } } | Copy table data from one table to another . |
32,187 | public function route ( $ name , $ path , callable $ callback ) { $ path = preg_replace ( "|(:(\w+))|" , '{$2}' , $ path ) ; if ( ! $ name ) { $ name = "N" . uniqid ( ) ; } $ map = $ this [ "router" ] -> getMap ( ) ; $ route = $ map -> route ( $ name , $ path , $ callback ) ; return $ route ; } | Define a route and map a callback function to the path |
32,188 | public function destroy ( $ id ) { $ memberInvitation = MemberInvitation :: findOrFail ( $ id ) ; $ this -> authorize ( 'destroy' , $ memberInvitation ) ; $ memberInvitation -> delete ( ) ; return fractal ( $ id , new DeletedTransformer ( ) ) -> withResourceName ( 'deletedMemberInvitation' ) -> respond ( ) ; } | Delete an MemberInvitation object |
32,189 | public function index ( ) { $ invitations = MemberInvitation :: with ( 'member' , 'member.user' , 'inviter' , 'inviter.user' ) -> active ( ) -> forUserContext ( $ this -> userContext ( ) ) -> orderBy ( 'created_at' , 'desc' ) -> paginate ( config ( 'app.pagination_default' ) ) ; return fractal ( $ invitations , new MemberInvitationTransformer ( ) ) -> withResourceName ( 'memberInvitation' ) -> respond ( ) ; } | Fetch a paginated list of Invitations for a selected Team |
32,190 | public function store ( Request $ request ) { $ request -> validate ( [ 'email' => 'required|email' , 'name' => 'max:36' , ] ) ; $ invitedMember = $ this -> createInvitedMember ( $ request ) ; $ memberInvitation = $ this -> createMemberInvitation ( $ request -> email , $ invitedMember -> id ) ; $ invitedMember -> notify ( new MemberInvited ( $ memberInvitation ) ) ; return fractal ( $ memberInvitation , new MemberInvitationTransformer ( ) ) -> includeInvitedMember ( ) -> withResourceName ( 'memberInvitation' ) -> respond ( ) ; } | Invite a new Member ; creates User if none exists ; creates Member |
32,191 | protected function validateUser ( User $ user , $ teamId ) { if ( $ user -> hasMemberOnTeam ( $ teamId ) ) { $ validationException = ValidationException :: withMessages ( [ 'email' => 'EMAIL_HAS_TEAM_EMPLOYEE' ] ) ; throw $ validationException ; } if ( $ user -> hasMemberInvitationOnTeam ( $ teamId ) ) { $ validationException = ValidationException :: withMessages ( [ 'email' => 'EMAIL_HAS_TEAM_EMPLOYEE_INVITATION' ] ) ; throw $ validationException ; } return $ user ; } | Validates MemberInvitations for existing Users to verify that invitation is not for a Team where User has an existing Member and that an MemberInvitation does not already exist for the Team |
32,192 | public function getConfiguration ( ) { if ( ! $ this -> _configuration ) { if ( $ this -> modelClass ) { $ this -> _configuration = $ this -> _keyStorage -> get ( $ this -> getKey ( ) ) ? : [ ] ; $ modelClass = $ this -> modelClass ; if ( ! $ this -> _configuration || ! ( $ this -> _configuration instanceof $ modelClass ) ) { $ this -> _configuration = Yii :: createObject ( $ modelClass , $ this -> modelConfig ) ; } if ( is_array ( $ this -> attributes ) ) { foreach ( $ this -> attributes as $ key => $ default ) { if ( $ this -> _configuration -> { $ key } === null ) { $ this -> _configuration -> { $ key } = $ default ; } } } } else { $ dbConfig = $ this -> _keyStorage -> get ( $ this -> getKey ( ) ) ? : [ ] ; if ( is_array ( $ this -> attributes ) ) { $ config = [ ] ; foreach ( $ this -> attributes as $ key => $ default ) { $ config [ $ key ] = ( isset ( $ dbConfig [ $ key ] ) && $ dbConfig [ $ key ] !== null ) ? $ dbConfig [ $ key ] : $ default ; } $ this -> _configuration = $ config ; } else { $ this -> _configuration = $ dbConfig ; } } } return $ this -> _configuration ; } | Returns owner config |
32,193 | public function saveConfigurationModel ( $ model , $ validate = true , $ apply = true ) { if ( ! $ model ) { return false ; } if ( $ validate && ! $ model -> validate ( ) ) { return false ; } if ( $ this -> modelClass ) { $ modelClass = $ this -> modelClass ; if ( ( $ model instanceof $ modelClass ) && $ this -> _keyStorage -> set ( $ this -> getKey ( ) , $ model ) ) { if ( $ apply ) { $ this -> _configuration = $ model ; $ this -> configure ( ) ; } return true ; } else { return false ; } } else { return $ this -> saveConfigurationArray ( $ model -> getAttributes ( ) , $ apply ) ; } } | Saves configuration model . Performs validation if needed . |
32,194 | public function saveConfigurationArray ( $ config , $ apply = true ) { if ( $ this -> ignoreIfDefault && $ this -> attributes ) { foreach ( $ this -> attributes as $ key => $ default ) { if ( isset ( $ config [ $ key ] ) && $ config [ $ key ] == $ default ) { unset ( $ config [ $ key ] ) ; } } } if ( $ this -> _keyStorage -> set ( $ this -> getKey ( ) , $ config ) ) { if ( $ apply ) { $ this -> _configuration = null ; $ this -> configure ( ) ; } return true ; } else { return false ; } } | Save array config |
32,195 | public function editSettings ( ) { $ this -> setTitleEditSettings ( ) ; $ this -> setBreadcrumbEditSettings ( ) ; $ this -> setData ( 'imagestyles' , $ this -> image_style -> getList ( ) ) ; $ this -> setData ( 'settings' , $ this -> module -> getSettings ( 'mobile' ) ) ; $ this -> setData ( 'imagestyle_fields' , $ this -> getImageStyleFieldsSettings ( ) ) ; $ this -> submitSettings ( ) ; $ this -> outputEditSettings ( ) ; } | Displays the module settings page |
32,196 | public function setContent ( $ text , $ type = 'text' ) { $ this -> setType ( $ type ) ; $ this -> getDomElement ( ) -> nodeValue = $ text ; $ this -> setCachedProperty ( 'content' , $ this -> parseContent ( ) ) ; } | Set new text . |
32,197 | private function parseContent ( ) { if ( $ this -> getType ( ) === 'xhtml' ) { try { $ xhtml = $ this -> query ( 'xhtml:div' , Node :: SINGLE | Node :: REQUIRED ) ; } catch ( MalformedNodeException $ e ) { return '' ; } return Xhtml :: extract ( $ xhtml ) ; } return $ this -> getDomElement ( ) -> textContent ; } | Return string value . |
32,198 | public static function selectField ( $ name , $ options , $ attributes , $ value = null , $ fieldProperties = null , $ ID = null ) { if ( empty ( $ name ) ) { return false ; } if ( empty ( $ options ) ) { trigger_error ( "Object <strong>{$name}</strong> has no valid options!" , E_USER_WARNING ) ; return false ; } $ fieldProperties = empty ( $ fieldProperties ) ? array ( ) : ( is_array ( $ fieldProperties ) ? $ fieldProperties : array ( $ fieldProperties ) ) ; $ baseAttributes = array ( 'ID' => $ name , 'name' => $ name ) ; $ source = '' ; $ hasSelectedOption = false ; foreach ( $ options as $ item ) { $ option = '' ; $ selectedOption = '' ; if ( ! $ hasSelectedOption && ( isset ( $ item [ 'selected' ] ) || ( $ item == $ value ) || ( isset ( $ item [ 'value' ] ) && $ value == $ item [ 'value' ] ) ) ) { $ selectedOption = 'selected="selected"' ; $ hasSelectedOption = true ; } if ( ! is_array ( $ item ) ) { $ option .= "<option {$selectedOption} value=\"{$item}\">{$item}</option>" ; } else { $ option = "<option " ; if ( isset ( $ item [ 'value' ] ) ) { $ option .= " value=\"{$item['value']}\" {$selectedOption}" ; } else { $ option .= " value=\"{$item['text']}\" {$selectedOption}" ; } $ option = trim ( $ option ) . ">{$item['text']}</option>" ; } $ source .= $ option ; } $ attsString = self :: arrayToHTMLAttributes ( array_merge ( $ baseAttributes , $ attributes ) ) ; $ output = "<select {$attsString}>{$source}</select>" ; $ field = new \ stdClass ( ) ; $ field -> html = $ output ; $ field -> properties = array_merge ( $ baseAttributes , $ attributes , array ( 'options' => $ options ) , $ fieldProperties ) ; return $ field ; } | Generate a Select Field . |
32,199 | public function index ( $ teamId ) { $ team = Team :: findOrFail ( $ teamId ) ; $ this -> authorize ( 'view' , $ team ) ; return $ this -> respondRelatedPhones ( $ teamId , 'team' ) ; } | Produce a list of Phones related to a selected Team |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.