idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
36,200 | public function form ( $ instance ) { add_filter ( 'cmb2_override_meta_value' , [ $ this , 'cmb2_override_meta_value' ] , 11 , 4 ) ; $ this -> _instance = wp_parse_args ( ( array ) $ instance , $ this -> getDefaults ( ) ) ; $ cmb2 = $ this -> cmb2 ( ) ; $ cmb2 -> object_id ( $ this -> option_name ) ; $ cmb2 -> show_form ( ) ; remove_filter ( 'cmb2_override_meta_value' , [ $ this , 'cmb2_override_meta_value' ] ) ; } | Back - end widget form with defaults . |
36,201 | public function getPageRange ( $ start , $ end ) { $ pages = array ( ) ; for ( $ page = $ start ; $ page <= $ end ; $ page ++ ) { if ( $ this -> currentPage == $ page ) { $ pages [ ] = $ this -> getActivePageWrapper ( $ page ) ; } else { $ pages [ ] = $ this -> getLink ( $ page ) ; } } return implode ( '' , $ pages ) ; } | Create a range of pagination links . |
36,202 | protected function getPageSlider ( ) { $ window = 6 ; if ( $ this -> currentPage <= $ window ) { $ ending = $ this -> getFinish ( ) ; return $ this -> getPageRange ( 1 , $ window + 2 ) . $ ending ; } elseif ( $ this -> currentPage >= $ this -> lastPage - $ window ) { $ start = $ this -> lastPage - 8 ; $ content = $ this -> getPageRange ( $ start , $ this -> lastPage ) ; return $ this -> getStart ( ) . $ content ; } else { $ content = $ this -> getAdjacentRange ( ) ; return $ this -> getStart ( ) . $ content . $ this -> getFinish ( ) ; } } | Create a pagination slider link window . |
36,203 | public function getFinish ( ) { $ content = $ this -> getPageRange ( $ this -> lastPage - 1 , $ this -> lastPage ) ; return $ this -> getDots ( ) . $ content ; } | Create the ending cap of a pagination slider . |
36,204 | public function getPrevious ( $ text = '«' ) { if ( $ this -> currentPage <= 1 ) { return $ this -> getDisabledTextWrapper ( $ text ) ; } else { $ url = $ this -> paginator -> getUrl ( $ this -> currentPage - 1 ) ; return $ this -> getPageLinkWrapper ( $ url , $ text ) ; } } | Get the previous page pagination element . |
36,205 | public function getLink ( $ page ) { $ url = $ this -> paginator -> getUrl ( $ page ) ; return $ this -> getPageLinkWrapper ( $ url , $ page ) ; } | Create a pagination slider link . |
36,206 | public function process ( ContainerBuilder $ container ) { $ taggedServices = $ container -> findTaggedServiceIds ( 'ongr_cookie.cookie' ) ; $ injectorDefinition = $ container -> getDefinition ( 'ongr_cookie.injector' ) ; foreach ( $ taggedServices as $ id => $ tagAttributes ) { $ injectorDefinition -> addMethodCall ( 'addCookieModel' , [ new Reference ( $ id ) ] ) ; } } | Finds all services tagged with cookie tag and adds them to cookie factory . |
36,207 | public function addQ ( Q $ q ) { $ aliases = [ ] ; foreach ( $ this -> tableJoinsMap as $ key => $ join ) { if ( INNER === $ join -> getJoinType ( ) ) { $ aliases [ ] = $ key ; } } $ clause = $ this -> _addQ ( $ q , $ this -> usedTableAlias ) [ 0 ] ; if ( $ clause ) { $ this -> where -> add ( $ clause , AND_CONNECTOR ) ; } $ this -> changeToInnerjoin ( $ aliases ) ; } | ] ) ; |
36,208 | public function changeToInnerjoin ( $ aliases = [ ] ) { while ( $ aliases ) { $ alias = array_pop ( $ aliases ) ; $ join = $ this -> tableJoinsMap [ $ alias ] ; if ( LOUTER == $ join -> getJoinType ( ) ) { $ this -> tableJoinsMap [ $ alias ] = $ join -> demote ( ) ; $ parent = $ this -> tableJoinsMap [ $ join -> getParentAlias ( ) ] ; if ( INNER == $ parent -> getJoinType ( ) ) { $ aliases [ ] = $ join -> getParentAlias ( ) ; } } } } | Change join type from LOUTER to INNER for all joins in aliases . |
36,209 | public function changeToOuterJoin ( $ aliases ) { while ( $ aliases ) { $ alias = array_pop ( $ aliases ) ; $ join = $ this -> tableJoinsMap [ $ alias ] ; if ( null == $ join -> getJoinType ( ) ) { continue ; } assert ( null !== $ join -> getJoinType ( ) ) ; $ parentAlias = $ join -> getParentAlias ( ) ; $ parentIsOuter = ( $ parentAlias && LOUTER == $ this -> tableJoinsMap [ $ parentAlias ] -> getJoinType ( ) ) ; $ aliasIsOuter = ( LOUTER == $ join -> getJoinType ( ) ) ; if ( ( $ join -> getNullable ( ) || $ parentIsOuter ) && ! $ aliasIsOuter ) { $ this -> tableJoinsMap [ $ alias ] = $ join -> promote ( ) ; foreach ( $ this -> tableJoinsMap as $ key => $ join ) { if ( $ join -> getParentAlias ( ) == $ alias && ! ArrayHelper :: hasKey ( $ aliases , $ key ) ) { $ aliases [ ] = $ key ; } } } } } | Promotes recursively the join type of given aliases and its children to an outer join . If unconditional is False the join is only promoted if it is nullable or the parent join is an outer join . |
36,210 | public function getFieldChoices ( ) { $ fields = [ ] ; foreach ( $ this -> getMeta ( ) -> getFields ( ) as $ field ) { if ( ! $ field -> isRelation ) { continue ; } $ fields [ ] = $ field -> getName ( ) ; } foreach ( $ this -> getMeta ( ) -> getReverseRelatedObjects ( ) as $ reverseRelatedObject ) { if ( $ reverseRelatedObject -> relation -> fromField -> isUnique ( ) ) { $ fields [ ] = $ reverseRelatedObject -> relation -> fromField -> getRelatedQueryName ( ) ; } } return $ fields ; } | Gets all names for the fields in the query model inclusing reverse fields . |
36,211 | public function _getSql ( ) { $ sql = '' ; $ params = [ ] ; try { list ( $ sql , $ params ) = $ this -> getSqlCompiler ( BaseOrm :: getDbConnection ( ) ) -> asSql ( ) ; } catch ( OrmException $ e ) { } $ sql = str_replace ( '?' , '%s' , $ sql ) ; return vsprintf ( $ sql , $ params ) ; } | Makes a the query return the sql to be executed . |
36,212 | private function alterField ( $ schemaEditor , $ fromState , $ toState ) { $ toModel = $ toState -> getRegistry ( ) -> getModel ( $ this -> modelName ) ; if ( $ this -> allowMigrateModel ( $ schemaEditor -> connection , $ toModel ) ) { $ fromModel = $ fromState -> getRegistry ( ) -> getModel ( $ this -> modelName ) ; $ fromField = $ fromModel -> getMeta ( ) -> getField ( $ this -> name ) ; $ toField = $ toModel -> getMeta ( ) -> getField ( $ this -> name ) ; if ( false === $ this -> preserveDefault ) { $ toField -> default = $ this -> field -> default ; } $ schemaEditor -> alterField ( $ fromModel , $ fromField , $ toField ) ; if ( false === $ this -> preserveDefault ) { $ toField -> default = NOT_PROVIDED ; } } } | Does the actual field alteration . |
36,213 | public function reduce ( Operation $ operation , $ inBetween ) { if ( $ operation instanceof DeleteModel && $ this -> name === $ operation -> name && ! $ this -> getMeta ( ) -> proxy ) { return [ ] ; } if ( $ operation instanceof FieldOperation && strtolower ( $ operation -> modelName ) === strtolower ( $ this -> name ) ) { if ( $ operation instanceof AddField ) { if ( $ operation -> field -> relation ) { foreach ( $ inBetween as $ between ) { $ modelName = $ operation -> field -> relation -> toModel -> getMeta ( ) -> getNSModelName ( ) ; if ( $ between -> referencesModel ( $ modelName ) ) { return false ; } if ( $ operation -> field -> relation -> hasProperty ( 'through' ) && $ operation -> field -> relation -> through ) { $ modelName = $ operation -> field -> relation -> through -> getMeta ( ) -> getNSModelName ( ) ; if ( $ between -> referencesModel ( $ modelName ) ) { return false ; } } } } $ fields = $ this -> fields ; $ fields [ $ operation -> field -> getName ( ) ] = $ operation -> field ; $ op = static :: createObject ( [ 'name' => $ this -> name , 'fields' => $ fields , 'meta' => $ this -> getMeta ( ) , 'extends' => $ this -> extends , ] ) ; $ op -> setAppLabel ( $ this -> getAppLabel ( ) ) ; return [ $ op , ] ; } } return parent :: reduce ( $ operation , $ inBetween ) ; } | Return either a list of operations the actual operation should be replaced with or a boolean that indicates whether or not the specified operation can be optimized across . |
36,214 | public function toSchema ( ) { $ schema = [ ] ; foreach ( $ this -> getColumns ( ) as $ column ) { if ( ! in_array ( $ name = $ column -> getName ( ) , $ this -> except ) ) { $ schema [ ] = $ name . ':' . strtolower ( $ column -> getType ( ) ) ; } } return implode ( ', ' , $ schema ) ; } | Convert table description to migration schema . |
36,215 | public function getOptions ( $ key = null , $ default = null ) { if ( $ key !== null ) { return isset ( $ this -> _options [ $ key ] ) ? $ this -> _options [ $ key ] : $ default ; } else { return $ this -> _options ; } } | Get options for configuring widget |
36,216 | public function getView ( ) { if ( ! $ this -> _view ) { $ defaultViewsDir = $ this -> getDI ( ) -> get ( 'view' ) -> getViewsDir ( ) . '/' . static :: VIEW_DIR_NAME . '/' ; $ this -> _view = new ViewSimple ( ) ; $ this -> _view -> setViewsDir ( $ this -> getOptions ( 'viewsDir' , $ defaultViewsDir ) ) ; } return $ this -> _view ; } | Gets the view service |
36,217 | public function resolve ( $ name ) { if ( ! isset ( $ this -> connections [ $ name ] ) ) { $ this -> connections [ $ name ] = $ this -> makeConnection ( $ name , $ this -> getConfig ( $ name ) ) ; } return $ this -> connections [ $ name ] ; } | Resolve a remote connection instance . |
36,218 | protected function setOutput ( Connection $ connection ) { $ output = php_sapi_name ( ) == 'cli' ? new ConsoleOutput : new NullOutput ; $ connection -> setOutput ( $ output ) ; } | Set the output implementation on the connection . |
36,219 | protected function getAuth ( array $ config ) { if ( isset ( $ config [ 'key' ] ) && trim ( $ config [ 'key' ] ) != '' ) { return array ( 'key' => $ config [ 'key' ] , 'keyphrase' => $ config [ 'keyphrase' ] ) ; } elseif ( isset ( $ config [ 'keytext' ] ) && trim ( $ config [ 'keytext' ] ) != '' ) { return array ( 'keytext' => $ config [ 'keytext' ] ) ; } elseif ( isset ( $ config [ 'password' ] ) ) { return array ( 'password' => $ config [ 'password' ] ) ; } throw new \ InvalidArgumentException ( 'Password / key is required.' ) ; } | Format the appropriate authentication array payload . |
36,220 | protected function getConfig ( $ name ) { $ config = $ this -> app [ 'config' ] [ 'remote.connections.' . $ name ] ; if ( ! is_null ( $ config ) ) return $ config ; throw new \ InvalidArgumentException ( "Remote connection [$name] not defined." ) ; } | Get the configuration for a remote server . |
36,221 | protected function getForeignAttributesForCreate ( ) { $ foreign = array ( $ this -> getPlainForeignKey ( ) => $ this -> getParentKey ( ) ) ; $ foreign [ last ( explode ( '.' , $ this -> morphType ) ) ] = $ this -> morphClass ; return $ foreign ; } | Get the foreign ID and type for creating a related model . |
36,222 | public function queue ( $ event , $ payload = array ( ) ) { $ me = $ this ; $ this -> listen ( $ event . '_queue' , function ( ) use ( $ me , $ event , $ payload ) { $ me -> fire ( $ event , $ payload ) ; } ) ; } | Register a queued event and payload . |
36,223 | public function asSql ( CompilerInterface $ compiler = null , ConnectionInterface $ connection = null ) { $ connection = $ this -> connection ; $ this -> preSqlSetup ( ) ; $ qb = $ connection -> createQueryBuilder ( ) ; $ qb -> update ( $ this -> query -> tablesAliasList [ 0 ] ) ; $ params = [ ] ; foreach ( $ this -> query -> getValues ( ) as $ valItem ) { $ field = $ valItem [ 0 ] ; $ model = $ valItem [ 1 ] ; $ value = $ valItem [ 2 ] ; $ name = $ field -> getColumnName ( ) ; $ qb -> set ( $ name , '?' ) ; if ( method_exists ( $ value , 'prepareDatabaseSave' ) ) { if ( $ field -> isRelation ) { $ value = $ field -> prepareValueBeforeSave ( $ value -> prepareDatabaseSave ( $ field ) , $ connection ) ; } else { throw new TypeError ( "Tried to update field '%s' with a model instance, '%s'. Use a value compatible with '%s'." , $ field -> getName ( ) , $ value , get_class ( $ field ) ) ; } } else { $ value = $ field -> prepareValueBeforeSave ( $ value , $ connection ) ; } $ params [ ] = $ value ; } list ( $ sql , $ whereParams ) = $ this -> compile ( $ this -> where ) ; $ qb -> where ( $ sql ) ; $ params = array_merge ( $ params , $ whereParams ) ; foreach ( $ params as $ index => $ param ) { $ qb -> setParameter ( $ index , $ param ) ; } return $ qb ; } | if the instance passed to a compiler it can be converted into a valid Sql string . |
36,224 | public function addLogger ( $ name = 'log' , $ type = 'file' , $ options = [ 'log_location' => '/var/log/usf-logger.log' , 'log_level' => 'warn' ] ) { if ( array_key_exists ( $ name , $ this -> logRegistry ) ) { throw new \ Exception ( 'LogHandler named [' . $ name . '] already exists.' ) ; } $ this -> logRegistry [ $ name ] = new UsfLogger ( $ name ) ; $ this -> logRegistry [ $ name ] -> setDefaultLogLevel ( $ this -> defaultLogLevel ) ; $ this -> logRegistry [ $ name ] -> addLogHandler ( $ type , $ options ) ; if ( php_sapi_name ( ) !== 'cli' ) { $ this -> logRegistry [ $ name ] -> addLogProcessor ( 'web' ) ; } } | Add an UsfLogger object to the registry . |
36,225 | public function removeLogger ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> logRegistry ) ) { throw new \ Exception ( 'LogHandler named [' . $ name . '] does not exist' ) ; } unset ( $ this -> logRegistry [ 'name' ] ) ; } | Remove an UsfLogger object from the registry . |
36,226 | public function getLogger ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> logRegistry ) ) { throw new \ Exception ( 'LogHandler named [' . $ name . '] does not exist' ) ; } return $ this -> logRegistry [ 'name' ] ; } | Return an UsfLogger object from the registry . |
36,227 | public function setDefaultHandler ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> logRegistry ) ) { throw new \ Exception ( 'LogHandler named [' . $ name . '] does not exist' ) ; } $ this -> defaultLogHandler = $ name ; } | Set the default log handler . |
36,228 | public function getAssetPairs ( array $ pairs = null , $ info = 'info' ) { if ( is_array ( $ pairs ) ) $ code = implode ( '' , $ pairs ) ; if ( isset ( $ code ) ) { return $ this -> queryPublic ( 'AssetPairs' , array ( 'pair' => $ code , 'info' => $ info ) ) ; } else { return $ this -> queryPublic ( 'AssetPairs' ) ; } } | Get tradable asset pairs |
36,229 | public function trade ( $ pair , $ type , $ ordertype , $ price = false , $ price2 = false , $ volume ) { return $ this -> addOrder ( $ pair , $ type , $ ordertype , $ price , $ price2 , $ volume ) ; } | Make a trade calls addOrder |
36,230 | private function queryPublic ( $ method , array $ request = array ( ) ) { $ postdata = http_build_query ( $ request , '' , '&' ) ; curl_setopt ( $ this -> curl , CURLOPT_URL , $ this -> url . '/' . $ this -> version . '/public/' . $ method ) ; curl_setopt ( $ this -> curl , CURLOPT_POSTFIELDS , $ postdata ) ; curl_setopt ( $ this -> curl , CURLOPT_HTTPHEADER , array ( ) ) ; $ result = curl_exec ( $ this -> curl ) ; if ( $ result === false ) throw new \ Exception ( 'CURL error: ' . curl_error ( $ this -> curl ) ) ; $ result = json_decode ( $ result , true ) ; if ( ! is_array ( $ result ) ) throw new \ Exception ( 'JSON decode error' ) ; return $ result ; } | Query public methods |
36,231 | function queryPrivate ( $ method , array $ request = array ( ) ) { if ( ! isset ( $ request [ 'nonce' ] ) ) { $ nonce = explode ( ' ' , microtime ( ) ) ; $ request [ 'nonce' ] = $ nonce [ 1 ] . str_pad ( substr ( $ nonce [ 0 ] , 2 , 6 ) , 6 , '0' ) ; } $ postdata = http_build_query ( $ request , '' , '&' ) ; $ path = '/' . $ this -> version . '/private/' . $ method ; $ sign = hash_hmac ( 'sha512' , $ path . hash ( 'sha256' , $ request [ 'nonce' ] . $ postdata , true ) , base64_decode ( $ this -> secret ) , true ) ; $ headers = array ( 'API-Key: ' . $ this -> key , 'API-Sign: ' . base64_encode ( $ sign ) ) ; curl_setopt ( $ this -> curl , CURLOPT_URL , $ this -> url . $ path ) ; curl_setopt ( $ this -> curl , CURLOPT_POSTFIELDS , $ postdata ) ; curl_setopt ( $ this -> curl , CURLOPT_HTTPHEADER , $ headers ) ; $ result = curl_exec ( $ this -> curl ) ; if ( $ result === false ) throw new \ Exception ( 'CURL error: ' . curl_error ( $ this -> curl ) ) ; $ result = json_decode ( $ result , true ) ; if ( ! is_array ( $ result ) ) throw new \ Exception ( 'JSON decode error' ) ; return $ result ; } | Query private methods |
36,232 | protected static function firstByAttributes ( $ attributes ) { $ query = static :: query ( ) ; foreach ( $ attributes as $ key => $ value ) { $ query -> where ( $ key , $ value ) ; } return $ query -> first ( ) ? : null ; } | Get the first model for the given attributes . |
36,233 | public function validatePhpVersionComposerJson ( $ composerJson ) { if ( ! isset ( $ composerJson [ 'require' ] [ 'php' ] ) ) { $ this -> output -> writeln ( '<info>No PHP version mentioned in composer.json!</info>' ) ; return true ; } $ versionParser = new VersionParser ( ) ; try { $ versionParser -> parseConstraints ( $ composerJson [ 'require' ] [ 'php' ] ) ; } catch ( \ Exception $ e ) { $ this -> output -> writeln ( '<error>' . $ e -> getMessage ( ) . '</error>' ) ; return false ; } return true ; } | Ensure a proper PHP version has been set in composer . json . |
36,234 | public function validatePhpVersionTravisYml ( $ travisYml ) { if ( ! isset ( $ travisYml [ 'php' ] ) ) { $ this -> output -> writeln ( '<info>No PHP version mentioned in .travis.yml!</info>' ) ; return true ; } if ( ! is_array ( $ travisYml [ 'php' ] ) ) { $ this -> output -> writeln ( '<error>PHP version mentioned in .travis.yml must be an array!</error>' ) ; return false ; } $ versionParser = new VersionParser ( ) ; foreach ( $ travisYml [ 'php' ] as $ version ) { try { if ( 'nightly' === $ version ) { continue ; } $ versionParser -> parseConstraints ( $ version ) ; } catch ( \ Exception $ e ) { $ this -> output -> writeln ( '<error>' . $ e -> getMessage ( ) . '</error>' ) ; return false ; } } return true ; } | Ensure proper PHP versions have been set in . travis . yml . |
36,235 | public function validateNoUnmaintainedPhpVersionsInTravis ( $ travisYml , $ maintainedVersions ) { if ( empty ( $ travisYml [ 'php' ] ) ) { return true ; } $ failedTravis = array ( ) ; foreach ( $ travisYml [ 'php' ] as $ travisVersion ) { if ( ! in_array ( $ travisVersion , $ maintainedVersions ) ) { $ failedTravis [ ] = $ travisVersion ; } } if ( ! empty ( $ failedTravis ) ) { $ this -> output -> writeln ( sprintf ( '<error>travis.yml specifies PHP version "%s" but only "%s" are actively maintained.</error>' , implode ( ', ' , $ failedTravis ) , implode ( ', ' , $ maintainedVersions ) ) ) ; return false ; } return true ; } | Ensure all the . travis . yml PHP versions are marked as maintained versions . |
36,236 | public function validateNoUnmaintainedPhpVersionsInComposer ( $ composerJson , $ maintainedVersions ) { if ( empty ( $ composerJson [ 'require' ] [ 'php' ] ) ) { return true ; } $ versionParser = new VersionParser ( ) ; $ constraintsComposer = $ versionParser -> parseConstraints ( $ composerJson [ 'require' ] [ 'php' ] ) ; $ versionOk = false ; foreach ( $ maintainedVersions as $ maintainedVersion ) { if ( 'nightly' === $ maintainedVersion ) { continue ; } $ constraintsMaintainedVersion = $ versionParser -> parseConstraints ( $ maintainedVersion . '.9999999.9999999' ) ; if ( $ constraintsComposer -> matches ( $ constraintsMaintainedVersion ) ) { $ versionOk = true ; break ; } } if ( ! $ versionOk ) { $ this -> output -> writeln ( sprintf ( '<error>composer.json specifies PHP version "%s" but only "%s" are actively maintained.</error>' , $ constraintsComposer -> getPrettyString ( ) , implode ( ', ' , $ maintainedVersions ) ) ) ; return false ; } return true ; } | Ensure all the PHP versions in composer . json are marked as maintained versions . |
36,237 | public function validateTravisContainsAllSupportedPhpVersions ( $ composerJson , $ travisYml , $ supportedPhpByTravis ) { $ travisVersions = ! empty ( $ travisYml [ 'php' ] ) ? $ travisYml [ 'php' ] : array ( ) ; $ unsupportedVersions = array_diff ( $ travisVersions , $ supportedPhpByTravis ) ; if ( $ unsupportedVersions ) { $ this -> output -> writeln ( sprintf ( '<error>travis.yml contains a php version which is unavailable at travis-ci: %s</error>' , implode ( ', ' , $ unsupportedVersions ) ) ) ; return false ; } if ( empty ( $ composerJson [ 'require' ] [ 'php' ] ) ) { return true ; } $ versionParser = new VersionParser ( ) ; $ constraintsComposer = $ versionParser -> parseConstraints ( $ composerJson [ 'require' ] [ 'php' ] ) ; $ missingVersions = $ this -> determineMissingVersions ( $ supportedPhpByTravis , $ travisVersions , $ constraintsComposer ) ; if ( ! empty ( $ missingVersions ) ) { $ this -> output -> writeln ( sprintf ( '<error>composer.json version constraint "%s" covers more versions than defined in travis.yml. ' . 'Please add the missing PHP versions "%s" to .travis.yml</error>' , $ constraintsComposer -> getPrettyString ( ) , implode ( ',' , $ missingVersions ) ) ) ; return false ; } return true ; } | Ensure all PHP versions covered by the constraint in composer . json are noted in . travis . yml . |
36,238 | protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> input = $ input ; $ this -> output = $ output ; $ composerJson = $ this -> readComposerJson ( ) ; $ travisYml = $ this -> readTravisYml ( ) ; $ exitCode = 0 ; if ( ! ( $ this -> validatePhpVersionComposerJson ( $ composerJson ) && $ this -> validatePhpVersionTravisYml ( $ travisYml ) ) ) { return false ; } if ( $ this -> input -> hasOption ( 'unmaintained-version-error' ) ) { if ( ! $ this -> validateNoUnmaintainedPhpVersions ( $ composerJson , $ travisYml , explode ( ',' , TravisEnvironmentInformation :: PHP_VERSIONS ) ) ) { $ exitCode = 1 ; } } if ( ! $ this -> validatePhpVersionAgainstTravis ( $ composerJson , $ travisYml ) ) { $ exitCode = 1 ; } if ( ! $ this -> validateTravisContainsAllSupportedPhpVersions ( $ composerJson , $ travisYml , explode ( ',' , TravisEnvironmentInformation :: PHP_VERSIONS ) ) ) { $ exitCode = 1 ; } return $ exitCode ; } | Run the command and perform all tests . |
36,239 | private function determineMissingVersions ( $ supportedPhpByTravis , $ travisVersions , $ constraintsComposer ) { $ versionParser = new VersionParser ( ) ; $ missingVersions = array ( ) ; foreach ( array_diff ( $ supportedPhpByTravis , $ travisVersions ) as $ version ) { if ( 'nightly' === $ version ) { continue ; } $ constraintsTravis = $ versionParser -> parseConstraints ( $ version . '.9999999.9999999' ) ; if ( $ constraintsComposer -> matches ( $ constraintsTravis ) ) { $ missingVersions [ ] = $ version ; } } return $ missingVersions ; } | Determine the list of versions missing in composer . json . |
36,240 | protected function get ( $ method = null ) { if ( is_null ( $ method ) ) return $ this -> getRoutes ( ) ; return array_get ( $ this -> routes , $ method , array ( ) ) ; } | Get all of the routes in the collection . |
36,241 | public function getByName ( $ name ) { return isset ( $ this -> nameList [ $ name ] ) ? $ this -> nameList [ $ name ] : null ; } | Get a route instance by its name . |
36,242 | public function getByAction ( $ action ) { return isset ( $ this -> actionList [ $ action ] ) ? $ this -> actionList [ $ action ] : null ; } | Get a route instance by its controller action . |
36,243 | public function isProduction ( bool $ isProduction = null ) { return $ isProduction === null ? $ this -> isProduction : $ this -> isProduction = $ isProduction ; } | If Flow is using Production Environment |
36,244 | public function getReturnUrls ( string $ key = null ) { return $ key ? $ this -> returnUrls [ $ key ] ?? null : $ this -> returnUrls ; } | Get the Return URLs |
36,245 | public function setReturnUrls ( array $ returnUrls ) { foreach ( $ returnUrls as $ key => $ returnUrl ) { $ this -> returnUrls [ $ key ] = $ this -> parseUrl ( $ returnUrl ) ; } } | Set the Return URLs |
36,246 | public function getWebhookUrls ( string $ key = null ) { return $ key ? $ this -> webhookUrls [ $ key ] ?? null : $ this -> webhookUrls ; } | Get the Webhook URLs |
36,247 | public function setWebhookUrls ( array $ webhookUrls ) { foreach ( $ webhookUrls as $ key => $ webhookUrl ) { $ this -> webhookUrls [ $ key ] = $ this -> parseUrl ( $ webhookUrl ) ; } } | Set the Webhook URLs |
36,248 | protected function parseUrl ( string $ url ) { $ url = trim ( $ url , '/' ) ; if ( filter_var ( $ url , FILTER_VALIDATE_URL ) ) { return preg_match ( '/(\.(?<tld>\w*))$/m' , $ url ) ? $ url . '/' : $ url ; } throw new InvalidUrlException ( $ url ) ; } | Parses a string and appends a Webhook Secret . |
36,249 | public function send ( string $ method , string $ endpoint , array $ parameters = null ) { $ data = $ this -> processor -> prepare ( $ method , $ parameters ) ; switch ( $ method ) { case 'get' : return $ this -> adapter -> get ( $ this -> getEndpoint ( ) . '/' . trim ( $ endpoint , '/' ) . trim ( $ data , '/' ) ) ; case 'post' : return $ this -> adapter -> post ( $ this -> getEndpoint ( ) . '/' . trim ( $ endpoint , '/' ) , $ data ?? [ ] ) ; } } | Processes the data to send and passes it to the adapter |
36,250 | public static function make ( string $ environment , array $ credentials , LoggerInterface $ logger = null ) { $ flow = new static ( $ logger ?? new NullLogger ( ) ) ; $ flow -> setCredentials ( $ credentials ) ; $ flow -> isProduction ( $ environment === 'production' ) ; $ flow -> setAdapter ( new GuzzleAdapter ( $ flow ) ) ; return $ flow ; } | Creates a new Flow instance |
36,251 | protected function getTemplate ( $ template , $ name ) { $ this -> template = $ this -> file -> get ( $ template ) ; if ( $ this -> needsScaffolding ( $ template ) ) { return $ this -> getScaffoldedTemplate ( $ name ) ; } return $ name . PHP_EOL ; } | Fetch the compiled template for a view |
36,252 | protected function getScaffoldedTemplate ( $ name ) { $ model = $ this -> cache -> getModelName ( ) ; $ models = Pluralizer :: plural ( $ model ) ; $ Models = ucwords ( $ models ) ; $ Model = Pluralizer :: singular ( $ Models ) ; if ( $ name === 'create.blade' or $ name === 'edit.blade' ) { $ formElements = $ this -> makeFormElements ( ) ; $ this -> template = str_replace ( '{{formElements}}' , $ formElements , $ this -> template ) ; } foreach ( array ( 'model' , 'models' , 'Models' , 'Model' ) as $ var ) { $ this -> template = str_replace ( '{{' . $ var . '}}' , $ $ var , $ this -> template ) ; } list ( $ headings , $ fields , $ editAndDeleteLinks ) = $ this -> makeTableRows ( $ model ) ; $ this -> template = str_replace ( '{{headings}}' , implode ( PHP_EOL . "\t\t\t\t" , $ headings ) , $ this -> template ) ; $ this -> template = str_replace ( '{{fields}}' , implode ( PHP_EOL . "\t\t\t\t\t" , $ fields ) . PHP_EOL . $ editAndDeleteLinks , $ this -> template ) ; return $ this -> template ; } | Get the scaffolded template for a view |
36,253 | protected function makeTableRows ( $ model ) { $ models = Pluralizer :: plural ( $ model ) ; $ fields = $ this -> cache -> getFields ( ) ; $ headings = array_map ( function ( $ field ) { return '<th>' . ucwords ( $ field ) . '</th>' ; } , array_keys ( $ fields ) ) ; $ fields = array_map ( function ( $ field ) use ( $ model ) { return "<td>{{{ \$$model->$field }}}</td>" ; } , array_keys ( $ fields ) ) ; $ editAndDelete = <<<EOT <td>{{ link_to_route('{$models}.edit', 'Edit', array(\${$model}->id), array('class' => 'btn btn-info')) }}</td> <td> {{ Form::open(array('method' => 'DELETE', 'route' => array('{$models}.destroy', \${$model}->id))) }} {{ Form::submit('Delete', array('class' => 'btn btn-danger')) }} {{ Form::close() }} </td>EOT ; return array ( $ headings , $ fields , $ editAndDelete ) ; } | Create the table rows |
36,254 | public function makeFormElements ( ) { $ formMethods = array ( ) ; foreach ( $ this -> cache -> getFields ( ) as $ name => $ type ) { $ formalName = ucwords ( $ name ) ; switch ( $ type ) { case 'integer' : $ element = "{{ Form::input('number', '$name') }}" ; break ; case 'text' : $ element = "{{ Form::textarea('$name') }}" ; break ; case 'boolean' : $ element = "{{ Form::checkbox('$name') }}" ; break ; default : $ element = "{{ Form::text('$name') }}" ; break ; } $ frag = <<<EOT <li> {{ Form::label('$name', '$formalName:') }} $element </li>EOT ; $ formMethods [ ] = $ frag ; } return implode ( PHP_EOL , $ formMethods ) ; } | Add FlyPHP methods as string for the fields |
36,255 | public function commit ( array $ attributes ) { if ( $ this -> can ( 'commit' ) ) { $ this -> flow -> getLogger ( ) -> debug ( 'Committing Resource: ' . json_encode ( $ attributes ) ) ; return BasicResponse :: make ( $ this -> performCommit ( $ attributes ) ) ; } throw new \ BadMethodCallException ( 'Method ' . __FUNCTION__ . ' does not exist' ) ; } | Commits the transaction into Flow and returns a Response |
36,256 | protected function performCommit ( array $ attributes ) { return $ this -> flow -> send ( 'post' , $ this -> endpoint . '/' . ( $ options [ 'method' ] ?? $ this -> verbsMap [ 'commit' ] ?? 'create' ) , $ attributes ) ; } | Performs the Commit action with the Flow Adapter |
36,257 | public function create ( array $ attributes ) { if ( $ this -> can ( 'create' ) ) { $ this -> flow -> getLogger ( ) -> debug ( 'Creating Resource: ' . json_encode ( $ attributes ) ) ; return $ this -> make ( $ this -> performCreate ( $ attributes ) ) ; } throw new BadMethodCallException ( 'Method ' . __FUNCTION__ . ' does not exist' ) ; } | Creates a Resource |
36,258 | public function get ( string $ id ) { if ( $ this -> can ( 'get' ) ) { $ this -> flow -> getLogger ( ) -> debug ( "Retrieving Resource: $this->id => $id" ) ; return $ this -> make ( $ this -> performGet ( $ this -> id , $ id ) ) ; } throw new \ BadMethodCallException ( 'Method ' . __FUNCTION__ . ' does not exist' ) ; } | Gets the Resource |
36,259 | protected function performGet ( string $ key , string $ id , array $ options = null ) { return $ this -> flow -> send ( 'get' , $ this -> endpoint . '/' . ( $ options [ 'method' ] ?? $ this -> verbsMap [ 'get' ] ?? 'get' ) , [ $ key => $ id ] ) ; } | Performs the retrieval of the resource |
36,260 | public function update ( $ id , array $ attributes ) { if ( $ this -> can ( 'update' ) ) { $ this -> flow -> getLogger ( ) -> debug ( "Updating Resource Id: $this->id => $id" ) ; $ attributes = $ this -> updateableAttributes ? array_intersect_key ( $ attributes , array_flip ( $ this -> updateableAttributes ) ) : $ attributes ; return $ this -> make ( $ this -> performUpdate ( array_merge ( $ attributes , [ $ this -> id => $ id ] ) ) ) ; } throw new \ BadMethodCallException ( 'Method ' . __FUNCTION__ . ' does not exist' ) ; } | Updates a Resource |
36,261 | protected function performUpdate ( array $ attributes , array $ options = null ) { return $ this -> flow -> send ( 'post' , $ this -> endpoint . '/' . ( $ options [ 'method' ] ?? $ this -> verbsMap [ 'update' ] ?? 'edit' ) , $ attributes ) ; } | Performs the Update of the resource |
36,262 | public function delete ( string $ id ) { if ( $ this -> can ( 'delete' ) ) { $ this -> flow -> getLogger ( ) -> debug ( "Deleting Resource: $this->id => $id" ) ; return $ this -> make ( $ this -> performDelete ( $ this -> id , $ id ) ) ; } throw new \ BadMethodCallException ( 'Method ' . __FUNCTION__ . ' does not exist' ) ; } | Deletes a Resource |
36,263 | public static function run ( $ operations ) { while ( true ) { $ results = self :: optimize ( $ operations ) ; if ( $ results == $ operations ) { return $ results ; } $ operations = $ results ; } } | Main optimization entry point . Pass in a list of Operation instances get out a new list of Operation instances . |
36,264 | public static function optimize ( $ operations ) { $ newOperations = [ ] ; foreach ( $ operations as $ outIndex => $ outOperation ) { $ inOperations = array_slice ( $ operations , $ outIndex + 1 ) ; if ( $ inOperations ) { foreach ( $ inOperations as $ inIndex => $ inOperation ) { $ length = $ inIndex ; $ inBetween = array_slice ( $ operations , $ outIndex + 1 , $ length ) ; $ result = $ outOperation -> reduce ( $ inOperation , $ inBetween ) ; if ( $ result ) { $ newOperations = array_merge ( $ newOperations , $ result ) ; $ newOperations = array_merge ( $ newOperations , $ inBetween ) ; $ newOperations = array_merge ( $ newOperations , array_slice ( $ operations , $ outIndex + $ inIndex + 2 ) ) ; return $ newOperations ; } } $ newOperations [ ] = $ outOperation ; } else { $ newOperations [ ] = $ outOperation ; } } return $ newOperations ; } | Inner optimization loop . |
36,265 | public function liftEmbargo ( ) { $ query = $ this -> getEntityManager ( ) -> createQuery ( 'SELECT e.id, e.embargoed FROM ' . $ this -> getEntityName ( ) . ' e WHERE e.status = \'Embargoed\' AND DATE_DIFF(CURRENT_DATE(), e.embargoed) >= 0' ) ; $ embargoed = $ query -> getResult ( ) ; if ( empty ( $ embargoed ) ) { return ; } $ now = new DateTime ( ) ; $ updated = array_filter ( $ embargoed , function ( $ entry ) use ( $ now ) { $ liftEmbargo = $ entry [ 'embargoed' ] instanceof DateTime ? $ entry [ 'embargoed' ] : new DateTime ( $ entry [ 'embargoed' ] ) ; return $ now -> getTimestamp ( ) >= $ liftEmbargo -> getTimestamp ( ) ; } ) ; $ ids = array_map ( function ( $ entry ) { return $ entry [ 'id' ] ; } , $ updated ) ; if ( empty ( $ ids ) ) { return ; } $ query = $ this -> getEntityManager ( ) -> createQuery ( 'UPDATE ' . $ this -> getEntityName ( ) . ' e SET e.status = \'usable\' WHERE e.id IN (' . implode ( ',' , $ ids ) . ')' ) ; $ query -> getResult ( ) ; } | Lift embargo if expired |
36,266 | public function setupClassInfo ( $ fields = [ ] , $ kwargs = [ ] ) { try { $ registry = ArrayHelper :: getValue ( $ kwargs , 'registry' , ArrayHelper :: STRICT ) ; } catch ( KeyError $ e ) { throw new InvalidArgumentException ( 'registry not provided' ) ; } if ( $ registry -> hasModel ( get_class ( $ this ) ) && $ registry -> ready ) { $ this -> loadMeta ( $ registry ) ; } else { $ metaSettings = Tools :: getClassMetaSettings ( $ this ) ; $ metaSettings [ 'registry' ] = $ registry ; if ( $ kwargs ) { if ( ArrayHelper :: hasKey ( $ kwargs , 'meta' ) ) { $ metaSettings = array_merge ( $ kwargs [ 'meta' ] , $ metaSettings ) ; } } $ meta = Meta :: createObject ( $ metaSettings ) ; $ this -> addToClass ( 'meta' , $ meta ) ; list ( $ concreteParentName , $ immediateParent , $ classFields , $ parentLink ) = self :: getHierarchyMeta ( $ this ) ; $ this -> setupFields ( $ fields , $ classFields ) ; if ( $ this -> getMeta ( ) -> proxy ) { $ concreteParentName = Tools :: unifyModelName ( $ concreteParentName ) ; $ concreteParent = $ this -> getMeta ( ) -> getRegistry ( ) -> getRegisteredModel ( $ concreteParentName ) ; $ this -> proxySetup ( $ concreteParent ) ; } else { $ this -> getMeta ( ) -> setConcreteModel ( $ this ) ; if ( $ parentLink ) { $ this -> getMeta ( ) -> setParentLinks ( $ parentLink ) ; } } $ this -> prepare ( ) ; $ meta -> getRegistry ( ) -> registerModel ( $ this ) ; } } | This method is for internal use only and should not be overriden . |
36,267 | public function save ( $ updateFields = null , $ forceInsert = false , $ forceUpdate = false , $ connection = null ) { foreach ( $ this -> getMeta ( ) -> getConcreteFields ( ) as $ name => $ field ) { if ( $ field -> isRelation ) { if ( $ this -> hasProperty ( $ field -> getCacheName ( ) ) && $ this -> { $ field -> getCacheName ( ) } ) { continue ; } $ relObject = $ this -> { $ field -> getName ( ) } ; if ( $ relObject && is_null ( $ relObject -> getMeta ( ) -> primaryKey ) ) { throw new ValueError ( sprintf ( 'save() prohibited to prevent data loss ' . "due to unsaved related object '%s'." , $ field -> getName ( ) ) ) ; } } } if ( $ forceInsert && ( $ forceInsert || $ forceUpdate ) ) { throw new ValueError ( 'Cannot force both insert and updating' . ' in model saving.' ) ; } $ deferedFields = $ this -> getDeferredFields ( ) ; if ( $ updateFields ) { $ modelFields = $ this -> getMeta ( ) -> getNonM2MForwardFields ( ) ; $ fieldsNames = [ ] ; foreach ( $ modelFields as $ name => $ modelField ) { if ( $ modelField -> primaryKey ) { continue ; } $ fieldsNames [ ] = $ modelField -> getName ( ) ; if ( $ modelField -> getName ( ) !== $ modelField -> getAttrName ( ) ) { $ fieldsNames [ ] = $ modelField -> getAttrName ( ) ; } } $ nonModelFields = array_diff ( $ updateFields , $ fieldsNames ) ; if ( $ nonModelFields ) { throw new ValueError ( sprintf ( 'The following fields do not exist in this ' . 'model or are m2m fields: %s' . implode ( ', ' , $ nonModelFields ) ) ) ; } } elseif ( ! $ forceInsert && $ deferedFields ) { $ concreteFields = $ this -> getMeta ( ) -> getConcreteFields ( ) ; $ fieldsNames = [ ] ; foreach ( $ concreteFields as $ name => $ concreteField ) { if ( ! $ concreteField -> primaryKey && ! $ concreteField -> hasProperty ( 'through' ) ) { $ fieldsNames [ ] = $ concreteField -> getName ( ) ; } } $ loadedFields = array_diff ( $ fieldsNames , $ deferedFields ) ; if ( $ loadedFields ) { $ updateFields = $ loadedFields ; } } $ this -> prepareSave ( $ updateFields ) ; } | Saves the current instance . Override this in a subclass if you want to control the saving process . |
36,268 | private function prepareSave ( $ updateFields = null , $ forceInsert = false , $ forceUpdate = false ) { $ model = $ this ; if ( $ model -> getMeta ( ) -> proxy ) { $ model = $ model -> getMeta ( ) -> getConcreteModel ( ) ; } $ meta = $ model -> getMeta ( ) ; if ( ! $ meta -> autoCreated ) { $ this -> dispatchSignal ( 'powerorm.model.pre_save' , $ model ) ; } $ this -> saveParent ( $ model , $ updateFields ) ; $ this -> saveTable ( $ model , $ forceInsert , $ forceUpdate , $ updateFields ) ; if ( ! $ meta -> autoCreated ) { $ this -> dispatchSignal ( 'powerorm.model.post_save' , $ model ) ; } } | Handles the parts of saving which should be done only once per save yet need to be done in raw saves too . This includes some sanity checks and signal sending . |
36,269 | private function saveTable ( $ model , $ forceInsert = false , $ forceUpdate = false , $ updateFields = null ) { $ meta = $ this -> getMeta ( ) ; $ nonPkFields = [ ] ; foreach ( $ meta -> getConcreteFields ( ) as $ name => $ field ) { if ( $ field -> primaryKey ) { continue ; } $ nonPkFields [ $ name ] = $ field ; } $ nonePkUpdateFields = [ ] ; if ( $ updateFields ) { foreach ( $ nonPkFields as $ nonPkField ) { if ( in_array ( $ nonPkField -> getName ( ) , $ updateFields ) ) { $ nonePkUpdateFields [ $ nonPkField -> getName ( ) ] = $ nonPkField ; } elseif ( in_array ( $ nonPkField -> getAttrName ( ) , $ updateFields ) ) { $ nonePkUpdateFields [ $ nonPkField -> getAttrName ( ) ] = $ nonPkField ; } } } else { $ nonePkUpdateFields = $ nonPkFields ; } $ pkValue = $ this -> getPkValue ( $ meta ) ; $ pkSet = ( false === empty ( $ pkValue ) ) ; if ( ! $ pkSet && ( $ forceUpdate || $ forceInsert ) ) { throw new ValueError ( 'Cannot force an update in ' . 'save() with no primary key.' ) ; } $ updated = false ; if ( $ pkSet && ! $ forceInsert ) { $ values = [ ] ; foreach ( $ nonePkUpdateFields as $ nonePkUpdateField ) { $ values [ ] = [ $ nonePkUpdateField , null , $ nonePkUpdateField -> preSave ( $ this , false ) , ] ; } $ updated = $ this -> doUpdate ( $ values , $ pkValue , $ forceUpdate ) ; } if ( false === $ updated ) { $ concreteFields = $ meta -> getConcreteFields ( ) ; $ fields = [ ] ; foreach ( $ concreteFields as $ name => $ concreteField ) { if ( $ concreteField instanceof AutoField ) { continue ; } $ fields [ $ name ] = $ concreteField ; } $ updatePk = ( $ meta -> hasAutoField && ! $ pkSet ) ; $ result = $ this -> doInsert ( $ this , $ fields , $ updatePk ) ; if ( $ updatePk ) { $ this -> { $ meta -> primaryKey -> getAttrName ( ) } = $ result ; } } } | Does the heavy - lifting involved in saving . Updates or inserts the data for a single table . |
36,270 | public function getPkValue ( Meta $ meta = null ) { if ( null === $ meta ) { $ meta = $ this -> getMeta ( ) ; } return $ this -> { $ meta -> primaryKey -> getAttrName ( ) } ; } | Get the value of the model primary key . |
36,271 | private function doInsert ( $ model , $ fields , $ returnId ) { return $ model :: objects ( ) -> _insert ( $ this , $ fields , $ returnId ) ; } | Do an INSERT . If update_pk is defined then this method should return the new pk for the model . |
36,272 | public function prepareDatabaseSave ( RelatedField $ field ) { if ( $ this -> pk ) { throw new ValueError ( 'Unsaved model instance %s ' . 'cannot be used in an ORM query.' , $ this ) ; } $ name = $ field -> relation -> getRelatedField ( ) -> getAttrName ( ) ; return $ this -> { $ name } ; } | Used during save . its usually invoked when saving related fields . |
36,273 | public function getSortedTableNames ( ) { $ tables = [ strtolower ( $ this -> table_one ) , strtolower ( $ this -> table_two ) , ] ; sort ( $ tables ) ; return $ tables ; } | Get sorted table names . |
36,274 | public function getReplacements ( ) { return array_merge ( parent :: getReplacements ( ) , [ 'table_one' => $ this -> table_one , 'table_two' => $ this -> table_two , 'column_one' => $ this -> getColumnOne ( ) , 'column_two' => $ this -> getColumnTwo ( ) , 'table_pivot' => $ this -> getPivotTableName ( ) , 'timestamp' => $ this -> getTimestampReplacement ( ) , ] ) ; } | Get stub replacements . |
36,275 | public static function init ( ) { self :: $ loader = new Twig_Loader_Filesystem ( ) ; $ config = Config :: getInstance ( ) ; foreach ( array_reverse ( $ config -> get ( 'Octo.paths.templates' , [ ] ) ) as $ path ) { self :: $ loader -> addPath ( $ path ) ; } foreach ( array_reverse ( $ config -> get ( 'Octo.paths.admin_templates' , [ ] ) ) as $ path ) { self :: $ loader -> addPath ( $ path , 'admin' ) ; } self :: $ loader -> addPath ( CMS_PATH . 'Database/Templates/' , 'db' ) ; if ( OCTO_CACHE_ENABLED ) { self :: $ cache = OCTO_CACHE_PATH ; } else { self :: $ cache = false ; } self :: $ twig = new Twig_Environment ( self :: $ loader , [ 'charset' => 'UTF-8' , 'cache' => self :: $ cache , 'auto_reload' => true , 'strict_variables' => false , ] ) ; $ functions = [ ] ; Event :: trigger ( 'TemplateInit' , $ functions ) ; foreach ( $ functions as $ name => $ callable ) { self :: addFunction ( $ name , $ callable ) ; } self :: $ initialised = true ; } | Sets up the twig template loader . |
36,276 | protected function getRouteQueryString ( array $ parameters ) { if ( count ( $ parameters ) == 0 ) return '' ; $ query = http_build_query ( $ keyed = $ this -> getStringParameters ( $ parameters ) ) ; if ( count ( $ keyed ) < count ( $ parameters ) ) { $ query .= '&' . implode ( '&' , $ this -> getNumericParameters ( $ parameters ) ) ; } return '?' . trim ( $ query , '&' ) ; } | Get the query string for a given route . |
36,277 | public static function setup ( LoggerInterface $ logger , int $ verbosity = 1 ) : void { self :: $ logger = $ logger ; self :: setVerbosity ( $ verbosity ) ; } | Sets up the logger |
36,278 | public static function warning ( ... $ params ) : void { if ( self :: $ verbosity < 1 ) { return ; } $ msg = self :: processParams ( $ params ) ; if ( isset ( self :: $ logger ) ) { self :: $ logger -> warning ( $ msg ) ; } else { echo $ msg . PHP_EOL ; } } | Logs warning or more critical messages . |
36,279 | private static function processParams ( array $ message ) : string { $ msg_type = count ( $ message ) ; if ( $ msg_type == 1 ) { return ( string ) $ message [ 0 ] ; } else if ( $ msg_type < 1 ) { return "" ; } else { $ params = $ message ; $ message = array_shift ( $ params ) ; return sprintf ( $ message , ... $ params ) ; } } | A helper method to process log parameters . |
36,280 | private static function createPassKey ( $ key ) { ( is_null ( $ key ) || $ key === false ) && $ key = '' ; $ serialize_key = @ serialize ( $ key ) ; if ( ! $ serialize_key ) { throw new \ ErrorException ( sprintf ( 'Could not serialize input key of %s' , gettype ( $ serialize_key ) ) ) ; } $ key = pack ( 'H*' , self :: hashStringContainer ( $ serialize_key ) ) ; return [ $ serialize_key , self :: safeBase64Encode ( str_pad ( $ key , 24 , "\0" , STR_PAD_RIGHT ) ) ] ; } | Create Pass Key |
36,281 | private static function decryptStandard ( $ hash , $ crypt_text , $ method , $ iv ) { if ( substr ( $ iv , 0 , strlen ( $ method ) ) !== $ method ) { return null ; } $ crypt_text = self :: safeBase64Decode ( $ crypt_text ) ; $ enc_arr = str_split ( $ crypt_text ) ; $ add = 0 ; $ div = strlen ( $ crypt_text ) / strlen ( $ hash ) ; $ new_pass = '' ; while ( $ add <= $ div ) { $ new_pass .= $ hash ; $ add ++ ; } $ pass_arr = str_split ( $ new_pass ) ; $ ascii = '' ; foreach ( $ enc_arr as $ key => $ asc ) { $ pass_int = ord ( $ pass_arr [ $ key ] ) ; $ enc_int = ord ( $ asc ) ; $ str_int = $ enc_int - $ pass_int ; $ ascii .= chr ( ( $ str_int - strlen ( $ crypt_text ) ) ) ; } $ unpack = unpack ( 'a*' , trim ( $ ascii ) ) ; if ( empty ( $ unpack ) ) { return null ; } $ unpack = implode ( '' , ( array ) $ unpack ) ; $ iv = substr ( $ iv , strlen ( $ method ) ) ; if ( strlen ( $ hash ) < strlen ( $ unpack ) ) { $ sub_iv = substr ( $ unpack , strlen ( $ hash ) , strlen ( $ iv ) ) ; } else { $ sub_iv = substr ( $ unpack , - strlen ( $ iv ) ) ; } if ( $ sub_iv !== $ iv ) { return null ; } $ crypt_text = substr_replace ( $ unpack , '' , strlen ( $ hash ) , strlen ( $ iv ) ) ; return self :: rotate ( $ crypt_text , - ( strlen ( $ hash ) % 13 ) ) ; } | Decrypt string container crypt text |
36,282 | public static function altEncrypt ( $ value , $ hash = false , $ method = self :: DEFAULT_CHIPPER ) { $ string = @ serialize ( [ $ value ] ) ; if ( ! $ string ) { throw new \ ErrorException ( sprintf ( 'Could not serialize input of %s' , gettype ( $ string ) ) ) ; } $ passKey = self :: createPassKey ( $ hash ) ; $ crypt_arr = self :: cryptStandard ( $ passKey [ 1 ] , $ string , $ method ) ; $ microtime = microtime ( true ) ; $ iv = self :: safeBase64Encode ( $ method . $ crypt_arr [ 2 ] ) ; $ json_value = json_encode ( [ 'micro' => $ microtime , 'method' => $ crypt_arr [ 1 ] , 'iv' => $ iv , 'value' => $ crypt_arr [ 0 ] , ] ) ; $ crypt_text = trim ( self :: safeBase64Encode ( $ json_value . json_encode ( [ sha1 ( $ microtime . $ passKey [ 1 ] . $ iv ) ] ) ) ) ; $ pos = abs ( round ( strlen ( $ passKey [ 0 ] ) / 3 ) ) ; $ separator = self :: safeBase64Encode ( sha1 ( $ passKey [ 1 ] ) . self :: STANDARD_MIDDLE ) ; if ( strlen ( $ crypt_text ) > $ pos ) { return substr_replace ( $ crypt_text , $ separator . $ pos , $ pos , 0 ) ; } else { return substr_replace ( $ crypt_text , $ separator . $ pos , 2 , 0 ) ; } } | Alternative encryption using Pure PHP Libraries |
36,283 | protected function createMessage ( $ body ) { return $ this -> mailer -> compose ( 'nfy/message' , [ 'message' => $ body ] ) -> setSubject ( Yii :: t ( 'app' , 'Notification from {app}' , [ 'app' => Yii :: $ app -> name ] ) ) ; } | Creates an instance of a Message . This method may be overriden in extending classes . |
36,284 | private function getKey ( ) { if ( $ this -> _key === null ) { $ this -> _key = ftok ( __FILE__ , $ this -> id ) ; } return $ this -> _key ; } | Return a number representing the current queue . |
36,285 | public function receive ( $ subscriber_id = null , $ limit = - 1 ) { if ( $ subscriber_id !== null ) { throw new NotSupportedException ( 'Not implemented. System V queues does not support subscriptions.' ) ; } $ flags = $ this -> blocking ? 0 : MSG_IPC_NOWAIT ; $ messages = [ ] ; $ count = 0 ; while ( ( $ limit == - 1 || $ count < $ limit ) && ( msg_receive ( $ this -> getQueue ( ) , 0 , $ msgtype , self :: MSG_MAXSIZE , $ message , true , $ flags , $ errorcode ) ) ) { $ message -> subscriber_id = $ subscriber_id ; $ message -> status = Message :: AVAILABLE ; $ messages [ ] = $ message ; $ count ++ ; } return $ messages ; } | Gets available messages from the queue and removes them from the queue . |
36,286 | public function handle ( ) { $ asset = $ this -> asset -> container ( 'orchestra/foundation::footer' ) ; $ asset -> script ( 'simplemde' , 'packages/orchestra/story/js/simplemde.js' ) ; $ asset -> style ( 'simplemde' , 'packages/orchestra/story/css/simplemde.css' ) ; $ asset -> script ( 'storycms' , 'packages/orchestra/story/js/story.js' , [ 'orchestra' ] ) ; } | Handle event . |
36,287 | public function apply ( ProjectState $ state , SchemaEditor $ schemaEditor ) { foreach ( $ this -> operations as $ operation ) { if ( ! $ operation -> isReducibleToSql ( ) ) { $ schemaEditor -> addSql ( '-- MIGRATION NOW PERFORMS' . ' OPERATION THAT CANNOT BE WRITTEN AS SQL:' ) ; } $ schemaEditor -> addSql ( sprintf ( '<fg=yellow>-- %s</>' , $ operation -> getDescription ( ) ) ) ; if ( $ operation instanceof AddField && $ operation -> field instanceof ManyToManyField && ! $ operation -> field -> auto && $ operation -> field -> relation -> through ) { $ through = $ operation -> field -> relation -> through ; if ( ! is_string ( $ through ) ) { $ through = sprintf ( "%s\%s" , $ operation -> field -> relation -> through -> getMeta ( ) -> getNSModelName ( ) , $ operation -> field -> relation -> through -> getMeta ( ) -> getModelName ( ) ) ; } $ schemaEditor -> addSql ( sprintf ( ' -- an M2M field which use `%s` as join model' , $ through ) ) ; } if ( ! $ operation -> isReducibleToSql ( ) ) { continue ; } $ oldState = $ state -> deepClone ( ) ; $ operation -> setAppLabel ( $ this -> getAppLabel ( ) ) ; $ operation -> updateState ( $ state ) ; $ schemaEditor -> connection -> beginTransaction ( ) ; try { $ operation -> databaseForwards ( $ schemaEditor , $ oldState , $ state ) ; $ schemaEditor -> connection -> commit ( ) ; } catch ( \ Exception $ e ) { $ schemaEditor -> connection -> rollBack ( ) ; throw new CommandError ( $ e -> getMessage ( ) ) ; } } return $ state ; } | Takes a project_state representing all migrations prior to this one and a schema for a live database and applies the migration in a forwards order . |
36,288 | public function unApply ( $ state , $ schemaEditor ) { $ itemsToRun = [ ] ; $ newState = $ state ; foreach ( $ this -> operations as $ operation ) { $ newState = $ newState -> deepClone ( ) ; $ oldState = $ newState -> deepClone ( ) ; $ operation -> updateState ( $ newState ) ; $ operation -> setAppLabel ( $ this -> getAppLabel ( ) ) ; array_unshift ( $ itemsToRun , [ 'operation' => $ operation , 'oldState' => $ oldState , 'newState' => $ newState , ] ) ; } foreach ( $ itemsToRun as $ runItem ) { $ schemaEditor -> connection -> beginTransaction ( ) ; try { $ operation = $ runItem [ 'operation' ] ; if ( ! $ operation -> isReducibleToSql ( ) ) { $ schemaEditor -> addSql ( '-- MIGRATION NOW PERFORMS' . ' OPERATION THAT CANNOT BE WRITTEN AS SQL:' ) ; } $ schemaEditor -> addSql ( sprintf ( '<fg=yellow>-- %s </>' , ucfirst ( $ operation -> getDescription ( ) ) ) ) ; if ( $ operation -> isReducibleToSql ( ) ) { $ operation -> databaseBackwards ( $ schemaEditor , $ runItem [ 'newState' ] , $ runItem [ 'oldState' ] ) ; } $ schemaEditor -> connection -> commit ( ) ; } catch ( \ Exception $ exception ) { $ schemaEditor -> connection -> rollBack ( ) ; throw new CommandError ( $ exception -> getMessage ( ) ) ; } } return $ state ; } | Takes a project_state representing all migrations prior to this one and a schema for a live database and applies the migration in a reverse order . |
36,289 | public function updateState ( $ state , $ preserveState = true ) { $ newState = $ state ; if ( $ preserveState ) { $ newState = $ state -> deepClone ( ) ; } foreach ( $ this -> operations as $ operation ) { $ operation -> setAppLabel ( $ this -> getAppLabel ( ) ) ; $ operation -> updateState ( $ newState ) ; } return $ newState ; } | Takes a ProjectState and returns a new one with the migration s operations applied to it . |
36,290 | public function getLoginUri ( ) { $ params = array ( 'response_type' => 'code' , 'client_id' => $ this -> _getClientId ( ) , 'redirect_uri' => $ this -> _getRedirectUri ( ) , 'scope' => $ this -> _getScope ( ) ) ; return $ this -> _getUri ( $ this -> _authEndPoint , $ params ) ; } | Method to get the login uri |
36,291 | public function make ( $ mode = 0777 ) { if ( ! $ this -> exists ( ) && ! @ mkdir ( $ this -> pathname , $ mode , true ) ) { throw new FileException ( sprintf ( 'Failed to create directory "%s"' , $ this -> pathname ) ) ; } } | Creates the directory |
36,292 | public function delete ( ) { foreach ( $ this as $ file ) { if ( ! $ file -> isDot ( ) ) { $ file -> delete ( ) ; } } if ( ! @ rmdir ( $ this -> pathname ) ) { throw new FileException ( sprintf ( 'Failed to delete directory "%s"' , $ this -> pathname ) ) ; } } | Recursively deletes the directory |
36,293 | private function getIterator ( ) { if ( $ this -> iterator === null ) { $ this -> iterator = new DirectoryIterator ( $ this -> pathname ) ; } return $ this -> iterator ; } | Returns a directory iterator |
36,294 | public function setAllAttributes ( ) { $ methods = get_class_methods ( $ this ) ; $ attributeMethods = array ( ) ; foreach ( $ methods as $ method ) { if ( strpos ( $ method , 'getAttribute' ) !== false && $ method !== 'getAttributes' ) { $ attributeMethods [ ] = $ method ; } } foreach ( $ attributeMethods as $ attributeMethod ) { $ name = strtolower ( str_replace ( 'getAttribute' , '' , $ attributeMethod ) ) ; $ value = $ this -> $ attributeMethod ( ) ; $ this -> _setAttributeProperty ( $ name , $ value ) ; } return $ this ; } | Sets all attributes . Calls all methods that start with getAttribute . |
36,295 | protected function readName ( $ name ) { $ name = trim ( $ name ) ; $ firstName = NULL ; $ lastName = NULL ; preg_match ( '/([^,]+),([^,]+)/' , $ name , $ matches ) ; if ( count ( $ matches ) > 0 ) { $ lastName = trim ( $ matches [ 1 ] ) ; $ firstName = isset ( $ matches [ 2 ] ) ? trim ( $ matches [ 2 ] ) : '' ; } else { preg_match_all ( '/[^\s]+/' , $ name , $ matches ) ; if ( isset ( $ matches [ 0 ] ) ) { $ matches = $ matches [ 0 ] ; } if ( count ( $ matches ) > 1 ) { $ lastName = array_pop ( $ matches ) ; $ firstName = implode ( ' ' , $ matches ) ; } if ( count ( $ matches ) == 1 ) { $ firstName = $ matches [ 0 ] ; } } return array ( 'firstname' => $ firstName , 'lastname' => $ lastName ) ; } | Try to get a first and last name from a name string |
36,296 | public static function getXmlContent ( $ filePath ) { $ useErrors = libxml_use_internal_errors ( true ) ; $ content = simplexml_load_file ( $ filePath ) ; if ( false === $ content ) { $ error = libxml_get_last_error ( ) ; throw new \ Exception ( sprintf ( "%s in %s" , $ error -> message , $ error -> file ) ) ; } libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ useErrors ) ; return $ content ; } | Gets XML file content . |
36,297 | protected static function _timer_get_info ( $ timer , $ time ) { if ( isset ( self :: $ timers [ $ timer ] ) ) { $ timer = self :: $ timers [ $ timer ] ; if ( $ timer [ "value" ] == 0 ) { $ timer [ "value" ] = $ timer [ 'data' ] ; } return $ timer ; } return array ( ) ; } | For this class whenever asked for timer values show recorded data instead of actual time |
36,298 | protected function get ( $ key , $ default = null ) { $ val = dot_access ( $ this -> configuration , $ key ) ; return $ val !== null ? $ val : $ default ; } | Get a config value from the loaded configuration file |
36,299 | public function set ( $ key , $ value , $ priority = 0 ) { $ key = $ this -> getScalarKey ( $ key ) ; $ this -> list [ $ key ] = new \ stdclass ( ) ; $ this -> list [ $ key ] -> value = $ value ; $ this -> list [ $ key ] -> priority = ( int ) $ priority ; $ this -> list [ $ key ] -> sequence = $ this -> lastSequence ++ ; return $ this -> list [ $ key ] ; } | Add new item to map |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.