idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
36,500 | private function buildPackageMap ( $ package ) { $ package_map = array ( ) ; $ requirements = $ package -> getRequires ( ) ; $ extra = $ package -> getExtra ( ) ; $ mappings = $ extra [ self :: NAME ] [ $ this -> framework ] ; foreach ( $ mappings as $ element => $ value ) { if ( is_array ( $ value ) ) { if ( $ element != $ package -> getName ( ) && ! $ this -> externalMapping ) { throw new \ Exception ( sprintf ( 'Cannot perform external mapping for %s, disabled' , $ element ) ) ; } if ( strpos ( $ element , '*' ) !== FALSE ) { $ parts = explode ( '*' , $ element ) ; $ parts = array_map ( function ( $ v ) { return preg_quote ( $ v , '#' ) ; } , $ parts ) ; $ element = implode ( '(.*)' , $ parts ) ; } foreach ( $ requirements as $ link ) { if ( preg_match ( '#' . $ element . '#' , $ link -> getTarget ( ) ) ) { $ package_map [ $ link -> getTarget ( ) ] = $ value ; } } $ package_map [ $ element ] = $ value ; } elseif ( is_string ( $ value ) ) { if ( ! isset ( $ package_map [ $ package -> getName ( ) ] ) ) { $ package_map [ $ package -> getName ( ) ] = array ( ) ; } $ package_map [ $ package -> getName ( ) ] [ $ element ] = $ value ; } else { throw new \ Exception ( sprintf ( 'Ivalid element %s of type %s' , $ element , gettype ( $ value ) ) ) ; } } return $ package_map ; } | Builds a package map |
36,501 | private function checkFrameworkSupport ( $ package ) { $ extra = $ package -> getExtra ( ) ; if ( ! isset ( $ extra [ self :: NAME ] ) ) { return FALSE ; } if ( ! isset ( $ extra [ self :: NAME ] [ $ this -> framework ] ) ) { return FALSE ; } return $ this -> enabled ; } | Checks whether or not our framework is supported by this opus package |
36,502 | private function cleanup ( ) { foreach ( $ this -> installationMap as $ path => $ packages ) { if ( $ path == '__CHECKSUMS__' ) { continue ; } if ( count ( $ packages ) ) { sort ( $ this -> installationMap [ $ path ] ) ; continue ; } $ installation_path = ltrim ( $ path , '/\\' . DIRECTORY_SEPARATOR ) ; $ installation_path = getcwd ( ) . DIRECTORY_SEPARATOR . $ installation_path ; if ( is_dir ( $ installation_path ) ) { $ children = array_merge ( glob ( $ installation_path . DIRECTORY_SEPARATOR . '/*' ) , glob ( $ installation_path . DIRECTORY_SEPARATOR . '/.*' ) ) ; if ( count ( $ children ) > 2 ) { continue ; } if ( ! @ rmdir ( $ installation_path ) ) { switch ( $ this -> integrity ) { case 'low' : break ; case 'medium' : $ this -> io -> write ( sprintf ( self :: TAB . 'Warning: unable to remove empty directory %s' , $ path ) ) ; break ; case 'high' : throw new \ Exception ( sprintf ( 'Error removing empty directory %s' , $ path ) ) ; } } } else { if ( ! @ unlink ( $ installation_path ) ) { switch ( $ this -> integrity ) { case 'low' : break ; case 'medium' : $ this -> io -> write ( sprintf ( self :: TAB . 'Warning: unable to remove unused file %s; remove manually' , $ path ) ) ; break ; case 'high' : throw new \ Exception ( sprintf ( 'Error removing unused file %s, restore file or check permissions and try again' , $ path ) ) ; } } } unset ( $ this -> installationMap [ $ path ] ) ; unset ( $ this -> installationMap [ '__CHECKSUMS__' ] [ $ path ] ) ; } uksort ( $ this -> installationMap , function ( $ a , $ b ) { if ( strlen ( $ a ) == strlen ( $ b ) ) { return 0 ; } if ( strlen ( $ a ) > strlen ( $ b ) ) { return - 1 ; } return 1 ; } ) ; } | Cleans up our map and installations removing any files no longer mapped to packages |
36,503 | private function copyMap ( $ package_map , & $ result = NULL ) { $ result = ( array ) $ result ; $ manager = $ this -> composer -> getRepositoryManager ( ) ; $ packages = $ manager -> getLocalRepository ( ) -> getPackages ( ) ; foreach ( $ packages as $ package ) { $ package_name = $ package -> getName ( ) ; $ package_root = rtrim ( $ this -> getInstallPath ( $ package ) , '/\\' . DIRECTORY_SEPARATOR ) ; if ( ! isset ( $ package_map [ $ package_name ] ) ) { continue ; } $ this -> io -> write ( sprintf ( self :: TAB . 'Copying files from %s' , substr ( $ package_root , strlen ( getcwd ( ) ) ) ) ) ; foreach ( $ package_map [ $ package_name ] as $ a => $ b ) { $ a = trim ( $ a , '/\\' . DIRECTORY_SEPARATOR ) ; $ b = ltrim ( $ b , '/\\' . DIRECTORY_SEPARATOR ) ; $ result = array_replace_recursive ( $ this -> copy ( $ package_root . DIRECTORY_SEPARATOR . $ a , getcwd ( ) . DIRECTORY_SEPARATOR . $ b , $ package_name ) , $ result ) ; } } } | Copies files over from a package map |
36,504 | private function createDirectory ( $ directory , $ entry_name = NULL ) { $ directory = str_replace ( DIRECTORY_SEPARATOR , '/' , $ directory ) ; $ directory = str_replace ( '\\' , '/' , $ directory ) ; $ directory = str_replace ( '/' , '/' , $ directory ) ; $ directory = rtrim ( $ directory , '/\\' . DIRECTORY_SEPARATOR ) ; if ( ! file_exists ( $ directory ) ) { $ this -> createDirectory ( pathinfo ( $ directory , PATHINFO_DIRNAME ) , $ entry_name ) ; if ( ! mkdir ( $ directory ) ) { throw new \ Exception ( sprintf ( 'Cannot install, failure while creating requisite directory "%s"' , $ directory ) ) ; } } else { if ( ! is_dir ( $ directory ) ) { throw new \ Exception ( sprintf ( 'Cannot install, requisite path "%s" exists, but is not a directory' , $ directory ) ) ; } if ( ! is_writable ( $ directory ) ) { throw new \ Exception ( sprintf ( 'Cannot install, requisite directory "%s" is not writable' , $ directory ) ) ; } } $ this -> map ( $ directory , $ entry_name ) ; } | Attempts to create a directory and make sure it s writable while mapping any created directories . |
36,505 | private function loadInstallationMap ( ) { if ( file_exists ( $ this -> mapFile ) ) { if ( ! is_readable ( $ this -> mapFile ) || is_dir ( $ this -> mapFile ) ) { throw new \ Exception ( sprintf ( 'Cannot read map file at %s' , $ this -> mapFile ) ) ; } $ this -> installationMap = json_decode ( file_get_contents ( $ this -> mapFile ) , TRUE ) ; if ( $ this -> installationMap === NULL ) { throw new \ Exception ( sprintf ( 'Broken map file at %s' , $ this -> mapFile ) ) ; } } } | Loads the Opus installation map |
36,506 | private function map ( $ destination , $ entry_name ) { $ base_path = str_replace ( DIRECTORY_SEPARATOR , '/' , getcwd ( ) ) ; $ opus_path = str_replace ( $ base_path , '' , $ destination ) ; if ( ! isset ( $ this -> installationMap [ $ opus_path ] ) ) { $ this -> installationMap [ $ opus_path ] = array ( ) ; } if ( ! in_array ( $ entry_name , $ this -> installationMap [ $ opus_path ] ) ) { $ this -> installationMap [ $ opus_path ] [ ] = $ entry_name ; } else { } } | Maps a package entry name to an opus path |
36,507 | private function resolve ( & $ result ) { if ( ! isset ( $ result [ 'conflicts' ] ) || ! count ( $ result [ 'conflicts' ] ) ) { return ; } $ original_checksums = isset ( $ this -> installationMap [ '__CHECKSUMS__' ] ) ? $ this -> installationMap [ '__CHECKSUMS__' ] : array ( ) ; foreach ( $ result [ 'conflicts' ] as $ a => $ b ) { $ base_path = str_replace ( DIRECTORY_SEPARATOR , '/' , getcwd ( ) ) ; $ opus_path = str_replace ( $ base_path , '' , $ b ) ; $ current_checksum = md5 ( @ file_get_contents ( $ b ) ) ; $ new_checksum = md5 ( @ file_get_contents ( $ a ) ) ; $ old_checksum = isset ( $ original_checksums [ $ opus_path ] ) ? $ original_checksums [ $ opus_path ] : md5 ( FALSE ) ; switch ( $ this -> integrity ) { case 'low' : copy ( $ a , $ b ) ; break ; case 'medium' : if ( $ new_checksum == $ old_checksum ) { break ; } elseif ( $ old_checksum == $ current_checksum ) { copy ( $ a , $ b ) ; $ result [ 'updates' ] [ $ opus_path ] = $ new_checksum ; break ; } else { } case 'high' : $ answer = NULL ; $ this -> io -> write ( PHP_EOL . self :: TAB . 'The following conflicts were found:' . PHP_EOL ) ; while ( ! $ answer ) { $ answer = $ this -> io -> ask ( sprintf ( self :: TAB . '- %s [o=overwrite (default), k=keep, d=diff]: ' , $ opus_path ) , 'o' ) ; switch ( strtolower ( $ answer [ 0 ] ) ) { case 'o' : copy ( $ a , $ b ) ; $ result [ 'updates' ] [ $ opus_path ] = $ new_checksum ; break ; case 'k' : $ result [ 'updates' ] [ $ opus_path ] = $ new_checksum ; break ; case 'd' : $ this -> io -> write ( PHP_EOL . self :: diff ( $ a , $ b ) . PHP_EOL ) ; default : $ answer = NULL ; break ; } } break ; } } } | Resolve conflicts by prompting the user for action |
36,508 | private function saveInstallationMap ( $ result = array ( ) ) { if ( isset ( $ this -> installationMap [ '__CHECKSUMS__' ] ) ) { $ original_checksums = $ this -> installationMap [ '__CHECKSUMS__' ] ; unset ( $ this -> installationMap [ '__CHECKSUMS__' ] ) ; } else { $ original_checksums = array ( ) ; } if ( $ result && isset ( $ result [ 'updates' ] ) ) { foreach ( $ result [ 'updates' ] as $ opus_path => $ checksum ) { $ original_checksums [ $ opus_path ] = $ checksum ; } } $ this -> installationMap [ '__CHECKSUMS__' ] = $ original_checksums ; if ( file_exists ( $ this -> mapFile ) ) { if ( ! is_writable ( $ this -> mapFile ) || is_dir ( $ this -> mapFile ) ) { throw new \ Exception ( sprintf ( 'Cannot write to map file at %s' , $ this -> mapFile ) ) ; } } if ( ! file_put_contents ( $ this -> mapFile , json_encode ( $ this -> installationMap ) ) ) { throw new \ Exception ( sprintf ( 'Error while saving map file at %s' , $ this -> mapFile ) ) ; } } | Saves the Opus installation map |
36,509 | protected function getTemplate ( $ template , $ className ) { $ this -> template = $ this -> file -> get ( $ template ) ; $ resource = strtolower ( Pluralizer :: plural ( str_ireplace ( 'Controller' , '' , $ className ) ) ) ; if ( $ this -> needsScaffolding ( $ template ) ) { $ this -> template = $ this -> getScaffoldedController ( $ template , $ className ) ; } $ template = str_replace ( '{{className}}' , $ className , $ this -> template ) ; return str_replace ( '{{collection}}' , $ resource , $ template ) ; } | Fetch the compiled template for a controller |
36,510 | public function compileTruncate ( Builder $ query ) { $ sql = array ( 'delete from sqlite_sequence where name = ?' => array ( $ query -> from ) ) ; $ sql [ 'delete from ' . $ this -> wrapTable ( $ query -> from ) ] = array ( ) ; return $ sql ; } | Compile a truncate table statement into SQL . |
36,511 | public function is ( ) { foreach ( func_get_args ( ) as $ pattern ) { if ( str_is ( $ pattern , $ this -> path ( ) ) ) { return true ; } } return false ; } | Determine if the current request URI matches a pattern accepting patterns to test as function arguments . |
36,512 | public function has ( $ key ) { if ( count ( func_get_args ( ) ) > 1 ) { foreach ( func_get_args ( ) as $ value ) { if ( ! $ this -> has ( $ value ) ) return false ; } return true ; } if ( is_bool ( $ this -> input ( $ key ) ) || is_array ( $ this -> input ( $ key ) ) ) { return true ; } return trim ( ( string ) $ this -> input ( $ key ) ) !== '' ; } | Determine if the request contains a given input item . |
36,513 | public static function createFromBase ( SymfonyRequest $ request ) { if ( $ request instanceof static ) return $ request ; return with ( $ self = new static ) -> duplicate ( $ request -> query -> all ( ) , $ request -> request -> all ( ) , $ request -> attributes -> all ( ) , $ request -> cookies -> all ( ) , $ request -> files -> all ( ) , $ request -> server -> all ( ) ) ; } | Create an FlyPHP request from a Symfony instance . |
36,514 | private function getPersonalityInsightsQueryVariables ( ) { $ queryParams = [ 'raw_scores' => $ this -> rawScores ? 'true' : 'false' , 'consumption_preferences' => ( string ) $ this -> includeConsumption ? 'true' : 'false' , 'version' => $ this -> version , ] ; return http_build_query ( $ queryParams ) ; } | Retrieves the expected config for the Personality Insights API |
36,515 | public function getAuthUrl ( ) { $ return = $ this -> baseUrl . '/' . $ this -> authNamespace . '/' . $ this -> authVersion . '/token?url=' . $ this -> baseUrl . '/' . $ this -> apiNamespace ; return $ return ; } | Gets the Authentication URL |
36,516 | public function setVersion ( string $ version ) { if ( Validation :: isValidVersionRegex ( $ version ) ) { $ this -> version = $ version ; } else { throw new CustomException ( 'Malformed version' ) ; } } | Set the version if it is valid |
36,517 | public function setContentTypeHeader ( string $ header ) { if ( Validation :: isValidContentType ( $ header ) ) { $ this -> contentTypeHeader = $ header ; } else { throw new CustomException ( 'Invalid content type' ) ; } } | Set the content type header |
36,518 | public function setContentLanguageHeader ( string $ header ) { if ( Validation :: isValidContentLanguage ( $ header ) ) { $ this -> contentLanguageHeader = $ header ; } else { throw new CustomException ( 'Invalid language' ) ; } } | Set the content language header |
36,519 | public function setAcceptHeader ( string $ header ) { if ( Validation :: isValidAcceptType ( $ header ) ) { $ this -> acceptHeader = $ header ; } else { throw new CustomException ( 'Invalid accept type' ) ; } } | Set accept header |
36,520 | public function setAcceptLanguageHeader ( string $ header ) { if ( Validation :: isValidAcceptLanguage ( $ header ) ) { $ this -> acceptLanguageHeader = $ header ; } else { throw new CustomException ( 'Invalid accept language' ) ; } } | Set accept language header |
36,521 | private function preSet ( $ name , $ value ) { if ( array_search ( $ value , $ this -> _container ) !== false ) { throw new Exception ( __CLASS__ . "::" . __FUNCTION__ . "('$name', value)" . self :: ITEM_EXISTS ) ; } } | Pre regist . |
36,522 | public function parse ( ) { $ this -> ensureFileIsReadable ( ) ; $ envVariables = array ( ) ; $ filePath = $ this -> filePath ; $ lines = $ this -> readLinesFromFile ( $ filePath ) ; foreach ( $ lines as $ line ) { if ( ! $ this -> isComment ( $ line ) && $ this -> looksLikeSetter ( $ line ) ) { list ( $ name , $ value ) = $ this -> normaliseEnvironmentVariable ( $ line , null ) ; $ envVariables [ $ name ] = $ value ; } } return $ envVariables ; } | Returns the environment variables from the file as associative array |
36,523 | public function getAccessorName ( Model $ model = null ) { if ( is_null ( $ model ) ) { $ model = $ this -> getFromModel ( ) ; } if ( $ this -> relatedName ) { return $ this -> relatedName ; } $ name = strtolower ( $ model -> getMeta ( ) -> getModelName ( ) ) ; return ( $ this -> multiple ) ? sprintf ( '%s_set' , $ name ) : $ name ; } | This method encapsulates the logic that decides what name to give an accessor descriptor that retrieves related many - to - one or many - to - many objects . It uses the lower - cased object_name + _set but this can be overridden with the related_name option . |
36,524 | static function round12b ( $ val ) { if ( $ val > 100 ) return round ( $ val ) ; if ( $ val > 10 ) return round ( $ val , 1 ) ; if ( $ val - floor ( $ val ) > 0.2 ) return round ( $ val , 1 ) ; return round ( $ val , 2 ) ; } | 1 . 02 1 . 5 10 . 1 90 . 2 155 |
36,525 | public function renderWithMaxLength ( $ string , $ max = 0 , $ dots = true ) { $ field = $ this -> renderNakedField ( $ string ) ; if ( mb_strlen ( $ field ) > $ max && $ max > 0 ) { $ break = "*-*-*" ; $ wrap = wordwrap ( $ field , $ max , $ break ) ; $ items = explode ( $ break , $ wrap ) ; $ string = ( isset ( $ items [ 0 ] ) ? $ items [ 0 ] : "" ) . ( $ dots ? "..." : "" ) ; } return $ string ; } | Check string length and return him summary or in original |
36,526 | public function loadBlock ( $ id ) { $ block = $ this -> entityTypeManager -> getStorage ( 'block' ) -> load ( $ id ) ; return $ block ? $ this -> entityTypeManager -> getViewBuilder ( 'block' ) -> view ( $ block ) : '' ; } | Return array of selected block |
36,527 | public function loadRegion ( $ id ) { $ blocks = $ this -> entityTypeManager -> getStorage ( 'block' ) -> loadByProperties ( [ 'region' => $ id , 'theme' => $ this -> themeName ] ) ; $ result = [ ] ; foreach ( $ blocks as $ id => $ values ) { $ result [ ] = $ this -> loadBlock ( $ id ) ; } return $ result ; } | Render region by id |
36,528 | public function loadGalleryThumbs ( $ id , $ thumbnail = 'thumbnail' ) { $ gallery = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( $ id ) ; $ images = $ gallery -> get ( 'field_media_images' ) ; $ result = [ ] ; if ( $ images ) { foreach ( $ images as $ image ) { $ mid = $ image -> entity -> id ( ) ; $ fileEntity = $ image -> entity -> field_image -> entity ; $ fid = $ image -> entity -> field_image -> entity -> id ( ) ; $ imageUrl = $ fileEntity -> getFileUri ( ) ; $ result [ ] = [ 'mid' => $ mid , 'fid' => $ fid , 'thumb' => ImageStyle :: load ( $ thumbnail ) -> buildUrl ( $ imageUrl ) , ] ; } } return $ result ; } | Load gallery images |
36,529 | public function getMainNode ( $ returnId = true ) { $ node = \ Drupal :: routeMatch ( ) -> getParameter ( 'node' ) ; if ( $ node ) { return $ returnId ? $ node -> id ( ) : $ node ; } return null ; } | Load main node object anywhere |
36,530 | public function getMediaData ( $ currentId , $ dateComparator , $ sortOrder , $ thumbnail ) { $ current = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( $ currentId ) ; if ( ! $ current ) { return null ; } $ prev_or_next = \ Drupal :: entityQuery ( 'media' ) -> condition ( 'bundle' , $ current -> bundle ( ) ) -> condition ( 'status' , 1 ) -> condition ( 'created' , $ current -> getCreatedTime ( ) , $ dateComparator ) -> sort ( 'created' , $ sortOrder ) -> range ( 0 , 1 ) -> execute ( ) ; if ( ! $ prev_or_next ) { return null ; } $ gallery = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( array_values ( $ prev_or_next ) [ 0 ] ) ; $ all = $ gallery -> get ( 'field_media_images' ) ; if ( isset ( $ all [ 0 ] ) ) { $ file = $ all [ 0 ] -> entity -> field_image -> entity -> getFileUri ( ) ; return [ 'id' => $ gallery -> id ( ) , 'title' => $ gallery -> label ( ) , 'path' => $ gallery -> toUrl ( ) -> toString ( ) , 'images' => $ all , 'thumb' => ImageStyle :: load ( $ thumbnail ) -> buildUrl ( $ file ) ] ; } return null ; } | Load one gallery |
36,531 | public function validate ( array $ rules = array ( ) , array $ customMessages = array ( ) ) { if ( $ this -> fireModelEvent ( 'validating' ) === false ) { if ( $ this -> throwOnValidation ) { throw new InvalidModelException ( $ this ) ; } else { return false ; } } $ rules = ( empty ( $ rules ) ) ? static :: $ rules : $ rules ; foreach ( $ rules as $ field => $ rls ) { if ( $ rls == '' ) { unset ( $ rules [ $ field ] ) ; } } if ( empty ( $ rules ) ) { $ success = true ; } else { $ customMessages = ( empty ( $ customMessages ) ) ? static :: $ customMessages : $ customMessages ; if ( $ this -> forceEntityHydrationFromInput || ( empty ( $ this -> attributes ) && $ this -> autoHydrateEntityFromInput ) ) { $ this -> fill ( Input :: all ( ) ) ; } $ data = $ this -> getAttributes ( ) ; $ validator = static :: makeValidator ( $ data , $ rules , $ customMessages ) ; $ success = $ validator -> passes ( ) ; if ( $ success ) { if ( $ this -> validationErrors -> count ( ) > 0 ) { $ this -> validationErrors = new MessageBag ; } } else { $ this -> validationErrors = $ validator -> messages ( ) ; if ( ! self :: $ externalValidator && Input :: hasSession ( ) ) { Input :: flash ( ) ; } } } $ this -> fireModelEvent ( 'validated' , false ) ; if ( ! $ success && $ this -> throwOnValidation ) { throw new InvalidModelException ( $ this ) ; } return $ success ; } | Validate the model instance |
36,532 | public function forceSave ( array $ rules = array ( ) , array $ customMessages = array ( ) , array $ options = array ( ) , Closure $ beforeSave = null , Closure $ afterSave = null ) { return $ this -> internalSave ( $ rules , $ customMessages , $ options , $ beforeSave , $ afterSave , true ) ; } | Force save the model even if validation fails . |
36,533 | protected function addBasicPurgeFilters ( ) { if ( $ this -> purgeFiltersInitialized ) { return ; } $ this -> purgeFilters [ ] = function ( $ attributeKey ) { if ( Str :: endsWith ( $ attributeKey , '_confirmation' ) ) { return false ; } if ( strcmp ( $ attributeKey , '_method' ) === 0 ) { return false ; } if ( strcmp ( $ attributeKey , '_token' ) === 0 ) { return false ; } return true ; } ; $ this -> purgeFiltersInitialized = true ; } | Add the basic purge filters |
36,534 | protected function purgeArray ( array $ array = array ( ) ) { $ result = array ( ) ; $ keys = array_keys ( $ array ) ; $ this -> addBasicPurgeFilters ( ) ; if ( ! empty ( $ keys ) && ! empty ( $ this -> purgeFilters ) ) { foreach ( $ keys as $ key ) { $ allowed = true ; foreach ( $ this -> purgeFilters as $ filter ) { $ allowed = $ filter ( $ key ) ; if ( ! $ allowed ) { break ; } } if ( $ allowed ) { $ result [ $ key ] = $ array [ $ key ] ; } } } return $ result ; } | Removes redundant attributes from model |
36,535 | protected function performSave ( array $ options ) { if ( $ this -> autoPurgeRedundantAttributes ) { $ this -> attributes = $ this -> purgeArray ( $ this -> getAttributes ( ) ) ; } if ( $ this -> autoHashPasswordAttributes ) { $ this -> attributes = $ this -> hashPasswordAttributes ( $ this -> getAttributes ( ) , static :: $ passwordAttributes ) ; } return parent :: save ( $ options ) ; } | Saves the model instance to database . If necessary it will purge the model attributes of unnecessary fields . It will also replace plain - text password fields with their hashes . |
36,536 | protected function buildUniqueExclusionRules ( array $ rules = array ( ) ) { if ( ! count ( $ rules ) ) $ rules = static :: $ rules ; foreach ( $ rules as $ field => & $ ruleset ) { $ ruleset = ( is_string ( $ ruleset ) ) ? explode ( '|' , $ ruleset ) : $ ruleset ; foreach ( $ ruleset as & $ rule ) { if ( strpos ( $ rule , 'unique' ) === 0 ) { $ params = explode ( ',' , $ rule ) ; $ uniqueRules = array ( ) ; $ table = explode ( ':' , $ params [ 0 ] ) ; if ( count ( $ table ) == 1 ) $ uniqueRules [ 1 ] = $ this -> table ; else $ uniqueRules [ 1 ] = $ table [ 1 ] ; if ( count ( $ params ) == 1 ) $ uniqueRules [ 2 ] = $ field ; else $ uniqueRules [ 2 ] = $ params [ 1 ] ; if ( isset ( $ this -> primaryKey ) ) { $ uniqueRules [ 3 ] = $ this -> { $ this -> primaryKey } ; $ uniqueRules [ 4 ] = $ this -> primaryKey ; } else { $ uniqueRules [ 3 ] = $ this -> id ; } $ rule = 'unique:' . implode ( ',' , $ uniqueRules ) ; } } } return $ rules ; } | When given an ID and a FlyPHP validation rules array this function appends the ID to the unique rules given . The resulting array can then be fed to a SmartModel save so that unchanged values don t flag a validation issue . Rules can be in either strings with pipes or arrays but the returned rules are in arrays . |
36,537 | public function updateUniques ( array $ rules = array ( ) , array $ customMessages = array ( ) , array $ options = array ( ) , Closure $ beforeSave = null , Closure $ afterSave = null ) { $ rules = $ this -> buildUniqueExclusionRules ( $ rules ) ; return $ this -> save ( $ rules , $ customMessages , $ options , $ beforeSave , $ afterSave ) ; } | Update a model but filter uniques first to ensure a unique validation rule does not fire |
36,538 | public function validateUniques ( array $ rules = array ( ) , array $ customMessages = array ( ) ) { $ rules = $ this -> buildUniqueExclusionRules ( $ rules ) ; return $ this -> validate ( $ rules , $ customMessages ) ; } | Validates a model with unique rules properly treated . |
36,539 | static public function recordValues ( array $ vars ) { foreach ( $ vars as $ varName => $ value ) { self :: $ custom_variables [ $ varName ] = $ value ; } } | Record a list of values associated with a set of variables in a single call |
36,540 | static public function registerShutdownPerfLogger ( $ onlyIfConfigured = false , $ eZ5Context = false ) { if ( $ onlyIfConfigured && eZPerfLoggerINI :: variable ( 'GeneralSettings' , 'AlwaysRegisterShutdownPerfLogger' ) !== 'enabled' ) { return false ; } foreach ( eZExecution :: cleanupHandlers ( ) as $ handler ) { if ( $ handler == array ( __CLASS__ , 'cleanup' ) || $ handler == array ( __CLASS__ , 'cleanupOnCleanExit' ) ) { return true ; } } if ( $ eZ5Context ) { eZExecution :: addCleanupHandler ( array ( __CLASS__ , 'cleanupOnCleanExit' ) ) ; } else { eZExecution :: addCleanupHandler ( array ( __CLASS__ , 'cleanup' ) ) ; } return true ; } | Registers the cleanup function as shutdown handler trying to do it only once |
36,541 | public static function getValues ( $ doMeasure , $ output , $ returnCode = null ) { if ( $ doMeasure ) { foreach ( eZPerfLoggerINI :: variable ( 'GeneralSettings' , 'VariableProviders' ) as $ measuringClass ) { $ measured = call_user_func_array ( array ( $ measuringClass , 'measure' ) , array ( $ output , $ returnCode ) ) ; if ( is_array ( $ measured ) ) { self :: recordValues ( $ measured ) ; } else { eZPerfLoggerDebug :: writeError ( "Perf measuring class $measuringClass did not return an array of data" , __METHOD__ ) ; } } } return self :: $ custom_variables ; } | Returns all the perf . values measured so far . |
36,542 | public static function getModuleData ( $ var , $ default = null ) { if ( strpos ( $ var , 'module_params/' ) === 0 ) { return self :: getModuleParamsData ( $ var , $ default ) ; } else if ( strpos ( $ var , 'content_info/' ) === 0 || strpos ( $ var , 'module_result/' ) === 0 ) { return self :: getModuleResultData ( $ var , $ default ) ; } else { eZPerfLoggerDebug :: writeWarning ( "Can not recover module result variable $var" , __METHOD__ ) ; return $ default ; } } | Encapsulates retrieval of module_result data to make it available globally across all eZP versions . |
36,543 | public static function getStream ( ) { $ tweetStore = Store :: get ( 'Tweet' ) ; $ consumerKey = Setting :: getSetting ( 'twitter' , 'consumer_key' ) ; $ consumerSecret = Setting :: getSetting ( 'twitter' , 'consumer_secret' ) ; $ accessToken = Setting :: getSetting ( 'twitter' , 'access_token' ) ; $ accessTokenSecret = Setting :: getSetting ( 'twitter' , 'access_token_secret' ) ; $ streamSearch = Setting :: getSetting ( 'twitter' , 'stream_search' ) ; $ twitter = new Twitter ( $ consumerKey , $ consumerSecret , $ accessToken , $ accessTokenSecret ) ; if ( self :: canCallAPI ( ) ) { self :: updateLastAPICall ( ) ; $ stream = $ twitter -> search ( $ streamSearch ) ; foreach ( $ stream as $ s ) { if ( ! $ tweetStore -> getByTwitterIdForScope ( $ s -> id , 'stream' ) ) { $ t = new Tweet ; $ t -> setTwitterId ( $ s -> id ) ; $ t -> setText ( $ s -> text ) ; $ t -> setHtmlText ( Twitter :: clickable ( $ s ) ) ; $ t -> setScreenname ( $ s -> user -> screen_name ) ; $ t -> setPosted ( $ s -> created_at ) ; $ t -> setCreatedDate ( new \ DateTime ( ) ) ; $ t -> setScope ( 'stream' ) ; $ tweetStore -> insert ( $ t ) ; } } } } | Get the stream of tweets for the search term and cache to the database |
36,544 | public static function getUser ( ) { $ tweetStore = Store :: get ( 'Tweet' ) ; $ consumerKey = Setting :: getSetting ( 'twitter' , 'consumer_key' ) ; $ consumerSecret = Setting :: getSetting ( 'twitter' , 'consumer_secret' ) ; $ accessToken = Setting :: getSetting ( 'twitter' , 'access_token' ) ; $ accessTokenSecret = Setting :: getSetting ( 'twitter' , 'access_token_secret' ) ; $ twitter = new Twitter ( $ consumerKey , $ consumerSecret , $ accessToken , $ accessTokenSecret ) ; if ( self :: canCallAPI ( ) ) { self :: updateLastAPICall ( ) ; $ statuses = $ twitter -> load ( Twitter :: ME ) ; foreach ( $ statuses as $ s ) { if ( ! $ tweetStore -> getByTwitterIdForScope ( $ s -> id , 'user' ) ) { $ t = new Tweet ; $ t -> setTwitterId ( $ s -> id ) ; $ t -> setText ( $ s -> text ) ; $ t -> setHtmlText ( Twitter :: clickable ( $ s ) ) ; $ t -> setScreenname ( $ s -> user -> screen_name ) ; $ t -> setPosted ( $ s -> created_at ) ; $ t -> setCreatedDate ( new \ DateTime ( ) ) ; $ t -> setScope ( 'user' ) ; $ tweetStore -> saveByInsert ( $ t ) ; } } } } | Get tweets for the currently authenticated twitter user |
36,545 | public static function canCallAPI ( ) { $ lastCall = Setting :: getSetting ( 'twitter' , 'last_api_call' ) ; if ( $ lastCall == null ) { return true ; } else { $ lastCall = new \ DateTime ( $ lastCall ) ; } $ now = new \ DateTime ( ) ; $ interval = $ lastCall -> diff ( $ now ) ; if ( $ interval -> i >= 1 ) { return true ; } else { return false ; } } | Checks whether the API can be called |
36,546 | public function parseJSKOS ( PrettyJsonSerializable $ jskos ) : EasyRdf_Graph { if ( ! $ this -> context ) { $ this -> context = json_decode ( file_get_contents ( __DIR__ . '/jskos-context.json' ) ) ; } if ( $ jskos instanceof Set ) { $ json = '{"@graph":' . json_encode ( $ jskos -> jsonLDSerialize ( '' , true ) ) . '}' ; } else { $ json = json_encode ( $ jskos -> jsonLDSerialize ( '' , true ) ) ; } $ rdf = JsonLD :: toRdf ( $ json , [ 'expandContext' => $ this -> context ] ) ; $ graph = new EasyRdf_Graph ( ) ; $ this -> parse ( $ graph , $ rdf ) ; return $ graph ; } | Parse JSKOS Resources to RDF . |
36,547 | public function parse ( $ graph , $ data , $ format = 'jsonld' , $ baseUri = null ) { parent :: checkParseParams ( $ graph , $ data , $ format , $ baseUri ) ; foreach ( $ data as $ quad ) { $ subject = ( string ) $ quad -> getSubject ( ) ; if ( '_:' === substr ( $ subject , 0 , 2 ) ) { $ subject = $ this -> remapBnode ( $ subject ) ; } $ predicate = ( string ) $ quad -> getProperty ( ) ; if ( $ quad -> getObject ( ) instanceof IRI ) { $ object = [ 'type' => 'uri' , 'value' => ( string ) $ quad -> getObject ( ) ] ; if ( '_:' === substr ( $ object [ 'value' ] , 0 , 2 ) ) { $ object = [ 'type' => 'bnode' , 'value' => $ this -> remapBnode ( $ object [ 'value' ] ) ] ; } } else { $ object = [ 'type' => 'literal' , 'value' => $ quad -> getObject ( ) -> getValue ( ) ] ; if ( $ quad -> getObject ( ) instanceof LanguageTaggedString ) { $ object [ 'lang' ] = $ quad -> getObject ( ) -> getLanguage ( ) ; } else { $ object [ 'datatype' ] = $ quad -> getObject ( ) -> getType ( ) ; } } $ this -> addTriple ( $ subject , $ predicate , $ object ) ; } } | Parse Quads as returned by JsonLD . |
36,548 | public function dim ( $ percent ) { if ( $ percent < 0 ) { $ percent = 0 ; } else if ( $ percent > 100 ) { $ percent = 100 ; } $ level = round ( ( 255 * $ percent ) / 100 ) ; return $ this -> bridge -> setDeviceStatus ( $ this -> deviceId , null , $ level ) ; } | Dims Wemo bulb to specified percentage |
36,549 | public function dimState ( ) { $ currentState = $ this -> bridge -> getBulbState ( $ this -> deviceId ) ; $ level = explode ( ':' , $ currentState [ 1 ] ) [ 0 ] ; $ percent = round ( ( $ level * 100 ) / 255 ) ; return $ percent ; } | Returns dim level |
36,550 | protected function setupBorisErrorHandling ( ) { restore_error_handler ( ) ; restore_exception_handler ( ) ; $ this -> flyphp -> make ( 'flyconsole' ) -> setCatchExceptions ( false ) ; $ this -> flyphp -> error ( function ( ) { return '' ; } ) ; } | Setup the Boris exception handling . |
36,551 | protected function runPlainShell ( ) { $ input = $ this -> prompt ( ) ; while ( $ input != 'quit' ) { try { if ( starts_with ( $ input , 'dump ' ) ) { $ input = 'var_dump(' . substr ( $ input , 5 ) . ');' ; } eval ( $ input ) ; } catch ( \ Exception $ e ) { $ this -> error ( $ e -> getMessage ( ) ) ; } $ input = $ this -> prompt ( ) ; } } | Run the plain FlyConsole tinker shell . |
36,552 | protected function prompt ( ) { $ dialog = $ this -> getHelperSet ( ) -> get ( 'dialog' ) ; return $ dialog -> ask ( $ this -> output , "<info>></info>" , null ) ; } | Prompt the developer for a command . |
36,553 | public function hasAccess ( array $ url , array $ user ) : bool { $ result = parent :: hasAccess ( $ url , $ user ) ; if ( ! $ result ) { return $ result ; } if ( ! empty ( $ user [ 'is_superuser' ] ) && $ user [ 'is_superuser' ] ) { return true ; } return false ; } | hasAccess for super user |
36,554 | public function save ( ) { static :: checkReadOnly ( ) ; $ is_fresh = $ this -> isFresh ( ) ; $ this -> updateStampColumns ( ) ; if ( ( $ is_fresh && ! $ this -> onFirstSave ( ) ) || ! $ this -> onSave ( ) || empty ( $ this -> changes ) ) { return ; } $ data = $ this -> changes ; $ data = static :: validate ( $ data , $ is_fresh ) ; $ database = self :: getDatabase ( ) ; $ stmt = ( $ is_fresh ) ? $ database -> insert ( static :: TABLE , $ data ) : $ database -> update ( static :: TABLE , $ data , $ this -> getPrimaryKey ( ) ) ; $ error_code = $ stmt -> errorCode ( ) ; if ( $ error_code == '00000' ) { $ data = $ this -> getData ( ) ; if ( $ is_fresh ) { $ column = static :: AUTO_INCREMENT ; if ( $ column !== null ) { $ data [ $ column ] = $ database -> id ( ) ; } } $ where = Utils :: arrayWhitelist ( $ data , static :: PRIMARY_KEY ) ; return $ this -> load ( $ where ) ; } return $ error_code ; } | Creates a new row in the Table or updates it with new data |
36,555 | public function load ( $ where ) { $ where = self :: processWhere ( $ where ) ; $ old_primary_key = $ this -> getPrimaryKey ( ) ; $ database = self :: getDatabase ( ) ; $ data = $ database -> get ( static :: TABLE , static :: COLUMNS , $ where ) ; if ( $ data ) { $ this -> reset ( ) ; $ this -> data = $ data ; if ( $ old_primary_key ) { $ this -> managerUpdate ( $ old_primary_key ) ; } else { $ this -> managerExport ( ) ; } return true ; } return false ; } | Loads a row from Table into the model |
36,556 | public function update ( $ columns ) { static :: checkReadOnly ( ) ; if ( $ this -> isFresh ( ) ) { $ message = 'Can not update fresh Model: ' . static :: class ; throw new \ LogicException ( $ message ) ; } $ this -> updateStampColumns ( $ columns ) ; $ columns = ( array ) $ columns ; $ data = Utils :: arrayWhitelist ( $ this -> changes , $ columns ) ; $ data = static :: validate ( $ data , false ) ; $ database = self :: getDatabase ( ) ; $ stmt = $ database -> update ( static :: TABLE , $ data , $ this -> getPrimaryKey ( ) ) ; $ error_code = $ stmt -> errorCode ( ) ; if ( $ error_code == '00000' ) { $ changes = Utils :: arrayBlacklist ( $ this -> changes , $ columns ) ; $ data = $ this -> getData ( ) ; $ where = Utils :: arrayWhitelist ( $ data , static :: PRIMARY_KEY ) ; if ( $ this -> load ( $ where ) ) { $ this -> changes = $ changes ; return true ; } return false ; } return $ error_code ; } | Selectively updates the model s row in the Database |
36,557 | public function delete ( ) { static :: checkReadOnly ( ) ; $ column = static :: SOFT_DELETE ; if ( $ column ) { switch ( static :: SOFT_DELETE_MODE ) { case 'deleted' : $ value = 1 ; break ; case 'active' : $ value = 0 ; break ; case 'stamp' : $ value = static :: getCurrentTimestamp ( ) ; break ; default : throw new \ LogicException ( sprintf ( "%s has invalid SOFT_DELETE_MODE mode: '%s'" , static :: class , static :: SOFT_DELETE_MODE ) ) ; break ; } $ this -> __set ( $ column , $ value ) ; if ( $ this -> isFresh ( ) ) { return true ; } return $ this -> update ( $ column ) ; } $ database = self :: getDatabase ( ) ; $ stmt = $ database -> delete ( static :: TABLE , $ this -> getPrimaryKey ( ) ) ; if ( $ stmt -> rowCount ( ) > 0 ) { ModelManager :: remove ( $ this ) ; $ this -> reset ( ) ; return true ; } return false ; } | Removes model s row from the Table or sets the SOFT_DELETE column |
36,558 | public static function dump ( $ where = [ ] , $ columns = [ ] ) { $ columns = ( empty ( $ columns ) ) ? static :: COLUMNS : array_values ( self :: getTypedColumns ( $ columns ) ) ; $ database = self :: getDatabase ( ) ; return $ database -> select ( static :: TABLE , $ columns , $ where ) ; } | Returns data in model s Table |
36,559 | public function fill ( array $ data ) { foreach ( $ data as $ column => $ value ) { $ this -> __set ( $ column , $ value ) ; } return $ this ; } | Changes the value in multiple columns |
36,560 | final public static function getColumns ( ) { $ result = [ ] ; foreach ( static :: COLUMNS as $ column ) { $ result [ ] = trim ( explode ( '[' , $ column , 2 ) [ 0 ] ) ; } return $ result ; } | Returns columns list without data type |
36,561 | public static function getCurrentTimestamp ( ) { $ database = self :: getDatabase ( ) ; $ sql = 'SELECT CURRENT_TIMESTAMP' ; return $ database -> query ( $ sql ) -> fetch ( \ PDO :: FETCH_NUM ) [ 0 ] ; } | Selects Current Timestamp from Database |
36,562 | final public function isDeleted ( ) { $ column = static :: SOFT_DELETE ; if ( $ column ) { $ value = $ this -> __get ( $ column ) ; switch ( static :: SOFT_DELETE_MODE ) { case 'deleted' : $ result = ( int ) $ value === 1 ; break ; case 'active' : $ result = ( int ) $ value === 0 ; break ; case 'stamp' : $ result = $ value !== null ; break ; default : throw new \ LogicException ( sprintf ( "%s has invalid SOFT_DELETE_MODE mode: '%s'" , static :: class , static :: SOFT_DELETE_MODE ) ) ; break ; } return $ result ; } return false ; } | Tells if Model is deleted |
36,563 | public function undelete ( ) { static :: checkReadOnly ( ) ; $ column = static :: SOFT_DELETE ; if ( $ column ) { switch ( static :: SOFT_DELETE_MODE ) { case 'deleted' : $ value = 0 ; break ; case 'active' : $ value = 1 ; break ; case 'stamp' : $ value = null ; break ; default : throw new \ LogicException ( sprintf ( "%s has invalid SOFT_DELETE_MODE mode: '%s'" , static :: class , static :: SOFT_DELETE_MODE ) ) ; break ; } $ this -> __set ( $ column , $ value ) ; if ( $ this -> isFresh ( ) ) { return true ; } return $ this -> update ( $ column ) ; } $ message = 'Model ' . static :: class . ' is not soft-deletable' ; throw new \ LogicException ( $ message ) ; } | Sets the SOFT_DELETE column to a undeleted state |
36,564 | final public static function addColumnTypeKeys ( array $ data ) { $ columns = self :: getTypedColumns ( array_keys ( $ data ) ) ; return array_combine ( $ columns , array_merge ( $ columns , $ data ) ) ; } | Adds column types in array s keys |
36,565 | final public static function checkUnknownColumn ( $ columns ) { $ unknown = array_diff ( ( array ) $ columns , self :: getColumns ( ) ) ; if ( ! empty ( $ unknown ) ) { throw new UnknownColumnException ( static :: class , $ unknown ) ; } } | Tests if model has columns |
36,566 | public static function getAutoStampColumns ( ) { $ auto_stamp = [ ] ; if ( ! empty ( static :: STAMP_COLUMNS ) ) { $ stamp_columns = self :: normalizeColumnList ( static :: STAMP_COLUMNS ) ; $ auto_stamp = array_filter ( $ stamp_columns , function ( $ mode ) { return $ mode === 'auto' ; } ) ; } return array_keys ( $ auto_stamp ) ; } | Returns STAMP_COLUMNS with auto mode |
36,567 | public function jsonSerialize ( ) { $ data = $ this -> getData ( ) ; if ( empty ( $ data ) ) { return null ; } foreach ( array_keys ( static :: FOREIGN_KEYS ) as $ column ) { $ data [ $ column ] = $ this -> __get ( $ column ) ; } return $ data ; } | Returns the stored data |
36,568 | protected function loadForeign ( $ column , $ value ) { static :: checkUnknownColumn ( $ column ) ; if ( ! array_key_exists ( $ column , static :: FOREIGN_KEYS ) ) { throw new NotForeignColumnException ( static :: class , $ column ) ; } $ foreign_map = static :: FOREIGN_KEYS [ $ column ] ; if ( $ value === null ) { unset ( $ this -> foreign [ $ column ] ) ; return ; } $ foreign = ModelManager :: getInstance ( $ foreign_map [ 0 ] , [ $ foreign_map [ 1 ] => $ value ] ) ; if ( $ foreign ) { $ this -> foreign [ $ column ] = $ foreign ; } else { throw new ForeignConstraintException ( static :: class , $ column ) ; } } | Updates a foreign model to a new row |
36,569 | final protected static function normalizeColumnList ( $ list , $ default = null ) { $ result = [ ] ; foreach ( $ list as $ key => $ value ) { if ( is_int ( $ key ) ) { $ result [ $ value ] = $ default ; } else { $ result [ $ key ] = $ value ; } } return $ result ; } | Normalize column lists |
36,570 | public function updateStampColumns ( $ subset = null ) { $ columns = self :: normalizeColumnList ( static :: STAMP_COLUMNS , 'datetime' ) ; if ( $ subset !== null ) { $ columns = Utils :: arrayWhitelist ( $ columns , ( array ) $ subset ) ; } $ columns = Utils :: arrayBlacklist ( $ columns , array_keys ( $ this -> changes ) ) ; $ stamp = explode ( ' ' , static :: getCurrentTimestamp ( ) ) ; foreach ( $ columns as $ column => $ mode ) { switch ( $ mode ) { case 'auto' : break ; case 'date' : $ this -> __set ( $ column , $ stamp [ 0 ] ) ; break ; case 'time' : $ this -> __set ( $ column , $ stamp [ 1 ] ) ; break ; case 'datetime' : $ this -> __set ( $ column , implode ( ' ' , $ stamp ) ) ; break ; default : throw new \ LogicException ( sprintf ( "%s (`%s`) has invalid STAMP_COLUMNS mode: '%s'" , static :: class , $ column , $ mode ) ) ; break ; } } } | Updates STAMP_COLUMNS to current timestamp |
36,571 | protected static function validate ( $ data , $ full ) { $ columns = array_keys ( $ data ) ; if ( $ full ) { $ missing = array_diff ( static :: getRequiredColumns ( ) , $ columns ) ; if ( ! empty ( $ missing ) ) { throw new MissingColumnException ( static :: class , $ missing ) ; } } static :: checkUnknownColumn ( $ columns ) ; $ result = static :: onValidate ( $ data ) ; if ( $ result === false ) { $ message = static :: class . ' has invalid data' ; throw new \ UnexpectedValueException ( $ message ) ; } elseif ( is_array ( $ result ) ) { $ data = ( empty ( Utils :: arrayUniqueDiffKey ( $ data , $ result ) ) ) ? $ result : array_replace ( $ data , $ result ) ; } return $ data ; } | Tells if the model has valid data |
36,572 | public function register ( \ Transip \ Model \ Domain $ domain ) { return $ this -> getSoapClient ( array_merge ( array ( $ domain ) , array ( '__method' => 'register' ) ) ) -> register ( $ domain ) ; } | Registers a domain name will automatically create and sign a proposition for it |
36,573 | public function setNameservers ( $ domainName , $ nameservers ) { foreach ( $ nameservers as $ nameserver ) { if ( ! $ nameserver instanceof \ Transip \ Model \ Nameserver ) { throw new \ RuntimeException ( sprintf ( 'nameserver is not an instance of %s' , '\\Transip\\Model\\Nameserver' ) ) ; } } return $ this -> getSoapClient ( array_merge ( array ( $ domainName , $ nameservers ) , array ( '__method' => 'setNameservers' ) ) ) -> setNameservers ( $ domainName , $ nameservers ) ; } | Starts a nameserver change for this domain will replace all existing nameservers with the new nameservers |
36,574 | public function setDnsEntries ( $ domainName , $ dnsEntries ) { foreach ( $ dnsEntries as $ dnsEntry ) { if ( ! $ dnsEntry instanceof \ Transip \ Model \ DnsEntry ) { throw new \ RuntimeException ( sprintf ( 'DnsEntry is not instance of %s' , '\\Transip\\Model\\DnsEntry' ) ) ; } } return $ this -> getSoapClient ( array_merge ( array ( $ domainName , $ dnsEntries ) , array ( '__method' => 'setDnsEntries' ) ) ) -> setDnsEntries ( $ domainName , $ dnsEntries ) ; } | Sets the DnEntries for this Domain will replace all existing dns entries with the new entries |
36,575 | public function setContacts ( $ domainName , $ contacts ) { foreach ( $ contacts as $ contact ) { if ( ! $ contact instanceof \ Transip \ Model \ WhoisContact ) { throw new \ RuntimeException ( sprintf ( 'Contact is not an instance of %s' , '\\Transip\\Model\\WhoisContact' ) ) ; } } return $ this -> getSoapClient ( array_merge ( array ( $ domainName , $ contacts ) , array ( '__method' => 'setContacts' ) ) ) -> setContacts ( $ domainName , $ contacts ) ; } | Starts a contact change of a domain this will replace all existing contacts |
36,576 | public function retryTransferWithDifferentAuthCode ( \ Transip \ Model \ Domain $ domain , $ newAuthCode ) { return $ this -> getSoapClient ( array_merge ( array ( $ domain , $ newAuthCode ) , array ( '__method' => 'retryTransferWithDifferentAuthCode' ) ) ) -> retryTransferWithDifferentAuthCode ( $ domain , $ newAuthCode ) ; } | Retry a transfer action with a new authcode |
36,577 | public function cancelDomainAction ( \ Transip \ Model \ Domain $ domain ) { return $ this -> getSoapClient ( array_merge ( array ( $ domain ) , array ( '__method' => 'cancelDomainAction' ) ) ) -> cancelDomainAction ( $ domain ) ; } | Cancels a failed domain action |
36,578 | private function translateCipher ( int $ nscaName ) : string { if ( isset ( $ this -> cipherMap [ $ nscaName ] ) ) { return $ this -> cipherMap [ $ nscaName ] ; } throw new EncryptionException ( 'Unsupported Cipher' ) ; } | Method to translate ciphers from EncryptorInterface to openSSL |
36,579 | public static function fromModel ( Model $ model , $ excludeRels = false ) { $ fields = [ ] ; foreach ( $ model -> getMeta ( ) -> localFields as $ name => $ field ) { try { $ fields [ $ name ] = $ field -> deepClone ( ) ; } catch ( \ Exception $ e ) { throw new TypeError ( sprintf ( "Couldn't reconstruct field %s on %s: %s" , $ name , $ model -> getMeta ( ) -> getNSModelName ( ) ) ) ; } } if ( false == $ excludeRels ) { foreach ( $ model -> getMeta ( ) -> localManyToMany as $ name => $ field ) { try { $ fields [ $ name ] = $ field -> deepClone ( ) ; } catch ( \ Exception $ e ) { throw new TypeError ( sprintf ( "Couldn't reconstruct field %s on %s: %s" , $ name , $ model -> getMeta ( ) -> getNSModelName ( ) ) ) ; } } } $ overrides = $ model -> getMeta ( ) -> getOverrides ( ) ; $ meta = [ ] ; $ ignore = [ 'registry' ] ; foreach ( $ overrides as $ name => $ value ) { if ( in_array ( $ name , $ ignore ) ) { continue ; } $ meta [ $ name ] = $ value ; } $ extends = '' ; list ( $ concreteParent , $ immediateParent ) = Model :: getHierarchyMeta ( $ model ) ; if ( $ immediateParent ) { if ( $ immediateParent -> isAbstract ( ) ) { $ extends = ( is_null ( $ concreteParent ) ) ? '' : $ concreteParent ; } else { $ extends = $ immediateParent -> getName ( ) ; } } $ kwargs = [ 'meta' => $ meta , 'extends' => $ extends , ] ; return new static ( $ model -> getMeta ( ) -> getNSModelName ( ) , $ fields , $ kwargs ) ; } | Takes a model returns a ModelState representing it . |
36,580 | public function toModel ( & $ registry ) { $ metaData = $ this -> getMeta ( ) ; $ extends = $ this -> extends ; $ className = $ this -> name ; if ( $ this -> fromDisk ) { $ className = sprintf ( '%s\\%s' , Model :: FAKENAMESPACE , $ className ) ; if ( $ extends ) { $ extends = sprintf ( '%s\\%s' , Model :: FAKENAMESPACE , $ extends ) ; } } $ model = $ this -> createInstance ( $ className , $ extends , [ 'registry' => $ registry ] ) ; $ fields = [ ] ; foreach ( $ this -> fields as $ name => $ field ) { $ fields [ $ name ] = $ field -> deepClone ( ) ; } $ model -> setupClassInfo ( $ fields , [ 'meta' => $ metaData , 'registry' => $ registry ] ) ; return $ model ; } | Converts the current modelState into a model . |
36,581 | protected function tagKeys ( array $ keys ) { $ prefix = $ this -> taggedItemKey ( '' ) ; return array_map ( function ( $ key ) use ( $ prefix ) { return $ prefix . $ key ; } , $ keys ) ; } | Prefix all keys and return an array of fully qualified keys for tagged items . |
36,582 | protected function validateCommand ( array & $ data ) { if ( empty ( $ data [ 'command' ] ) ) { throw new InvalidArgumentException ( "'command' property is required" ) ; } if ( empty ( $ data [ 'command_arguments' ] ) ) { $ data [ 'command_arguments' ] = [ ] ; } if ( empty ( $ data [ 'command_environment_variables' ] ) ) { $ data [ 'command_environment_variables' ] = [ ] ; } if ( empty ( $ data [ 'in_background' ] ) ) { $ data [ 'in_background' ] = false ; } if ( $ data [ 'in_background' ] && DIRECTORY_SEPARATOR == '\\' ) { throw new LogicException ( 'Background jobs are not supported on Windows' ) ; } if ( empty ( $ data [ 'log_output_to_file' ] ) ) { $ data [ 'log_output_to_file' ] = '' ; } } | Validate and prepare job data . |
36,583 | public function runCommandFromData ( array $ data , $ from_working_directory = '' ) { return $ this -> runCommand ( $ this -> prepareCommandFromData ( $ data ) , $ from_working_directory , $ data [ 'log_to_file' ] , $ data [ 'in_background' ] ) ; } | Use input data to prepare command and execute it . |
36,584 | public function sign ( $ path ) { $ delimiter = strpos ( $ path , '?' ) === false ? '?' : '&' ; $ path .= $ delimiter . self :: HMAC_TIMESTAMP_QUERY . '=' . time ( ) ; $ sign = hash_hmac ( 'sha1' , $ path , $ this -> secretKey ) ; $ path .= '&' . self :: HMAC_SIGN_QUERY . '=' . $ sign ; return $ path ; } | Signs given path with hmac hashing |
36,585 | protected function validSession ( ) : bool { if ( ! array_key_exists ( self :: CLIENT_SIGNATURE , $ _SESSION ) || ! array_key_exists ( self :: SESSION_CREATED , $ _SESSION ) ) { return false ; } if ( $ _SESSION [ self :: SESSION_CREATED ] < time ( ) - $ this -> lifetime ) { return false ; } if ( ! hash_equals ( $ _SESSION [ self :: CLIENT_SIGNATURE ] , $ this -> clientSignature ) ) { return false ; } return true ; } | Check if session is valid for |
36,586 | public function getTemplateAuthItems ( ) { $ rule = new \ nineinchnick \ nfy \ components \ SubscribedRule ; return [ [ 'name' => 'nfy.queue.read' , 'bizRule' => null , 'child' => null ] , [ 'name' => 'nfy.queue.read.subscribed' , 'bizRule' => $ rule -> name , 'child' => 'nfy.queue.read' ] , [ 'name' => 'nfy.queue.subscribe' , 'bizRule' => null , 'child' => null ] , [ 'name' => 'nfy.queue.unsubscribe' , 'bizRule' => null , 'child' => null ] , [ 'name' => 'nfy.message.read' , 'bizRule' => null , 'child' => null ] , [ 'name' => 'nfy.message.create' , 'bizRule' => null , 'child' => null ] , [ 'name' => 'nfy.message.read.subscribed' , 'bizRule' => $ rule -> name , 'child' => 'nfy.message.read' ] , [ 'name' => 'nfy.message.create.subscribed' , 'bizRule' => $ rule -> name , 'child' => 'nfy.message.create' ] , ] ; } | nfy . queue . read | \ - nfy . queue . read . subscribed nfy . queue . subscribe nfy . queue . unsubscribe |
36,587 | public function getLeafNodes ( $ app = null ) { $ leaves = [ ] ; foreach ( $ this -> nodes as $ appName => $ nodes ) { if ( ! is_null ( $ app ) && $ app != $ appName ) { continue ; } foreach ( $ nodes as $ name => $ migration ) { $ children = $ this -> getNodeFamilyTree ( $ appName , $ name ) -> children ; $ isLatest = true ; foreach ( $ children as $ child ) { if ( $ child -> appName == $ appName ) { $ isLatest = false ; } } if ( $ isLatest ) { if ( ! is_null ( $ app ) ) { $ leaves [ ] = $ name ; } else { $ leaves [ $ appName ] [ ] = $ name ; } } } } return $ leaves ; } | This is a list of all the migrations that are the latest that is no other dependency depends on them . |
36,588 | public function getRootNodes ( ) { $ root = [ ] ; foreach ( $ this -> nodes as $ appName => $ nodes ) { foreach ( $ nodes as $ name => $ migration ) { $ parents = $ this -> getNodeFamilyTree ( $ appName , $ name ) -> parent ; if ( empty ( $ parents ) ) { $ root [ $ appName ] = $ name ; } } } return $ root ; } | This is a list of all the migrations that were the first i . e they don t depend on any other migrations . |
36,589 | public function getState ( $ leaves = null , $ atEnd = true ) { if ( is_null ( $ leaves ) ) { $ leaves = $ this -> getLeafNodes ( ) ; } $ state = ProjectState :: createObject ( ) ; $ state -> fromDisk ( true ) ; if ( empty ( $ leaves ) ) { return $ state ; } $ lineage = [ ] ; foreach ( $ leaves as $ appName => $ appLeaves ) { foreach ( $ appLeaves as $ leaf ) { $ lineage_members = $ this -> getAncestryTree ( $ appName , $ leaf ) ; foreach ( $ lineage_members as $ l_member => $ l_app ) { if ( empty ( $ lineage [ $ l_member ] [ $ l_app ] ) ) { if ( ! $ atEnd && in_array ( $ l_member , $ appLeaves ) ) { continue ; } $ lineage [ $ l_member ] = $ l_app ; } } } } foreach ( $ lineage as $ member => $ lAppName ) { $ migration = $ this -> nodes [ $ lAppName ] [ $ member ] ; $ state = $ migration -> updateState ( $ state ) ; } return $ state ; } | Create ProjectState based on migrations on disk . |
36,590 | private function detectCircularDepedency ( $ appName , $ node , $ getDependency ) { $ todo = [ ] ; foreach ( $ this -> nodeFamilyTree as $ app => $ appNodes ) { foreach ( $ appNodes as $ appNode ) { $ todo [ $ appNode -> getNameWithApp ( ) ] = $ getDependency ( $ appNode -> getNameWithApp ( ) ) ; } } Tools :: topologicalSort ( $ todo ) ; } | Find any cyclic dependencies . |
36,591 | protected function _writeData ( $ path , $ data , $ method = 'PUT' ) { $ jsonData = json_encode ( $ data ) ; $ header = array ( 'Content-Type: ' . $ this -> _contentType , 'Content-Length: ' . strlen ( $ jsonData ) ) ; $ this -> _addHeaderAuthentication ( $ header ) ; try { $ ch = $ this -> _getCurlHandler ( $ path , $ method ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ header ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ jsonData ) ; $ return = $ this -> _parseCurlResponse ( curl_exec ( $ ch ) ) ; curl_close ( $ ch ) ; } catch ( \ Exception $ e ) { $ return = null ; } return $ return ; } | Handles data write RESTful calls |
36,592 | protected function _noData ( $ path , $ method = 'GET' ) { try { $ ch = $ this -> _getCurlHandler ( $ path , $ method ) ; $ return = $ this -> _parseCurlResponse ( curl_exec ( $ ch ) ) ; curl_close ( $ ch ) ; } catch ( \ Exception $ e ) { $ return = null ; } return $ return ; } | Handles non - data write RESTful calls |
36,593 | private function _getCurlHandler ( $ path , $ mode ) { $ url = $ this -> _getJsonPath ( $ path ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ this -> _timeout ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ this -> _timeout ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ mode ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; return $ ch ; } | Returns with Initialized CURL Handler |
36,594 | private function _getJsonPath ( $ path ) { $ url = $ this -> _baseURI ; $ path = ltrim ( $ path , '/' ) ; $ auth = ( $ this -> _isAuthInPath ( ) ) ? $ this -> _token : '' ; $ pathConfiguration = ( $ this -> _isPathConfiguration ( ) ) ? $ this -> _pathConfiguration : '/' ; return $ url . $ path . $ pathConfiguration . $ auth ; } | Returns with the normalized JSON absolute path |
36,595 | public function generate ( $ type , $ object , $ absolute = false , array $ extraParams = array ( ) ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( sprintf ( '$object must be an object, but got "%s".' , gettype ( $ object ) ) ) ; } $ metadata = $ this -> metadataFactory -> getMetadataForClass ( get_class ( $ object ) ) ; if ( null === $ metadata ) { throw new \ RuntimeException ( sprintf ( 'There were no object routes defined for class "%s".' , get_class ( $ object ) ) ) ; } if ( ! isset ( $ metadata -> routes [ $ type ] ) ) { throw new \ RuntimeException ( sprintf ( 'The object of class "%s" has no route with type "%s". Available types: %s' , get_class ( $ object ) , $ type , implode ( ', ' , array_keys ( $ metadata -> routes ) ) ) ) ; } $ route = $ metadata -> routes [ $ type ] ; $ params = $ extraParams ; foreach ( $ route [ 'params' ] as $ k => $ path ) { $ params [ $ k ] = $ this -> accessor -> getValue ( $ object , $ path ) ; } return $ this -> router -> generate ( $ route [ 'name' ] , $ params , $ absolute ) ; } | Generates a path for an object . |
36,596 | private function getJobFromRow ( array $ row ) { $ type = $ row [ 'type' ] ; $ job = new $ type ( $ this -> jsonDecode ( $ row [ 'data' ] ) ) ; $ job -> setChannel ( $ row [ 'channel' ] ) ; $ job -> setBatchId ( $ row [ 'batch_id' ] ) ; $ job -> setQueue ( $ this , ( integer ) $ row [ 'id' ] ) ; return $ job ; } | Hydrate a job based on row data . |
36,597 | public function prepareForNextAttempt ( $ job_id , $ previous_attempts , $ delay = 0 ) { $ this -> connection -> execute ( 'UPDATE `' . self :: JOBS_TABLE_NAME . '` SET `available_at` = ?, `reservation_key` = NULL, `reserved_at` = NULL, `attempts` = ? WHERE `id` = ?' , date ( 'Y-m-d H:i:s' , time ( ) + $ delay ) , $ previous_attempts + 1 , $ job_id ) ; } | Increase number of attempts by job ID . |
36,598 | public function logFailedJob ( JobInterface $ job , $ reason ) { if ( mb_strlen ( $ reason ) > 191 ) { $ reason = mb_substr ( $ reason , 0 , 191 ) ; } $ this -> connection -> transact ( function ( ) use ( $ job , $ reason ) { $ this -> connection -> execute ( 'INSERT INTO `' . self :: FAILED_JOBS_TABLE_NAME . '` (`type`, `channel`, `batch_id`, `data`, `failed_at`, `reason`) VALUES (?, ?, ?, ?, ?, ?)' , get_class ( $ job ) , $ job -> getChannel ( ) , $ job -> getBatchId ( ) , json_encode ( $ job -> getData ( ) ) , date ( 'Y-m-d H:i:s' ) , $ reason ) ; $ this -> deleteJob ( $ job ) ; } ) ; } | Log failed job and delete it from the main queue . |
36,599 | public function nextBatchInLine ( $ jobs_to_run , ... $ from_channels ) { if ( ! is_int ( $ jobs_to_run ) ) { if ( ctype_digit ( $ jobs_to_run ) ) { $ jobs_to_run = ( int ) $ jobs_to_run ; } else { throw new InvalidArgumentException ( 'Jobs to run needs to be a number larger than zero' ) ; } } if ( $ jobs_to_run < 1 ) { throw new InvalidArgumentException ( 'Jobs to run needs to be a number larger than zero' ) ; } $ result = [ ] ; foreach ( $ this -> reserveNextJobs ( $ from_channels , $ jobs_to_run ) as $ job_id ) { $ result [ ] = $ this -> getJobById ( $ job_id ) ; } return $ result ; } | Return a batch of jobs that are next in line to be executed . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.