idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
36,700 | protected function getFreshMigrations ( $ source , $ destination ) { $ me = $ this ; return array_filter ( $ this -> getPackageMigrations ( $ source ) , function ( $ file ) use ( $ me , $ destination ) { return ! $ me -> migrationExists ( $ file , $ destination ) ; } ) ; } | Get the fresh migrations for the source . |
36,701 | public function migrationExists ( $ migration , $ destination ) { $ existing = $ this -> getExistingMigrationNames ( $ destination ) ; return in_array ( substr ( basename ( $ migration ) , 18 ) , $ existing ) ; } | Determine if the migration is already published . |
36,702 | public function getExistingMigrationNames ( $ destination ) { if ( isset ( $ this -> existing [ $ destination ] ) ) return $ this -> existing [ $ destination ] ; return $ this -> existing [ $ destination ] = array_map ( function ( $ file ) { return substr ( basename ( $ file ) , 18 ) ; } , $ this -> files -> files ( $ destination ) ) ; } | Get the existing migration names from the destination . |
36,703 | protected function getPackageMigrations ( $ source ) { $ files = array_filter ( $ this -> files -> files ( $ source ) , function ( $ file ) { return ! starts_with ( $ file , '.' ) ; } ) ; sort ( $ files ) ; return $ files ; } | Get the file list from the source directory . |
36,704 | protected function getNewMigrationName ( $ file , $ add ) { return Carbon :: now ( ) -> addSeconds ( $ add ) -> format ( 'Y_m_d_His' ) . substr ( basename ( $ file ) , 17 ) ; } | Get the new migration name . |
36,705 | public function createView ( $ viewType ) { if ( class_exists ( $ viewType ) ) { $ reflectionClass = new \ ReflectionClass ( $ viewType ) ; if ( $ reflectionClass -> implementsInterface ( AjaxViewInterface :: class ) ) { return $ reflectionClass -> newInstance ( ) ; } } throw new AjaxModalsException ( "View type $viewType does not exists." ) ; } | Creates an AjaxView of the given type |
36,706 | public function createModel ( $ model ) { $ schema = new Schema ( ) ; $ tableDef = $ schema -> createTable ( $ model -> getMeta ( ) -> getDbTable ( ) ) ; $ primaryKeyFields = [ ] ; $ unique_fields = [ ] ; $ indexes = [ ] ; foreach ( $ model -> getMeta ( ) -> localFields as $ fname => $ field ) { $ colName = $ field -> getColumnName ( ) ; $ type = $ field -> dbType ( $ this -> connection ) ; if ( empty ( $ type ) ) { continue ; } if ( $ field -> primaryKey ) { $ primaryKeyFields [ ] = $ model -> getMeta ( ) -> primaryKey -> getColumnName ( ) ; } elseif ( $ field -> isUnique ( ) ) { $ unique_fields [ ] = $ colName ; } elseif ( $ field -> dbIndex ) { $ indexes [ ] = $ colName ; } $ tableDef -> addColumn ( $ colName , $ type , $ this -> getDoctrineColumnOptions ( $ field ) ) ; if ( $ field -> isRelation && $ field -> relation && $ field -> dbConstraint ) { $ relField = $ field -> getRelatedField ( ) ; $ tableDef -> addForeignKeyConstraint ( $ relField -> scopeModel -> getMeta ( ) -> getDbTable ( ) , [ $ field -> getColumnName ( ) ] , [ $ relField -> getColumnName ( ) ] ) ; } } $ tableDef -> setPrimaryKey ( $ primaryKeyFields ) ; if ( ! empty ( $ indexes ) ) { $ tableDef -> addIndex ( $ indexes ) ; } if ( ! empty ( $ unique_fields ) ) { $ tableDef -> addUniqueIndex ( $ unique_fields ) ; } $ this -> createTable ( $ tableDef ) ; foreach ( $ model -> getMeta ( ) -> localManyToMany as $ name => $ relationField ) { if ( $ relationField -> manyToMany && $ relationField -> relation -> through -> getMeta ( ) -> autoCreated ) { $ this -> createModel ( $ relationField -> relation -> through ) ; } } } | Creates database table represented by the model . |
36,707 | public function deleteModel ( $ model ) { foreach ( $ model -> getMeta ( ) -> localManyToMany as $ name => $ relationField ) { if ( $ relationField -> relation -> through -> getMeta ( ) -> autoCreated ) { $ this -> deleteModel ( $ relationField -> relation -> through ) ; } } $ this -> dropTable ( $ model -> getMeta ( ) -> getDbTable ( ) ) ; } | Drop database represented by the model . |
36,708 | public function alterDbTable ( $ model , $ oldDbTableName , $ newDbTableName ) { if ( $ oldDbTableName === $ newDbTableName ) { return ; } $ this -> renameTable ( $ oldDbTableName , $ newDbTableName ) ; } | Renames the table a model points to . |
36,709 | public function addField ( $ model , $ field ) { if ( $ field -> manyToMany && $ field -> relation -> through -> getMeta ( ) -> autoCreated ) { $ this -> createModel ( $ field -> relation -> through ) ; return ; } $ type = $ field -> dbType ( $ this -> connection ) ; $ name = $ field -> getColumnName ( ) ; $ fieldOptions = $ this -> getDoctrineColumnOptions ( $ field , true ) ; if ( empty ( $ type ) ) { return ; } $ tableDef = new TableDiff ( $ model -> getMeta ( ) -> getDbTable ( ) ) ; $ tableDef -> addedColumns [ ] = new Column ( $ name , Type :: getType ( $ type ) , $ fieldOptions ) ; if ( $ field -> primaryKey ) { $ tableDef -> addedIndexes [ ] = new Index ( 'primary' , [ $ name ] , true , true ) ; } if ( $ field -> isUnique ( ) && ! $ field -> primaryKey ) { $ tableDef -> addedIndexes [ ] = new Index ( sprintf ( 'uniq_%s_%s' , mt_rand ( 1 , 1000 ) , $ name ) , [ $ name ] , true ) ; } if ( $ field -> dbIndex && ! $ field -> isUnique ( ) && ! $ field -> primaryKey ) { $ tableDef -> addedIndexes [ ] = new Index ( sprintf ( 'idx_%s_%s' , mt_rand ( 1 , 1000 ) , $ name ) , [ $ name ] ) ; } if ( $ this -> effectiveDefault ( $ field ) ) { } if ( $ field -> isRelation && $ field -> relation && $ field -> dbConstraint ) { $ relField = $ field -> getRelatedField ( ) ; $ tableDef -> addedForeignKeys [ ] = new ForeignKeyConstraint ( [ $ field -> getColumnName ( ) ] , $ relField -> scopeModel -> getMeta ( ) -> getDbTable ( ) , [ $ relField -> getColumnName ( ) ] ) ; } $ this -> alterTable ( $ tableDef ) ; } | Creates a field on a model . |
36,710 | public function removeField ( $ model , $ field ) { if ( $ field -> manyToMany && $ field -> relation -> through -> getMeta ( ) -> autoCreated ) { $ this -> deleteModel ( $ field -> relation -> through ) ; return ; } $ type = $ field -> dbType ( $ this -> connection ) ; $ name = $ field -> getColumnName ( ) ; if ( empty ( $ type ) ) { return ; } $ table = $ model -> getMeta ( ) -> getDbTable ( ) ; $ tableDef = new TableDiff ( $ table ) ; if ( $ field -> isRelation && null !== $ field -> relation ) { foreach ( $ this -> constraintName ( $ table , $ name , [ 'foreignKey' => true ] ) as $ fkConstraint ) { $ tableDef -> removedForeignKeys [ ] = $ fkConstraint ; } } if ( $ field -> primaryKey ) { $ newRels = $ field -> scopeModel -> getMeta ( ) -> getReverseRelatedObjects ( ) ; foreach ( $ newRels as $ newRel ) { $ fkConstraints = $ this -> constraintName ( $ newRel -> scopeModel -> getMeta ( ) -> getDbTable ( ) , $ newRel -> getColumnName ( ) , [ 'foreignKey' => true ] ) ; $ relDiff = new TableDiff ( $ newRel -> scopeModel -> getMeta ( ) -> getDbTable ( ) ) ; $ relDiff -> removedForeignKeys = $ fkConstraints ; $ this -> alterTable ( $ relDiff ) ; } } $ tableDef -> removedColumns [ ] = new Column ( $ name , Type :: getType ( $ type ) ) ; $ this -> alterTable ( $ tableDef ) ; } | Removes a field from a model . Usually involves deleting a column but for M2Ms may involve deleting a table . |
36,711 | public function alterField ( Model $ model , Field $ oldField , Field $ newField , $ strict = false ) { $ oldType = $ oldField -> dbType ( $ this -> connection ) ; $ newType = $ newField -> dbType ( $ this -> connection ) ; if ( ( is_null ( $ oldType ) && is_null ( $ oldField -> relation ) ) || ( is_null ( $ newType ) && is_null ( $ newField -> relation ) ) ) { throw new ValueError ( sprintf ( 'Cannot alter field %s into %s - they do not properly define ' . 'db_type (are you using a badly-written custom field?)' , $ newField -> getName ( ) , $ oldField -> getName ( ) ) ) ; } elseif ( is_null ( $ oldType ) && is_null ( $ newType ) && ( null !== $ oldField -> relation -> through && null !== $ newField -> relation -> through && $ oldField -> relation -> through -> getMeta ( ) -> autoCreated && $ newField -> relation -> through -> getMeta ( ) -> autoCreated ) ) { $ this -> alterManyToMany ( $ model , $ oldField , $ newField , $ strict ) ; } elseif ( is_null ( $ oldType ) && is_null ( $ newType ) && ( null !== $ oldField -> relation -> through && null !== $ newField -> relation -> through && ! $ oldField -> relation -> through -> getMeta ( ) -> autoCreated && ! $ newField -> relation -> through -> getMeta ( ) -> autoCreated ) ) { return ; } elseif ( is_null ( $ oldType ) && is_null ( $ newType ) ) { throw new ValueError ( sprintf ( 'Cannot alter field %s into %s - they are not compatible types ' . '(you cannot alter to or from M2M fields, or add or remove through= on M2M fields)' , $ oldField -> getName ( ) , $ newField -> getName ( ) ) ) ; } $ this -> doFieldAlter ( $ model , $ oldField , $ newField , $ strict ) ; } | Allows a field s type uniqueness nullability default column constraints etc . to be modified . |
36,712 | private function alterManyToMany ( Model $ model , Field $ oldField , Field $ newField , $ strict = false ) { if ( $ oldField -> relation -> through -> getMeta ( ) -> getDbTable ( ) != $ newField -> relation -> through -> getMeta ( ) -> getDbTable ( ) ) { $ this -> alterDbTable ( $ oldField -> relation -> through , $ oldField -> relation -> through -> getMeta ( ) -> getDbTable ( ) , $ newField -> relation -> through -> getMeta ( ) -> getDbTable ( ) ) ; } } | Alters M2Ms to repoint their to = endpoints . |
36,713 | public function setStudioSetting ( $ varName , $ value = null ) { $ params = array ( 'method' => 'sp.studio.set_setting' , 'setting_key' => $ varName , 'setting_value' => $ value ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to set a studio setting |
36,714 | public function getEvents ( $ brandId = null ) { $ params = array ( 'method' => 'sp.event.get_list' ) ; if ( strlen ( $ brandId ) > 0 ) { $ params [ 'brand_id' ] = $ brandId ; } return $ this -> _makeApiRequest ( $ params ) ; } | Method to return all the open events for a studio |
36,715 | public function createEvent ( $ eventName , $ brandId = null , $ eventDate = null ) { if ( is_null ( $ eventName ) || $ eventName == '' ) { throw new Exception ( 'The eventName is required to create a new event.' ) ; } $ params = array ( 'method' => 'sp.event.create' , 'event_name' => $ eventName ) ; if ( strlen ( $ brandId ) > 0 ) { $ params [ 'brand_id' ] = $ brandId ; } if ( strlen ( $ eventDate ) > 0 ) { $ params [ 'event_date' ] = $ eventDate ; } return $ this -> _makeApiRequest ( $ params ) ; } | Method to create a new event . |
36,716 | public function deleteEvent ( $ eventId ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to delete an event.' ) ; } $ params = array ( 'method' => 'sp.event.delete' , 'event_id' => $ eventId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to delete an event |
36,717 | public function photoExistsInEvent ( $ eventId , $ photoFileName ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to check if a photo exists.' ) ; } if ( is_null ( $ photoFileName ) || $ photoFileName == '' ) { throw new Exception ( 'The photoFileName is required to check if a photo exists.' ) ; } $ params = array ( 'method' => 'sp.event.photo_exists' , 'event_id' => $ eventId , 'photo_name' => $ photoFileName ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to check to see if a photo already exists within an event |
36,718 | public function setEventAccessLevel ( $ eventId , $ accessLevel , $ password ) { if ( is_null ( $ accessLevel ) || $ accessLevel == '' ) { throw new Exception ( 'The access level is required.' ) ; } $ params = array ( 'method' => 'sp.event.set_access_level' , 'event_id' => $ eventId , 'access_level' => $ accessLevel , 'password' => $ password ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to set the event access level and password |
36,719 | public function getEventPhotos ( $ eventId , $ page = 1 ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to get the list of photos in the event.' ) ; } $ params = array ( 'method' => 'sp.event.get_photos' , 'event_id' => $ eventId , 'page' => $ page ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to get the photos for an event |
36,720 | public function getEventAlbums ( $ eventId ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to check if a photo exists.' ) ; } $ params = array ( 'method' => 'sp.album.get_list' , 'event_id' => $ eventId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to return the albums for an event |
36,721 | public function getAlbumPhotos ( $ albumId , $ page = 1 ) { if ( is_null ( $ albumId ) || $ albumId == '' ) { throw new Exception ( 'The albumId is required to get the list of photos in the album.' ) ; } $ params = array ( 'method' => 'sp.album.get_photos' , 'album_id' => $ albumId , 'page' => $ page ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to get the photos for an album |
36,722 | public function createEventAlbum ( $ eventId , $ albumName , $ password = null , $ parentAlbumId = null ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to create an album.' ) ; } if ( is_null ( $ albumName ) || $ albumName == '' ) { throw new Exception ( 'The albumName is required to create a new album.' ) ; } $ params = array ( 'method' => 'sp.album.create' , 'event_id' => $ eventId , 'album_name' => $ albumName , 'password' => $ password , 'parent_id' => $ parentAlbumId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to create a new album in an event |
36,723 | public function moveEventAlbum ( $ albumId , $ parentAlbumId = null ) { if ( is_null ( $ albumId ) || $ albumId == '' ) { throw new Exception ( 'The albumId is required to move an album.' ) ; } $ params = array ( 'method' => 'sp.album.move' , 'album_id' => $ albumId , 'parent_id' => $ parentAlbumId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to create a move album within an event |
36,724 | public function renameEventAlbum ( $ albumId , $ albumName ) { if ( is_null ( $ albumId ) || $ albumId == '' ) { throw new Exception ( 'The albumId is required to rename an album.' ) ; } if ( is_null ( $ albumName ) || $ albumName == '' ) { throw new Exception ( 'The albumName is required to create a new album.' ) ; } $ params = array ( 'method' => 'sp.album.rename' , 'album_id' => $ albumId , 'album_name' => $ albumName ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to rename an album |
36,725 | public function deleteEventAlbum ( $ albumId ) { if ( is_null ( $ albumId ) || $ albumId == '' ) { throw new Exception ( 'The albumId is required to delete an album.' ) ; } $ params = array ( 'method' => 'sp.album.delete' , 'album_id' => $ albumId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to delete an album |
36,726 | public function uploadPhotoFromPath ( $ eventId , $ filepath , $ albumId = null ) { if ( is_null ( $ eventId ) || $ eventId == '' ) { throw new Exception ( 'The eventId is required to upload a file.' ) ; } if ( is_null ( $ filepath ) || $ filepath == '' ) { throw new Exception ( 'The filepath is required to upload a file.' ) ; } if ( ! file_exists ( $ filepath ) ) { throw new Exception ( 'The filepath does not point to an accessible file.' ) ; } $ params = array ( 'method' => 'sp.photo.upload' , 'event_id' => $ eventId , 'album_id' => $ albumId ) ; $ photos = array ( 'photo' => new CURLFile ( $ filepath ) , ) ; return $ this -> _makeApiRequest ( $ params , $ photos ) ; } | Method to upload a file from a filepath |
36,727 | public function updatePhotoFromPath ( $ photoId , $ filepath ) { if ( is_null ( $ photoId ) || $ photoId == '' ) { throw new Exception ( 'The photoId is required to update a photo.' ) ; } if ( is_null ( $ filepath ) || $ filepath == '' ) { throw new Exception ( 'The filepath is required to upload a file.' ) ; } if ( ! file_exists ( $ filepath ) ) { throw new Exception ( 'The filepath does not point to an accessible file.' ) ; } $ params = array ( 'method' => 'sp.photo.update' , 'photo_id' => $ photoId , ) ; $ photos = array ( 'photo' => new CURLFile ( $ filepath ) , ) ; return $ this -> _makeApiRequest ( $ params , $ photos ) ; } | Method to update a photo from a filepath |
36,728 | public function deletePhoto ( $ photoId ) { if ( is_null ( $ photoId ) || $ photoId == '' ) { throw new Exception ( 'The photoId is required to delete a photo.' ) ; } $ params = array ( 'method' => 'sp.photo.delete' , 'photo_id' => $ photoId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to delete a photo from an event |
36,729 | public function getOrderDetails ( $ orderId ) { if ( is_null ( $ orderId ) || $ orderId == '' ) { throw new Exception ( 'The orderId is required to get the details or an order.' ) ; } $ params = array ( 'method' => 'sp.order.get_details' , 'order_id' => $ orderId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to get the details for an order |
36,730 | public function getMobileApps ( $ brandId = null , $ page = 1 ) { $ params = array ( 'method' => 'sp.mobile_app.get_list' , 'page' => $ page ) ; if ( strlen ( $ brandId ) > 0 ) { $ params [ 'brand_id' ] = $ brandId ; } return $ this -> _makeApiRequest ( $ params ) ; } | Method to return all active mobile apps for a studio or brand . |
36,731 | public function updateContact ( $ contactId , array $ contactData ) { $ params = array_merge ( array ( 'method' => 'sp.contact.create' , 'contact_id' => $ contactId ) , $ contactData ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to update a new contact . |
36,732 | public function deleteContact ( $ contactId ) { if ( is_null ( $ contactId ) || $ contactId == '' ) { throw new Exception ( 'The contactId is required to delete a contact.' ) ; } $ params = array ( 'method' => 'sp.contact.delete' , 'contact_id' => $ contactId ) ; return $ this -> _makeApiRequest ( $ params ) ; } | Method to delete a contact . |
36,733 | public function inject ( Request $ request ) { foreach ( $ this -> cookieModels as $ cookieModel ) { $ cookie = $ this -> getHttpCookie ( $ cookieModel , $ request ) ; $ cookieModel -> load ( $ cookie ) ; } } | Inject HTTP cookies into cookie models . |
36,734 | public function update ( Response $ response ) { $ flatCookies = $ response -> headers -> getCookies ( ) ; $ cookies = [ ] ; $ getCookieId = function ( Cookie $ cookie ) { return $ cookie -> getDomain ( ) . '|' . $ cookie -> getPath ( ) . '|' . $ cookie -> getName ( ) ; } ; foreach ( $ flatCookies as $ cookie ) { $ cookies [ $ getCookieId ( $ cookie ) ] = $ cookie ; } foreach ( $ this -> cookieModels as $ cookieModel ) { $ cookie = $ cookieModel -> toCookie ( ) ; if ( $ cookieModel -> getClear ( ) ) { $ response -> headers -> clearCookie ( $ cookie -> getName ( ) , $ cookie -> getPath ( ) , $ cookie -> getDomain ( ) ) ; } elseif ( ! isset ( $ cookies [ $ getCookieId ( $ cookie ) ] ) && $ cookieModel -> isDirty ( ) ) { $ response -> headers -> setCookie ( $ cookieModel -> toCookie ( ) ) ; } } } | Add modified or removed cookies to the response object . |
36,735 | public function getButton ( $ buttonName ) { if ( isset ( $ this -> buttons [ $ buttonName ] ) ) { return $ this -> buttons [ $ buttonName ] ; } else { throw new AjaxModalsException ( "Button $buttonName does not exists." ) ; } } | Returns a determined button to be able to configure it |
36,736 | private static function slugTheString ( $ str ) { $ text = preg_replace ( '~[^\\pL\d]+~u' , '-' , $ str ) ; $ text = self :: enleve_accents ( $ text ) ; $ text = trim ( $ text , '-' ) ; $ text = iconv ( 'utf-8' , 'us-ascii//TRANSLIT' , $ text ) ; $ text = strtolower ( $ text ) ; return preg_replace ( '~[^-\w]+~' , '' , $ text ) ; } | Fais le sale boulot |
36,737 | public static function parseFilters ( $ filters ) { return array_build ( static :: explodeFilters ( $ filters ) , function ( $ key , $ value ) { return Route :: parseFilter ( $ value ) ; } ) ; } | Parse the given filter string . |
36,738 | protected static function explodeArrayFilters ( array $ filters ) { $ results = array ( ) ; foreach ( $ filters as $ filter ) { $ results = array_merge ( $ results , explode ( '|' , $ filter ) ) ; } return $ results ; } | Flatten out an array of filter declarations . |
36,739 | protected static function parseParameterFilter ( $ filter ) { list ( $ name , $ parameters ) = explode ( ':' , $ filter , 2 ) ; return array ( $ name , explode ( ',' , $ parameters ) ) ; } | Parse a filter with parameters . |
36,740 | public function getMessages ( ) { $ message = [ ] ; foreach ( $ this -> errorList as $ item ) { $ message [ ] = $ item -> getMessage ( ) ; } return $ message ; } | Returns all the messages . |
36,741 | public function getAbsoluteURL ( ) { return Director :: is_relative_url ( $ this -> url ) ? Director :: absoluteURL ( $ this -> url ) : $ this -> url ; } | Answers the absolute URL of the receiver . |
36,742 | public function getURLWithParams ( ) { return ( $ this -> params ? sprintf ( '%s?%s' , $ this -> url , http_build_query ( $ this -> params ) ) : $ this -> url ) ; } | Answers the defined URL with parameters included . |
36,743 | public function getAttributes ( ) { $ attributes = parent :: getAttributes ( ) ; if ( $ this -> options ) { $ attributes [ 'remote-options' ] = Convert :: array2json ( $ this -> options ) ; } if ( $ this -> remoteValidator ) { $ attributes [ 'remote-validator' ] = $ this -> remoteValidator ; } return $ attributes ; } | Answers the validator attributes for the associated form field . |
36,744 | public function registerCard ( string $ customerId , string $ urlReturn = null ) { $ this -> flow -> getLogger ( ) -> debug ( "Registering Card for $customerId, returns to $urlReturn" ) ; return BasicResponse :: make ( $ this -> flow -> send ( 'post' , $ this -> endpoint . '/register' , [ 'customerId' => $ customerId , 'url_return' => $ urlReturn ?? $ this -> flow -> getReturnUrls ( 'card.url_return' ) , ] ) ) ; } | Registers a Credit Card for the Customer |
36,745 | public function getCard ( string $ token ) { $ this -> flow -> getLogger ( ) -> debug ( "Retrieving Card with token $token" ) ; $ resource = $ this -> make ( $ this -> flow -> send ( 'get' , $ this -> endpoint . '/getRegisterStatus' , [ 'token' => $ token ] ) ) ; $ resource -> setExists ( ( int ) $ resource -> status === 1 ) ; return $ resource ; } | Returns the Credit Card Registration Resource Status |
36,746 | public function unregisterCard ( string $ customerId ) { $ this -> flow -> getLogger ( ) -> debug ( "Unregistering Card for $customerId" ) ; return $ this -> make ( $ this -> flow -> send ( 'post' , $ this -> endpoint . '/unRegister' , [ 'customerId' => $ customerId ] ) ) ; } | Unregisters a Credit Card from the Customer |
36,747 | protected function makeCharge ( array $ attributes ) { $ resource = new BasicResource ( $ attributes ) ; $ resource -> setType ( 'charge' ) ; $ resource -> setExists ( in_array ( $ resource -> status , [ 1 , 2 ] ) ) ; return $ resource ; } | Makes a Charge |
36,748 | public function createCharge ( array $ attributes ) { $ this -> flow -> getLogger ( ) -> debug ( 'Charging: ' . json_encode ( $ attributes ) ) ; return $ this -> makeCharge ( $ this -> flow -> send ( 'post' , $ this -> endpoint . '/charge' , $ attributes ) ) ; } | Immediately charges a desired amount into the customer registered Credit Card |
36,749 | public function reverseCharge ( string $ idType , string $ value ) { $ this -> flow -> getLogger ( ) -> debug ( "Reversing Charge: $idType, $value" ) ; return BasicResponse :: make ( $ this -> flow -> send ( 'post' , $ this -> endpoint . '/reverseCharge' , [ $ idType => $ value ] ) ) ; } | Immediately reverses a previously made charge a customer |
36,750 | public function getChargesPage ( string $ customerId , int $ page , array $ options = null ) { $ pagedResponse = $ this -> getPage ( $ page , array_merge ( $ options ?? [ ] , [ 'method' => 'getCharges' , 'customerId' => $ customerId ] ) ) ; $ items = $ pagedResponse -> items ; foreach ( $ items as & $ item ) { $ item = $ this -> makeCharge ( $ item -> toArray ( ) ) ; } $ pagedResponse -> setAttributes ( $ items ) ; return $ pagedResponse ; } | List the charges made to a customer |
36,751 | public function createGateway ( $ name , array $ config = array ( ) ) { if ( ! isset ( $ this -> gateways [ $ name ] ) ) { throw new CException ( sprintf ( 'Failed to create payment gateway "%s".' , $ name ) ) ; } $ config = CMap :: mergeArray ( $ this -> gateways [ $ name ] , $ config ) ; $ gateway = Yii :: createComponent ( $ config ) ; $ gateway -> manager = $ this ; $ gateway -> init ( ) ; return $ gateway ; } | Creates a payment gateway . |
36,752 | public function process ( PaymentTransaction $ transaction ) { if ( ! isset ( $ transaction -> gateway ) ) { throw new CException ( 'Cannot start transaction without a payment gateway.' ) ; } if ( ! isset ( $ transaction -> shippingContactId ) ) { throw new CException ( 'Cannot start transaction without a shipping contact.' ) ; } if ( ! count ( $ transaction -> items ) ) { throw new CException ( 'Cannot start transaction without any items.' ) ; } $ gateway = $ this -> createGateway ( $ transaction -> gateway ) ; try { $ gateway -> prepareTransaction ( $ transaction ) ; $ this -> changeTransactionStatus ( PaymentTransaction :: STATUS_STARTED , $ transaction ) ; $ gateway -> processTransaction ( $ transaction ) ; $ this -> changeTransactionStatus ( PaymentTransaction :: STATUS_PROCESSED , $ transaction ) ; $ gateway -> resolveTransaction ( $ transaction ) ; } catch ( CException $ e ) { $ this -> changeTransactionStatus ( PaymentTransaction :: STATUS_FAILED , $ transaction ) ; throw $ e ; } } | Processes the given transaction . |
36,753 | public function loadTransaction ( $ id ) { $ transaction = CActiveRecord :: model ( $ this -> transactionClass ) -> findByPk ( $ id ) ; if ( $ transaction === null ) { throw new CException ( sprintf ( 'Failed to load payment transaction #%d.' , $ id ) ) ; } return $ transaction ; } | Loads a payment transaction model . |
36,754 | public function resolveContext ( $ name ) { if ( ! isset ( $ this -> _contexts [ $ name ] ) ) { throw new CException ( sprintf ( 'Failed to find payment context "%s".' , $ name ) ) ; } return $ this -> _contexts [ $ name ] ; } | Resolves a payment context by name . |
36,755 | protected function initContexts ( ) { if ( empty ( $ this -> contexts ) ) { throw new CException ( 'PaymentManager.contexts cannot be empty.' ) ; } foreach ( $ this -> contexts as $ name => $ config ) { if ( ! isset ( $ config [ 'class' ] ) ) { $ config [ 'class' ] = 'PaymentContext' ; } if ( ! isset ( $ config [ 'name' ] ) ) { $ config [ 'name' ] = $ name ; } $ context = Yii :: createComponent ( $ config ) ; if ( ! ( $ context instanceof PaymentContext ) ) { throw new CException ( 'Payment context must be an instance of PaymentContext.' ) ; } $ this -> _contexts [ $ name ] = $ context ; } } | Creates the payment context components from the configuration . |
36,756 | public function deleteTranslation ( string $ locale ) { $ model = $ this ; $ this -> forgetAllTranslations ( $ locale ) ; $ this -> save ( ) ; Event :: fire ( new ModelUpdate ( $ model , 'Deleted' , $ locale ) ) ; } | Removes a translations and fires the model delted event for pusher . |
36,757 | public function getPairedDevices ( $ refresh = false ) { if ( $ refresh === false ) { $ device = Discovery :: lookupDevice ( 'ip' , $ this -> ip ) ; if ( isset ( $ device [ 'device' ] ) && is_array ( $ device [ 'device' ] ) ) { return $ device [ 'device' ] ; } } $ service = $ this -> services [ 'BridgeService' ] [ 'serviceType' ] ; $ controlUrl = $ this -> services [ 'BridgeService' ] [ 'controlURL' ] ; $ method = 'GetEndDevices' ; $ arguments = [ 'DevUDN' => $ this -> getUDN ( $ refresh ) , 'ReqListType' => 'PAIRED_LIST' ] ; $ rs = $ this -> client -> request ( $ controlUrl , $ service , $ method , $ arguments ) ; $ rs = $ this -> unwrapResponse ( $ rs ) ; $ rs = WemoClient :: xmlToArray ( $ rs [ 'u:GetEndDevicesResponse' ] [ 'DeviceLists' ] ) ; $ devices = $ rs [ 'DeviceLists' ] [ 'DeviceList' ] [ 'DeviceInfos' ] ; if ( static :: isArrayAssoc ( $ devices ) ) { $ devices = $ rs [ 'DeviceLists' ] [ 'DeviceList' ] [ 'DeviceInfos' ] [ 'DeviceInfo' ] ; } foreach ( $ devices as $ k => $ d ) { $ d [ 'IsGroupAction' ] = 'NO' ; $ devices [ $ k ] = $ d ; } $ groupedDeviceList = [ ] ; $ groupedDevices = $ rs [ 'DeviceLists' ] [ 'DeviceList' ] [ 'GroupInfos' ] ; if ( static :: isArrayAssoc ( $ groupedDevices ) ) { $ groupedDeviceList [ ] = $ rs [ 'DeviceLists' ] [ 'DeviceList' ] [ 'GroupInfos' ] [ 'GroupInfo' ] ; } foreach ( $ groupedDeviceList as $ gd ) { if ( ! empty ( $ gd [ 'GroupID' ] ) && ! empty ( $ gd [ 'GroupName' ] ) && ! empty ( $ gd [ 'GroupCapabilityValues' ] ) ) { $ devices [ ] = [ 'DeviceID' => $ gd [ 'GroupID' ] , 'FriendlyName' => $ gd [ 'GroupName' ] , 'CurrentState' => $ gd [ 'GroupCapabilityValues' ] , 'productName' => $ gd [ 'DeviceInfos' ] [ 'DeviceInfo' ] [ 0 ] [ 'productName' ] , 'IsGroupAction' => 'YES' ] ; if ( isset ( $ gd [ 'DeviceInfos' ] ) && isset ( $ gd [ 'DeviceInfos' ] [ 'DeviceInfo' ] ) ) { foreach ( $ gd [ 'DeviceInfos' ] [ 'DeviceInfo' ] as $ gdi ) { $ gdi [ 'IsGroupAction' ] = 'NO' ; $ devices [ ] = $ gdi ; } } } } return $ devices ; } | Retrieves all paired bridge devices . |
36,758 | public function getDeviceIdByCustomId ( $ id ) { $ devices = $ this -> getPairedDevices ( ) ; foreach ( $ devices as $ device ) { if ( strtolower ( $ device [ 'id' ] ) === strtolower ( $ id ) ) { return $ device [ 'DeviceID' ] ; } } return null ; } | Looks up bridge deviceId by its discovery id . |
36,759 | public function setDeviceStatus ( $ deviceId , $ state = null , $ level = null ) { $ groupAction = 'NO' ; $ devices = $ this -> getPairedDevices ( ) ; foreach ( $ devices as $ d ) { if ( $ deviceId === $ d [ 'DeviceID' ] ) { $ groupAction = $ d [ 'IsGroupAction' ] ; } } if ( intval ( $ level ) > 0 && $ state === 0 ) { $ state = '1' ; } $ capids = [ ] ; $ capval = [ ] ; if ( $ state !== null ) { $ capids [ ] = '10006' ; $ capval [ ] = $ state ; } if ( $ level !== null ) { $ capids [ ] = '10008' ; $ capval [ ] = $ level . ':0' ; } $ capIdsString = implode ( ',' , $ capids ) ; $ capValString = implode ( ',' , $ capval ) ; $ service = $ this -> services [ 'BridgeService' ] [ 'serviceType' ] ; $ controlUrl = $ this -> services [ 'BridgeService' ] [ 'controlURL' ] ; $ method = 'SetDeviceStatus' ; $ arguments = [ 'DeviceStatusList' => '<?xml version="1.0" encoding="utf-8"?><DeviceStatusList><DeviceStatus><IsGroupAction>' . $ groupAction . '</IsGroupAction><DeviceID available="YES">' . $ deviceId . '</DeviceID><CapabilityID>' . $ capIdsString . '</CapabilityID><CapabilityValue>' . $ capValString . '</CapabilityValue><LastEventTimeStamp>0</LastEventTimeStamp></DeviceStatus></DeviceStatusList>' ] ; $ rs = $ this -> client -> request ( $ controlUrl , $ service , $ method , $ arguments ) ; $ rs = $ this -> unwrapResponse ( $ rs ) ; if ( isset ( $ rs [ 's:Fault' ] ) ) { throw new \ Exception ( 'Failed to change bulb state. ' . print_r ( $ rs , true ) ) ; } return true ; } | Sets bridge device status |
36,760 | public function getSendNsca ( string $ connectionString , int $ encryptionCipher = null , string $ encryptionPassword = null ) : SendNsca { $ password = $ encryptionPassword ?? '' ; $ cipher = $ encryptionCipher ?? Ciphers :: ENCRYPT_NONE ; $ key = md5 ( $ connectionString . ':' . $ cipher . ':' . $ password ) ; if ( false === isset ( static :: $ instances [ $ key ] ) ) { static :: $ instances [ $ key ] = new SendNsca ( $ connectionString , $ this -> getEncryptor ( $ cipher , $ password ) ) ; } return static :: $ instances [ $ key ] ; } | Creates SendNsca class |
36,761 | protected function getEncryptor ( int $ cipher , string $ password ) : EncryptorInterface { try { if ( $ cipher === Ciphers :: ENCRYPT_NONE ) { return null ; } if ( $ cipher === Ciphers :: ENCRYPT_XOR ) { return $ this -> getXorEncryptor ( $ cipher , $ password ) ; } $ encryptor = $ this -> getOpenSslEncryptor ( $ cipher , $ password ) ; } catch ( \ Exception $ exc ) { trigger_error ( 'Falling back to legacy encryption, openssl failed: ' . $ exc -> getMessage ( ) , \ E_DEPRECATED ) ; $ encryptor = $ this -> getLegacyEncryptor ( $ cipher , $ password ) ; } return $ encryptor ; } | Tries to figure out correct encryptor for a given cipher |
36,762 | public function getOpenSslEncryptor ( int $ cipher , string $ password ) : OpenSslEncryptor { if ( false === extension_loaded ( 'openssl' ) ) { throw new \ Exception ( 'OpenSSL Extension not available' ) ; } $ encryptor = new OpenSslEncryptor ( $ cipher , $ password ) ; if ( false === $ encryptor -> isEncryptionCipherSupported ( $ cipher ) ) { throw new \ Exception ( 'Trying to use unsupported encryption cipher' ) ; } return $ encryptor ; } | Factorymethod for OpenSSL Encryptor |
36,763 | public function getLegacyEncryptor ( int $ cipher , string $ password ) : LegacyEncryptor { if ( PHP_VERSION_ID >= 702000 ) { throw new \ Exception ( 'Mcrypt extension not available' ) ; } if ( false === extension_loaded ( 'mcrypt' ) ) { throw new \ Exception ( 'Mcrypt extension not loaded' ) ; } return new LegacyEncryptor ( $ cipher , $ password ) ; } | Factory Method for LegacyEncryptor |
36,764 | public function setUp ( ) { if ( $ this -> resource ) { $ this -> stub = 'controller/resource' ; } elseif ( $ this -> scaffold ) { $ this -> stub = 'controller/scaffold' ; $ this -> scaffolder = new ControllerScaffolder ( $ this -> getClass ( ) , $ this -> getPrefix ( ) ) ; } } | Configure some data . |
36,765 | public function getPrefix ( ) { $ paths = explode ( '/' , $ this -> getName ( ) ) ; array_pop ( $ paths ) ; return strtolower ( implode ( '\\' , $ paths ) ) ; } | Get prefix class . |
36,766 | public function getCurrentJob ( ) : ? Job { $ key = $ this -> getCurrentJobId ( ) ; if ( empty ( $ key ) ) { return null ; } return Job :: Store ( ) -> getById ( $ key ) ; } | Get the Job model for this by Id . |
36,767 | public function setCurrentJob ( $ value ) : ScheduledJob { if ( is_scalar ( $ value ) ) { return $ this -> setCurrentJobId ( $ value ) ; } if ( is_object ( $ value ) && $ value instanceof Job ) { return $ this -> setCurrentJobObject ( $ value ) ; } if ( is_array ( $ value ) && ! empty ( $ value [ 'id' ] ) ) { return $ this -> setCurrentJobId ( $ value [ 'id' ] ) ; } throw new \ Exception ( 'Invalid value for CurrentJob.' ) ; } | Set CurrentJob - Accepts an ID an array representing a Job or a Job model . |
36,768 | protected function determineCodeAndVariables ( ) { if ( ! $ this -> code ) { list ( $ this -> code , $ this -> variables ) = unserialize ( $ this -> serialize ( ) ) ; } } | Uses the serialize method directly to lazily fetch the code and variables if needed |
36,769 | public function discovery ( $ params ) { if ( is_string ( $ params ) ) { $ params = array ( 'email' => $ params ) ; } else { $ params = $ this -> _filterParams ( $ params , array ( 'email' ) , array ( 'email' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } } return $ this -> get ( null , 'discovery?source_type=imap&email=' . rawurlencode ( $ params [ 'email' ] ) ) ; } | Attempts to discover IMAP settings for a given email address |
36,770 | public function moveMessage ( $ user , array $ params ) { if ( is_null ( $ user ) || ! is_string ( $ user ) || ( ! strpos ( $ user , '@' ) === false ) ) { throw new InvalidArgumentException ( 'user must be string representing userId' ) ; } $ params = $ this -> _filterParams ( $ params , array ( 'label' , 'folder' , 'message_id' , 'new_folder_id' , 'delimiter' ) , array ( 'label' , 'folder' , 'message_id' , 'new_folder_id' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } $ email_account = $ params [ 'label' ] ; $ folder = $ params [ 'folder' ] ; $ messageId = $ params [ 'message_id' ] ; $ newFolder = $ params [ 'new_folder_id' ] ; unset ( $ params [ 'label' ] ) ; unset ( $ params [ 'folder' ] ) ; unset ( $ params [ 'message_id' ] ) ; return $ this -> put ( $ user , "email_accounts/" . rawurlencode ( $ email_account ) . "/folders/" . rawurlencode ( $ folder ) . "/messages/" . rawurlencode ( $ messageId ) . '?new_folder_id=' . rawurlencode ( $ newFolder ) ) ; } | Move a message to a different folder . |
36,771 | public function getMessageHeaders ( $ user , array $ params ) { if ( is_null ( $ user ) || ! is_string ( $ user ) || ( ! strpos ( $ user , '@' ) === false ) ) { throw new InvalidArgumentException ( 'user must be string representing userId' ) ; } $ params = $ this -> _filterParams ( $ params , array ( 'label' , 'folder' , 'message_id' , 'raw' , 'delimiter' ) , array ( 'label' , 'folder' , 'message_id' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } $ email_account = $ params [ 'label' ] ; $ folder = $ params [ 'folder' ] ; $ messageId = $ params [ 'message_id' ] ; unset ( $ params [ 'label' ] ) ; unset ( $ params [ 'folder' ] ) ; unset ( $ params [ 'message_id' ] ) ; return $ this -> get ( $ user , "email_accounts/" . rawurlencode ( $ email_account ) . "/folders/" . rawurlencode ( $ folder ) . "/messages/" . rawurlencode ( $ messageId ) . "/headers" , $ params ) ; } | Returns the message headers of a message . |
36,772 | public function markRead ( $ user , array $ params ) { if ( is_null ( $ user ) || ! is_string ( $ user ) || ( ! strpos ( $ user , '@' ) === false ) ) { throw new InvalidArgumentException ( 'user must be string representing userId' ) ; } $ params = $ this -> _filterParams ( $ params , array ( 'label' , 'folder' , 'message_id' , 'raw' ) , array ( 'label' , 'folder' , 'message_id' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } $ email_account = $ params [ 'label' ] ; $ folder = $ params [ 'folder' ] ; $ messageId = $ params [ 'message_id' ] ; return $ this -> post ( $ user , "email_accounts/" . rawurlencode ( $ email_account ) . "/folders/" . rawurlencode ( $ folder ) . "/messages/" . rawurlencode ( $ messageId ) . "/read" ) ; } | Marks a message as read |
36,773 | public function markUnread ( $ user , array $ params ) { if ( is_null ( $ user ) || ! is_string ( $ user ) || ( ! strpos ( $ user , '@' ) === false ) ) { throw new InvalidArgumentException ( 'user must be string representing userId' ) ; } $ params = $ this -> _filterParams ( $ params , array ( 'label' , 'folder' , 'message_id' , 'raw' ) , array ( 'label' , 'folder' , 'message_id' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } $ email_account = $ params [ 'label' ] ; $ folder = $ params [ 'folder' ] ; $ messageId = $ params [ 'message_id' ] ; return $ this -> delete ( $ user , "email_accounts/" . rawurlencode ( $ email_account ) . "/folders/" . rawurlencode ( $ folder ) . "/messages/" . rawurlencode ( $ messageId ) . "/read" ) ; } | Marks a message as unread |
36,774 | public function deleteEmailAccount ( $ user , $ params ) { if ( is_null ( $ user ) || ! is_string ( $ user ) || ( ! strpos ( $ user , '@' ) === false ) ) { throw new InvalidArgumentException ( 'user must be string representing userId' ) ; } if ( is_string ( $ params ) ) { $ params = array ( 'label' => $ params ) ; } else { $ params = $ this -> _filterParams ( $ params , array ( 'label' ) , array ( 'label' ) ) ; if ( $ params === false ) { throw new InvalidArgumentException ( "params array contains invalid parameters or misses required parameters" ) ; } } return $ this -> delete ( $ user , 'email_accounts/' . $ params [ 'label' ] ) ; } | Remove the connection to an IMAP account |
36,775 | private function getFieldsDefinitions ( $ fields ) { $ fieldDefs = [ ] ; foreach ( $ fields as $ name => $ field ) { $ def = $ this -> deepDeconstruct ( $ field ) ; if ( null !== $ field -> relation && null !== $ field -> relation -> toModel ) { unset ( $ def [ 'constructorArgs' ] [ 'to' ] ) ; } $ fieldDefs [ ] = $ def ; } return $ fieldDefs ; } | Return a definition of the fields that ignores field names and what related fields actually relate to . |
36,776 | public function suggestName ( $ operations = null , $ id = null ) { $ prefix = $ this -> migrationNamePrefix ; if ( null === $ operations ) { return sprintf ( '%s0001_Initial' , $ prefix ) ; } if ( 1 == count ( $ operations ) ) { $ op = $ operations [ 0 ] ; if ( $ op instanceof CreateModel ) { return sprintf ( '%s%s_%s' , $ prefix , $ id , $ this -> formatName ( $ op -> name , $ op -> getAppLabel ( ) ) ) ; } elseif ( $ op instanceof DeleteModel ) { return sprintf ( '%s%s_Delete_%s' , $ prefix , $ id , $ this -> formatName ( $ op -> name , $ op -> getAppLabel ( ) ) ) ; } elseif ( $ op instanceof AddField ) { return sprintf ( '%s%s_%s_%s' , $ prefix , $ id , $ this -> formatName ( $ op -> modelName , $ op -> getAppLabel ( ) ) , $ this -> formatName ( $ op -> name ) ) ; } elseif ( $ op instanceof RemoveField ) { return sprintf ( '%s%s_Remove_%s_%s' , $ prefix , $ id , $ this -> formatName ( $ op -> modelName , $ op -> getAppLabel ( ) ) , $ this -> formatName ( $ op -> name ) ) ; } } return sprintf ( '%s%s_Auto_%s' , $ prefix , $ id , date ( 'Ymd_hm' ) ) ; } | Try to guess a name for the migration that is to be created . |
36,777 | public function generateRenamedModels ( ) { $ addedModels = array_diff ( $ this -> newModelKeys , $ this -> oldModelKeys ) ; foreach ( $ addedModels as $ addedModel ) { $ modelState = $ this -> toState -> getModelState ( $ addedModel ) ; $ meta = $ this -> newRegistry -> getModel ( $ addedModel ) -> getMeta ( ) ; $ modelDefinitionList = $ this -> getFieldsDefinitions ( $ modelState -> fields ) ; $ removedModels = array_diff ( $ this -> oldModelKeys , $ this -> newModelKeys ) ; foreach ( $ removedModels as $ removedModel ) { $ remModelState = $ this -> fromState -> getModelState ( $ removedModel ) ; $ remModelDefinitionList = $ this -> getFieldsDefinitions ( $ remModelState -> fields ) ; if ( $ remModelDefinitionList == $ modelDefinitionList ) { if ( MigrationQuestion :: hasModelRenamed ( $ this -> asker , $ removedModel , $ addedModel ) ) { $ this -> addOperation ( $ meta -> getAppName ( ) , RenameModel :: createObject ( [ 'oldName' => $ removedModel , 'newName' => $ addedModel , ] ) ) ; $ this -> renamedModels [ $ addedModel ] = $ removedModel ; $ pos = array_search ( $ removedModel , $ this -> oldModelKeys ) ; array_splice ( $ this -> oldModelKeys , $ pos , 1 , [ $ addedModel ] ) ; break ; } } } } } | Finds any renamed models and generates the operations for them and removes the old entry from the model lists . Must be run before other model - level generation . |
36,778 | public function generateCreatedProxies ( ) { $ addedProxies = array_diff ( $ this -> newProxyKeys , $ this -> oldProxyKeys ) ; foreach ( $ addedProxies as $ addedProxy ) { $ meta = $ this -> newRegistry -> getModel ( $ addedProxy ) -> getMeta ( ) ; $ modelState = $ this -> toState -> getModelState ( $ addedProxy ) ; assert ( $ modelState -> getMeta ( ) [ 'proxy' ] ) ; $ opDep = [ [ 'app' => $ meta -> getAppName ( ) , 'target' => $ addedProxy , 'type' => self :: TYPE_MODEL , 'action' => self :: ACTION_DROPPED , ] , ] ; $ this -> addOperation ( $ meta -> getAppName ( ) , CreateModel :: createObject ( [ 'name' => $ modelState -> name , 'fields' => [ ] , 'meta' => $ modelState -> getMeta ( ) , 'extends' => $ modelState -> extends , ] ) , $ opDep ) ; } } | Makes CreateModel statements for proxy models . |
36,779 | public function generateDeletedProxies ( ) { $ droppedProxies = array_diff ( $ this -> oldProxyKeys , $ this -> newProxyKeys ) ; foreach ( $ droppedProxies as $ droppedProxy ) { $ modelState = $ this -> fromState -> getModelState ( $ droppedProxy ) ; $ meta = $ this -> oldRegistry -> getModel ( $ droppedProxy ) -> getMeta ( ) ; $ this -> addOperation ( $ meta -> getAppName ( ) , DeleteModel :: createObject ( [ 'name' => $ modelState -> name , ] ) ) ; } } | Makes DeleteModel statements for proxy models . |
36,780 | public function generateAlteredMeta ( ) { $ managed = array_intersect ( $ this -> oldUnmanagedKeys , $ this -> newModelKeys ) ; $ unmanaged = array_intersect ( $ this -> oldModelKeys , $ this -> newUnmanagedKeys ) ; $ modelsToCheck = array_merge ( $ this -> keptProxyKeys , $ this -> keptUnmanagedKeys , $ managed , $ unmanaged ) ; $ modelsToCheck = array_unique ( $ modelsToCheck ) ; foreach ( $ modelsToCheck as $ modelName ) { $ oldModelName = $ this -> getOldModelName ( $ modelName ) ; $ oldState = $ this -> fromState -> getModelState ( $ oldModelName ) ; $ newState = $ this -> toState -> getModelState ( $ modelName ) ; $ oldMeta = [ ] ; if ( $ oldState -> getMeta ( ) ) { foreach ( $ oldState -> getMeta ( ) as $ name => $ opt ) { if ( AlterModelMeta :: isAlterableOption ( $ name ) ) { $ oldMeta [ $ name ] = $ opt ; } } } $ newMeta = [ ] ; if ( $ newState -> getMeta ( ) ) { foreach ( $ newState -> getMeta ( ) as $ name => $ opt ) { if ( AlterModelMeta :: isAlterableOption ( $ name ) ) { $ newMeta [ $ name ] = $ opt ; } } } if ( $ oldMeta !== $ newMeta ) { $ this -> addOperation ( $ newMeta -> getAppName ( ) , AlterModelMeta :: createObject ( [ 'name' => $ modelName , 'meta' => $ newMeta , ] ) ) ; } } } | Works out if any non - schema - affecting options have changed and makes an operation to represent them in state changes . |
36,781 | public function generateRenamedFields ( ) { foreach ( $ this -> keptModelKeys as $ modelName ) { $ oldModelName = $ this -> getOldModelName ( $ modelName ) ; $ meta = $ this -> newRegistry -> getModel ( $ modelName ) -> getMeta ( ) ; $ oldModelState = $ this -> fromState -> getModelState ( $ oldModelName ) ; $ newModel = $ this -> newRegistry -> getModel ( $ modelName ) ; $ oldFieldKeys = $ this -> oldFieldKeys [ $ modelName ] ; $ newFieldKeys = $ this -> newFieldKeys [ $ modelName ] ; $ addedFields = array_diff ( $ newFieldKeys , $ oldFieldKeys ) ; foreach ( $ addedFields as $ addedField ) { $ field = $ newModel -> getMeta ( ) -> getField ( $ addedField ) ; $ fieldDef = $ this -> deepDeconstruct ( $ field ) ; $ removedFields = array_diff ( $ oldFieldKeys , $ newFieldKeys ) ; foreach ( $ removedFields as $ remField ) { $ oldFieldDef = $ this -> deepDeconstruct ( $ oldModelState -> getFieldByName ( $ remField ) ) ; if ( ! is_null ( $ field -> relation ) && ! is_null ( $ field -> relation -> toModel ) && isset ( $ oldFieldDef [ 'constructorArgs' ] [ 'to' ] ) ) { $ oldRelTo = $ oldFieldDef [ 'constructorArgs' ] [ 'to' ] ; if ( in_array ( $ oldRelTo , $ this -> renamedModels ) ) { $ oldFieldDef [ 'constructorArgs' ] [ 'to' ] = $ this -> getOldModelName ( $ oldRelTo ) ; } } if ( $ fieldDef === $ oldFieldDef ) { if ( MigrationQuestion :: hasFieldRenamed ( $ this -> asker , $ modelName , $ remField , $ addedField , $ field ) ) { $ this -> addOperation ( $ meta -> getAppName ( ) , RenameField :: createObject ( [ 'modelName' => $ modelName , 'oldName' => $ remField , 'newName' => $ addedField , ] ) ) ; $ pos = array_search ( $ remField , $ this -> oldFieldKeys [ $ modelName ] ) ; array_splice ( $ this -> oldFieldKeys [ $ modelName ] , $ pos , 1 , [ $ addedField ] ) ; $ this -> renamedFields [ $ modelName ] [ $ addedField ] = $ remField ; break ; } } } } } } | Works out renamed fields . |
36,782 | public function generateAddedFields ( ) { foreach ( $ this -> keptModelKeys as $ modelName ) { $ oldFieldKeys = $ this -> oldFieldKeys [ $ modelName ] ; $ newFieldKeys = $ this -> newFieldKeys [ $ modelName ] ; $ addedFields = array_diff ( $ newFieldKeys , $ oldFieldKeys ) ; foreach ( $ addedFields as $ addedField ) { $ this -> findAddedFields ( $ modelName , $ addedField ) ; } } } | Fields that have been added . |
36,783 | public function generateRemovedFields ( ) { foreach ( $ this -> keptModelKeys as $ modelName ) { $ oldFieldKeys = $ this -> oldFieldKeys [ $ modelName ] ; $ newFieldKeys = $ this -> newFieldKeys [ $ modelName ] ; $ remFields = array_diff ( $ oldFieldKeys , $ newFieldKeys ) ; foreach ( $ remFields as $ remField ) { $ this -> findRemovedFields ( $ modelName , $ remField ) ; } } } | Fields that have been removed . |
36,784 | public function generateAlteredFields ( ) { foreach ( $ this -> keptModelKeys as $ modelName ) { $ oldFieldKeys = $ this -> oldFieldKeys [ $ modelName ] ; $ newFieldKeys = $ this -> newFieldKeys [ $ modelName ] ; $ keptFieldKeys = array_intersect ( $ oldFieldKeys , $ newFieldKeys ) ; $ oldModelName = $ this -> getOldModelName ( $ modelName ) ; foreach ( $ keptFieldKeys as $ keptField ) { $ oldFieldName = $ this -> getOldFieldName ( $ modelName , $ keptField ) ; $ oldField = $ this -> oldRegistry -> getModel ( $ oldModelName ) -> getMeta ( ) -> getField ( $ oldFieldName ) ; $ meta = $ this -> newRegistry -> getModel ( $ modelName ) -> getMeta ( ) ; $ newField = $ meta -> getField ( $ keptField ) ; $ oldDec = $ this -> deepDeconstruct ( $ oldField ) ; $ newDec = $ this -> deepDeconstruct ( $ newField ) ; if ( $ oldDec !== $ newDec ) { $ bothM2M = ( $ newField instanceof ManyToManyField && $ oldField instanceof ManyToManyField ) ; $ neitherM2M = ( ! $ newField instanceof ManyToManyField && ! $ oldField instanceof ManyToManyField ) ; if ( $ bothM2M || $ neitherM2M ) { $ preserveDefault = true ; if ( $ oldField -> isNull ( ) && ! $ newField -> isNull ( ) && ! $ newField -> hasDefault ( ) && ! $ newField instanceof ManyToManyField ) { $ field = $ newField -> deepClone ( ) ; $ default = MigrationQuestion :: askNotNullAlteration ( $ this -> asker , $ modelName , $ keptField ) ; if ( NOT_PROVIDED !== $ default ) { $ field -> default = $ default ; $ preserveDefault = false ; } } else { $ field = $ newField ; } $ this -> addOperation ( $ meta -> getAppName ( ) , AlterField :: createObject ( [ 'modelName' => $ modelName , 'name' => $ keptField , 'field' => $ field , 'preserveDefault' => $ preserveDefault , ] ) ) ; } else { $ this -> findRemovedFields ( $ modelName , $ keptField ) ; $ this -> findAddedFields ( $ modelName , $ keptField ) ; } } } } } | Fields that have been altered . |
36,785 | private function findAddedFields ( $ modelName , $ fieldName ) { $ meta = $ this -> newRegistry -> getModel ( $ modelName ) -> getMeta ( ) ; $ field = $ meta -> getField ( $ fieldName ) ; $ opDep = [ ] ; $ preserveDefault = true ; if ( null !== $ field -> relation && $ field -> relation -> toModel ) { $ opDep [ ] = [ 'app' => $ field -> relation -> toModel -> getMeta ( ) -> getAppName ( ) , 'target' => $ field -> relation -> toModel -> getMeta ( ) -> getNSModelName ( ) , 'type' => self :: TYPE_MODEL , 'action' => self :: ACTION_CREATED , ] ; $ rel = $ field -> relation ; if ( $ field -> relation -> hasProperty ( 'through' ) && null != $ field -> relation -> through && ! $ field -> relation -> through -> getMeta ( ) -> autoCreated ) { $ opDep [ ] = [ 'app' => $ field -> relation -> through -> getMeta ( ) -> getAppName ( ) , 'target' => $ field -> relation -> through -> getMeta ( ) -> getNSModelName ( ) , 'type' => self :: TYPE_MODEL , 'action' => self :: ACTION_CREATED , ] ; } } if ( ! $ field -> isNull ( ) && ! $ field -> hasDefault ( ) && ! $ field instanceof ManyToManyField ) { $ def = MigrationQuestion :: askNotNullAddition ( $ this -> asker , $ modelName , $ fieldName , $ field ) ; $ field = $ field -> deepClone ( ) ; $ field -> default = $ def ; $ preserveDefault = false ; } $ this -> addOperation ( $ meta -> getAppName ( ) , AddField :: createObject ( [ 'modelName' => $ modelName , 'name' => $ fieldName , 'field' => $ field , 'preserveDefault' => $ preserveDefault , ] ) , $ opDep ) ; } | Does the actual add of the field . |
36,786 | private function topologicalSort ( $ operations , $ dependency ) { $ sorted = $ arranged = [ ] ; $ deps = $ dependency ; while ( $ deps ) { $ noDeps = [ ] ; foreach ( $ deps as $ index => $ dep ) { if ( ! $ dep ) { $ noDeps [ ] = $ index ; } } if ( ! $ noDeps ) { throw new ValueError ( 'Cyclic dependency on topological sort' ) ; } $ arranged = array_merge ( $ arranged , $ noDeps ) ; $ newDeps = [ ] ; foreach ( $ deps as $ index => $ dep ) { if ( ! in_array ( $ index , $ noDeps ) ) { $ parents = array_diff ( $ dep , $ noDeps ) ; $ newDeps [ $ index ] = $ parents ; } } $ deps = $ newDeps ; } foreach ( $ arranged as $ index ) { $ sorted [ ] = $ operations [ $ index ] ; } return $ sorted ; } | sorts the operations in topological order using kahns algorithim . |
36,787 | public function setUser ( $ value ) : Permission { if ( is_scalar ( $ value ) ) { return $ this -> setUserId ( $ value ) ; } if ( is_object ( $ value ) && $ value instanceof User ) { return $ this -> setUserObject ( $ value ) ; } if ( is_array ( $ value ) && ! empty ( $ value [ 'id' ] ) ) { return $ this -> setUserId ( $ value [ 'id' ] ) ; } throw new \ Exception ( 'Invalid value for User.' ) ; } | Set User - Accepts an ID an array representing a User or a User model . |
36,788 | public function stream_seek ( $ aOffset , $ aWhence ) : bool { switch ( $ aWhence ) { case SEEK_SET : $ this -> position = $ aOffset ; $ this -> truncate_after_seek ( ) ; return true ; break ; case SEEK_CUR : $ this -> position += $ aOffset ; $ this -> truncate_after_seek ( ) ; return true ; break ; case SEEK_END : $ this -> position = strlen ( $ this -> string ) + $ aOffset ; $ this -> truncate_after_seek ( ) ; return true ; break ; default : return false ; } } | Seek to new position . |
36,789 | public function stream_truncate ( $ aSize ) : bool { if ( strlen ( $ this -> string ) > $ aSize ) { $ this -> string = substr ( $ this -> string , 0 , $ aSize ) ; } elseif ( strlen ( $ this -> string ) < $ aSize ) { $ this -> string = str_pad ( $ this -> string , $ aSize , "\0" , STR_PAD_RIGHT ) ; } return true ; } | Truncate to given size . |
36,790 | protected function truncate_after_seek ( ) : void { if ( $ this -> position > strlen ( $ this -> string ) ) { $ this -> stream_truncate ( $ this -> position ) ; } } | If we ve seeked past the end of file auto truncate . |
36,791 | public static function isValidLanguageRegex ( string $ language ) { $ match = false ; if ( preg_match ( self :: $ validISOLanguageRegex , $ language ) ) { $ match = true ; } if ( preg_match ( self :: $ validBCP47LanguageRegex , $ language ) ) { $ match = true ; } return $ match ; } | Check if a string is a possible language string . |
36,792 | public static function registerNamespace ( $ namespace , $ path , $ classname = null ) { $ namespace = trim ( $ namespace , '\\' ) ; $ path = rtrim ( $ path , '/\\' ) ; $ loader = function ( $ classname , $ return_filename = false ) use ( $ namespace , $ path ) { if ( class_exists ( $ classname , false ) || interface_exists ( $ classname , false ) ) { return true ; } $ classname = trim ( $ classname , '\\' ) ; if ( $ namespace && stripos ( $ classname , $ namespace ) !== 0 ) { return false ; } else { $ filename = trim ( substr ( $ classname , strlen ( $ namespace ) ) , '\\' ) ; } $ filename = $ path . DIRECTORY_SEPARATOR . str_replace ( '\\' , DIRECTORY_SEPARATOR , $ filename ) . '.php' ; if ( $ return_filename ) { return $ filename ; } else { if ( ! file_exists ( $ filename ) ) { return false ; } require $ filename ; return class_exists ( $ classname , false ) || interface_exists ( $ classname , false ) ; } } ; if ( $ classname === null ) { spl_autoload_register ( $ loader ) ; } else { return $ loader ( $ classname , true ) ; } } | class loader . |
36,793 | public static function shouldReceive ( ) { $ name = static :: getFacadeAccessor ( ) ; if ( static :: isMock ( ) ) { $ mock = static :: $ resolvedInstance [ $ name ] ; } else { $ mock = static :: createFreshMockInstance ( $ name ) ; } return call_user_func_array ( array ( $ mock , 'shouldReceive' ) , func_get_args ( ) ) ; } | Initiate a mock expectation on the facade . |
36,794 | public function getParams ( ) { $ service = $ this -> services [ 'InsightService' ] [ 'serviceType' ] ; $ controlUrl = $ this -> services [ 'InsightService' ] [ 'controlURL' ] ; $ method = 'GetInsightParams' ; $ rs = $ this -> client -> request ( $ controlUrl , $ service , $ method ) ; $ rs = $ this -> unwrapResponse ( $ rs ) ; if ( isset ( $ rs [ 's:Fault' ] ) ) { throw new \ Exception ( 'Failed to get insight params. ' . print_r ( $ rs , true ) ) ; } return $ rs [ 'u:GetInsightParamsResponse' ] [ 'InsightParams' ] ; } | Returns insight params |
36,795 | private function alterModelTable ( $ schemaEditor , $ fromState , $ toState ) { $ toModel = $ toState -> getRegistry ( ) -> getModel ( $ this -> name ) ; if ( $ this -> allowMigrateModel ( $ schemaEditor -> connection , $ toModel ) ) { $ fromModel = $ fromState -> getRegistry ( ) -> getModel ( $ this -> name ) ; $ schemaEditor -> alterDbTable ( $ toModel , $ fromModel -> getMeta ( ) -> getDbTable ( ) , $ toModel -> getMeta ( ) -> getDbTable ( ) ) ; foreach ( $ toModel -> getMeta ( ) -> localManyToMany as $ newName => $ newField ) { foreach ( $ fromModel -> getMeta ( ) -> localManyToMany as $ oldName => $ oldField ) { if ( $ newName === $ oldName ) { $ schemaEditor -> alterDbTable ( $ newField -> relation -> through , $ oldField -> relation -> through -> getMeta ( ) -> getDbTable ( ) , $ newField -> relation -> through -> getMeta ( ) -> getDbTable ( ) ) ; } } } } } | Does the actual alteration of the model table . |
36,796 | protected function registerCallbacks ( ) { if ( ! empty ( $ this -> callbacks ) ) { $ selector = $ this -> getSelector ( ) ; $ view = $ this -> getView ( ) ; foreach ( $ this -> callbacks as $ event => $ callback ) { if ( is_array ( $ callback ) ) { foreach ( $ callback as $ function ) { if ( ! $ function instanceof JsExpression ) { $ function = new JsExpression ( $ function ) ; } $ view -> registerJs ( "jQuery('#$selector').on('$event', $function);" ) ; } } else { if ( ! $ callback instanceof JsExpression ) { $ callback = new JsExpression ( $ callback ) ; } $ view -> registerJs ( "jQuery('#$selector').on('$event', $callback);" ) ; } } } } | Register widget callbacks |
36,797 | public function buildServiceTable ( $ services ) { $ table = new TableHelper ; $ table -> setHeaders ( $ this -> buildTableHeaders ( ) ) ; $ table -> setRows ( $ this -> buildTableRows ( $ services ) ) ; return $ table ; } | Construct an ASCII table to display services . |
36,798 | public function buildTableRows ( $ services ) { $ rows = array ( ) ; foreach ( array_keys ( $ services ) as $ identifier ) { try { $ service = $ this -> resolveService ( $ identifier ) ; $ rows [ ] = array ( $ identifier , $ this -> getServiceDescription ( $ service ) , $ this -> calculateServiceResolutionTime ( $ identifier ) ) ; } catch ( Exception $ e ) { $ rows [ ] = array ( $ identifier , 'Unable to resolve service.' , 'N/A' ) ; } } return $ rows ; } | Build the rows for the services table . |
36,799 | public function calculateServiceResolutionTime ( $ identifier ) { $ before = microtime ( true ) ; $ this -> resolveService ( $ identifier ) ; return number_format ( ( microtime ( true ) - $ before ) * 1000 , 3 ) ; } | Calculate the time to resolve a service in microseconds . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.