idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
26,700 | final public function fetchAllByColumn ( $ column , $ value , $ select = '*' ) { $ this -> validateShortcutData ( ) ; return $ this -> db -> select ( $ select ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> queryAll ( ) ; } | Fetches all row data by column s value |
26,701 | final public function fetchByColumn ( $ column , $ value , $ select = '*' ) { $ this -> validateShortcutData ( ) ; return $ this -> db -> select ( $ select ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> query ( ) ; } | Fetches single row a column |
26,702 | final public function deleteByColumn ( $ column , $ value ) { $ this -> validateShortcutData ( ) ; return $ this -> db -> delete ( ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> execute ( ) ; } | Deletes a row by its associated PK |
26,703 | final public function countByColumn ( $ column , $ value , $ field = null ) { $ this -> validateShortcutData ( ) ; $ alias = 'count' ; if ( $ field === null ) { $ field = $ this -> getPk ( ) ; } return ( int ) $ this -> db -> select ( ) -> count ( $ field , $ alias ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> query ( $ alias ) ; } | Counts by provided column s value |
26,704 | final public function incrementColumnByPk ( $ pk , $ column , $ step = 1 , $ table = null ) { return $ this -> db -> increment ( $ this -> getTable ( $ table ) , $ column , $ step ) -> whereEquals ( $ this -> getPk ( ) , $ pk ) -> execute ( ) ; } | Increments column s value by associated PK s value |
26,705 | final public function decrementColumnByPk ( $ pk , $ column , $ step = 1 , $ table = null ) { return $ this -> db -> decrement ( $ this -> getTable ( $ table ) , $ column , $ step ) -> whereEquals ( $ this -> getPk ( ) , $ pk ) -> execute ( ) ; } | Decrements column s value by associated PK s value |
26,706 | final public function dropTables ( array $ tables , $ fkChecks = false ) { if ( $ fkChecks == false ) { $ this -> db -> raw ( 'SET FOREIGN_KEY_CHECKS=0' ) -> execute ( ) ; } foreach ( $ tables as $ table ) { if ( ! $ this -> dropTable ( $ table ) ) { return false ; } } if ( $ fkChecks == false ) { $ this -> db -> raw ( 'SET FOREIGN_KEY_CHECKS=1' ) -> execute ( ) ; } return true ; } | Drop several tables at once |
26,707 | public function dropColumn ( $ column , $ table = null ) { return $ this -> db -> alterTable ( $ this -> getTable ( $ table ) ) -> dropColumn ( $ column ) -> execute ( ) ; } | Drops a column |
26,708 | public function renameColumn ( $ old , $ new , $ table = null ) { return $ this -> db -> alterTable ( $ this -> getTable ( $ table ) ) -> renameColumn ( $ old , $ new ) -> execute ( ) ; } | Renames a column |
26,709 | public function createIndex ( $ name , $ target , $ unique = false , $ table = null ) { return $ this -> db -> createIndex ( $ table , $ name , $ target , $ unique ) -> execute ( ) ; } | Creates an INDEX |
26,710 | public function dropIndex ( $ name , $ table = null ) { return $ this -> db -> dropIndex ( $ table , $ name ) -> execute ( ) ; } | Drops an INDEX |
26,711 | public function addPrimaryKey ( $ name , $ target , $ table = null ) { return $ this -> db -> alterTable ( $ this -> getTable ( $ table ) ) -> addConstraint ( $ name ) -> primaryKey ( $ target ) -> execute ( ) ; } | Adds a primary key |
26,712 | public function dropPrimaryKey ( $ name , $ table = null ) { return $ this -> db -> alterTable ( $ this -> getTable ( $ table ) ) -> dropConstraint ( $ name ) -> execute ( ) ; } | Drops a primary key |
26,713 | public function getMaxId ( ) { $ column = $ this -> getPk ( ) ; return $ this -> db -> select ( $ column ) -> from ( static :: getTableName ( ) ) -> orderBy ( $ column ) -> desc ( ) -> limit ( 1 ) -> query ( $ column ) ; } | Returns maximal id |
26,714 | public static function installRoot ( ) { $ install_root = ProjectX :: getProjectConfig ( ) -> getRoot ( ) ; $ install_root = substr ( $ install_root , 0 , 1 ) != '/' ? "/{$install_root}" : $ install_root ; if ( isset ( $ install_root ) && ! empty ( $ install_root ) ) { return $ install_root ; } return static :: INSTALL_ROOT ; } | Project current install root . |
26,715 | public function getInstallRoot ( $ strip_slash = false ) { $ install_root = static :: installRoot ( ) ; return $ strip_slash === false ? $ install_root : substr ( $ install_root , 1 ) ; } | Get project current install root . |
26,716 | public function onDeployBuild ( $ build_root ) { $ install_root = $ build_root . static :: installRoot ( ) ; if ( ! file_exists ( $ install_root ) ) { $ this -> _mkdir ( $ install_root ) ; } } | React on the deploy build . |
26,717 | public function setupProjectFilesystem ( ) { $ this -> taskFilesystemStack ( ) -> chmod ( ProjectX :: projectRoot ( ) , 0775 ) -> mkdir ( $ this -> getInstallPath ( ) , 0775 ) -> run ( ) ; return $ this ; } | Setup project filesystem . |
26,718 | public function getProjectOptionByKey ( $ key ) { $ options = $ this -> getProjectOptions ( ) ; if ( ! isset ( $ options [ $ key ] ) ) { return false ; } return $ options [ $ key ] ; } | Get project option by key . |
26,719 | public function createSymbolicLinksOnProject ( array $ options ) { $ project_root = ProjectX :: projectRoot ( ) ; $ excludes = isset ( $ options [ 'excludes' ] ) ? $ options [ 'excludes' ] : [ ] ; $ includes = isset ( $ options [ 'includes' ] ) ? $ options [ 'includes' ] : [ ] ; $ target_dir = isset ( $ options [ 'target_dir' ] ) ? $ options [ 'target_dir' ] : null ; $ source_dir = isset ( $ options [ 'source_dir' ] ) ? $ options [ 'source_dir' ] : $ project_root ; $ symlink_command = new SymlinkCommand ( ) ; foreach ( new \ FilesystemIterator ( $ project_root , \ FilesystemIterator :: SKIP_DOTS ) as $ file_info ) { $ filename = $ file_info -> getFilename ( ) ; if ( strpos ( $ filename , '.' ) === 0 || in_array ( $ filename , $ excludes ) ) { continue ; } if ( ! empty ( $ includes ) && ! in_array ( $ filename , $ includes ) ) { continue ; } $ symlink_command -> link ( "{$source_dir}/{$filename}" , "{$target_dir}/{$filename}" ) ; } return $ symlink_command ; } | Create symbolic links on project . |
26,720 | protected function canBuild ( ) { $ rebuild = false ; if ( $ this -> isBuilt ( ) ) { $ rebuild = $ this -> askConfirmQuestion ( 'Project has already been built, do you want to rebuild?' , false ) ; if ( ! $ rebuild ) { return static :: BUILD_ABORT ; } } return ! $ rebuild ? static :: BUILD_FRESH : static :: BUILD_DIRTY ; } | Can project run it s build process . |
26,721 | protected function getProjectOptions ( ) { $ config = ProjectX :: getProjectConfig ( ) ; $ type = $ config -> getType ( ) ; $ options = $ config -> getOptions ( ) ; return isset ( $ options [ $ type ] ) ? $ options [ $ type ] : [ ] ; } | Get project options . |
26,722 | public function render ( ) { if ( $ this -> paginator -> hasPages ( ) ) { $ ulClass = $ this -> getOption ( 'ulClass' , 'pagination' ) ; return $ this -> renderList ( $ ulClass , $ this -> createPaginationItems ( ) ) ; } } | Renders pagination block |
26,723 | private function createPaginationItems ( ) { $ linkClass = $ this -> getOption ( 'linkClass' , 'page-link' ) ; $ itemClass = $ this -> getOption ( 'itemClass' , 'page-item' ) ; $ itemActiveClass = $ this -> getOption ( 'itemActiveClass' , 'page-item active' ) ; $ previousCaption = ' « ' . $ this -> getOption ( 'previousCaption' , '' ) ; $ nextCaption = $ this -> getOption ( 'nextCaption' , '' ) . ' » ' ; $ items = array ( ) ; if ( $ this -> paginator -> hasPreviousPage ( ) ) { $ items [ ] = $ this -> createListItem ( $ itemClass , $ this -> renderLink ( $ previousCaption , $ this -> paginator -> getPreviousPageUrl ( ) , $ linkClass ) ) ; } foreach ( $ this -> paginator -> getPageNumbers ( ) as $ page ) { if ( is_numeric ( $ page ) ) { $ currentClass = $ this -> paginator -> isCurrentPage ( $ page ) ? $ itemActiveClass : $ itemClass ; $ items [ ] = $ this -> createListItem ( $ currentClass , $ this -> renderLink ( $ page , $ this -> paginator -> getUrl ( $ page ) , $ linkClass ) ) ; } else { $ items [ ] = $ this -> createListItem ( $ itemClass , $ this -> renderLink ( $ page , '#' , $ linkClass ) ) ; } } if ( $ this -> paginator -> hasNextPage ( ) ) { $ items [ ] = $ this -> createListItem ( $ itemClass , $ this -> renderLink ( $ nextCaption , $ this -> paginator -> getNextPageUrl ( ) , $ linkClass ) ) ; } return $ items ; } | Create navigation items |
26,724 | public function callback ( $ request ) { if ( $ this -> payment_handler === null ) { return $ this -> redirect ( Controller :: join_links ( Director :: BaseURL ( ) , $ this -> config ( ) -> url_segment , 'complete' , 'error' ) ) ; } return $ this -> payment_handler -> handleRequest ( $ request , $ this -> model ) ; } | This method can be called by a payment gateway to provide automated integration . |
26,725 | public function addColumn ( BlockInterface $ column , $ index = null ) { $ this -> mappingColumns = null ; if ( null !== $ index ) { array_splice ( $ this -> columns , $ index , 0 , $ column ) ; } else { array_push ( $ this -> columns , $ column ) ; } return $ this ; } | Add column . |
26,726 | public function removeColumn ( $ index ) { $ this -> mappingColumns = null ; array_splice ( $ this -> columns , $ index , 1 ) ; return $ this ; } | Remove column . |
26,727 | public function setSortColumns ( array $ columns ) { $ this -> sortColumns = [ ] ; $ this -> mappingSortColumns = [ ] ; foreach ( $ columns as $ i => $ column ) { if ( ! isset ( $ column [ 'name' ] ) ) { throw new InvalidArgumentException ( 'The "name" property of sort column must be present ("sort" property is optional)' ) ; } if ( isset ( $ column [ 'sort' ] ) && 'asc' !== $ column [ 'sort' ] && 'desc' !== $ column [ 'sort' ] ) { throw new InvalidArgumentException ( 'The "sort" property of sort column must have "asc" or "desc" value' ) ; } if ( $ this -> isSorted ( $ column [ 'name' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The "%s" column is already sorted' , $ column [ 'name' ] ) ) ; } $ this -> sortColumns [ ] = $ column ; $ this -> mappingSortColumns [ $ column [ 'name' ] ] = $ i ; } return $ this ; } | Set sort columns . |
26,728 | public function getSortColumn ( $ column ) { $ val = null ; if ( $ this -> isSorted ( $ column ) ) { $ def = $ this -> sortColumns [ $ this -> mappingSortColumns [ $ column ] ] ; if ( isset ( $ def [ 'sort' ] ) ) { $ val = $ def [ 'sort' ] ; } } return $ val ; } | Get sort column . |
26,729 | public function getColumnIndex ( $ name ) { if ( ! \ is_array ( $ this -> mappingColumns ) ) { $ this -> mappingColumns = [ ] ; foreach ( $ this -> getColumns ( ) as $ i => $ column ) { $ this -> mappingColumns [ $ column -> getName ( ) ] = $ i ; } } if ( isset ( $ this -> mappingColumns [ $ name ] ) ) { $ column = $ this -> columns [ $ this -> mappingColumns [ $ name ] ] ; return $ column -> getOption ( 'index' ) ; } throw new InvalidArgumentException ( sprintf ( 'The column name "%s" does not exist' , $ name ) ) ; } | Return the index name of column . |
26,730 | protected function fetchExecutionToken ( ) { try { $ response = $ this -> client -> get ( static :: LOGIN_URL , [ 'headers' => [ 'User-Agent' => 'niantic' ] ] ) ; } catch ( ServerException $ e ) { sleep ( 1 ) ; return $ this -> fetchExecutionToken ( ) ; } if ( $ response -> getStatusCode ( ) !== 200 ) { throw new AuthenticationException ( "Could not retrieve execution token. Got status code " . $ response -> getStatusCode ( ) ) ; } $ jsonData = json_decode ( $ response -> getBody ( ) -> getContents ( ) ) ; if ( ! $ jsonData || ! isset ( $ jsonData -> execution ) ) { throw new AuthenticationException ( "Could not retrieve execution token. Invalid JSON. TrainersClub could be offline or unstable." ) ; } return $ jsonData ; } | Get data we need |
26,731 | public function registerObserverServiceProvider ( ) { if ( ! $ this -> files -> exists ( app_path ( 'Providers/ObserverServiceProvider.php' ) ) ) { $ this -> call ( 'make:provider' , [ 'name' => 'ObserverServiceProvider' , ] ) ; $ this -> info ( 'Please register your ObserverServiceProvider in config/app.php.' ) ; $ this -> info ( 'Do run php artisan config:cache to make sure ObserverServiceProvider is loaded.' ) ; } else { $ this -> info ( app_path ( 'Providers/ObserverServiceProvider.php' ) . ' already exist.' ) ; } } | Register Observer Service Provider . |
26,732 | protected static function addElementToFilteredArray ( $ key , $ value ) { if ( is_null ( self :: $ filteringCallback ) ) { return ( $ value ) ; } if ( is_string ( self :: $ filteringCallback ) && function_exists ( self :: $ filteringCallback ) ) { $ callback = self :: $ filteringCallback ; return $ callback ( $ key , $ value ) ; } return call_user_func ( self :: $ filteringCallback , $ key , $ value ) ; } | Invoke the callback to check if the current element should be added to the resultant filtered array . |
26,733 | protected static function filterStrings ( array & $ subjectArray , $ goDeep = null , $ filterFunction = null ) { $ arrayWalkFunction = self :: getArrayWalkFunction ( $ goDeep ) ; $ arrayWalkFunction ( $ subjectArray , function ( & $ item ) use ( $ filterFunction ) { if ( ! is_string ( $ item ) ) { return ; } if ( is_callable ( $ filterFunction ) ) { $ item = $ filterFunction ( $ item ) ; } $ item = trim ( $ item ) ; } ) ; return $ subjectArray ; } | Filter the strings within the given array . Strings will be trimmed with an optional filter function to process too . |
26,734 | static function init ( ) { self :: $ hover_text = 'This option is set readonly in ' . basename ( __DIR__ ) . '/' . basename ( __FILE__ ) ; if ( is_admin ( ) && ! defined ( 'WP_READONLY_OPTIONS_NO_JS' ) ) { add_action ( 'admin_enqueue_scripts' , [ __CLASS__ , 'set_admin_readonly_js' ] ) ; } } | Setup hooks filters and default options |
26,735 | static function set ( array $ options ) { if ( is_array ( $ options ) ) { foreach ( $ options as $ must_use_option => $ must_use_value ) { add_filter ( "pre_option_{$must_use_option}" , function ( ) use ( $ must_use_value ) { return $ must_use_value ; } ) ; add_filter ( "pre_update_option_{$must_use_option}" , function ( ) use ( $ must_use_value ) { return $ must_use_value ; } ) ; } self :: add_options ( $ options ) ; } } | Forces options from WP_READONLY_OPTIONS array to be predetermined This is useful if some plugin doesn t allow defining options in wp - config . php |
26,736 | public static function fromProto ( ProtoAuthTicket $ ticket ) : self { return new self ( $ ticket -> getStart ( ) -> getContents ( ) , $ ticket -> getEnd ( ) -> getContents ( ) , $ ticket -> getExpireTimestampMs ( ) ) ; } | Create from prototicket |
26,737 | private function prepare ( ) { if ( ! $ this -> storage -> has ( self :: FLASH_KEY ) ) { $ this -> storage -> set ( self :: FLASH_KEY , array ( ) ) ; } } | Prepares a messenger for usage |
26,738 | public function has ( $ key ) { $ flashMessages = $ this -> storage -> get ( self :: FLASH_KEY ) ; return isset ( $ flashMessages [ $ key ] ) ; } | Checks whether message key exists |
26,739 | public function set ( $ key , $ message ) { $ this -> storage -> set ( self :: FLASH_KEY , array ( $ key => $ message ) ) ; return $ this ; } | Sets a message by given key name |
26,740 | public function get ( $ key ) { if ( $ this -> has ( $ key ) ) { $ flashMessages = $ this -> storage -> get ( self :: FLASH_KEY ) ; $ message = $ flashMessages [ $ key ] ; $ this -> remove ( $ key ) ; if ( $ this -> translator instanceof TranslatorInterface ) { $ message = $ this -> translator -> translate ( $ message ) ; } return $ message ; } else { throw new RuntimeException ( sprintf ( 'Attempted to read non-existing key %s' , $ key ) ) ; } } | Returns a message associated with a given key |
26,741 | final protected function buildClassNameByFileName ( $ filename ) { $ className = sprintf ( '%s/%s' , $ this -> getNamespace ( ) , $ filename ) ; $ className = str_replace ( array ( '//' , '/' , '\\' ) , '\\' , $ className ) ; return $ className ; } | Builds a classname according to defined pseudo - namespace |
26,742 | final public function build ( ) { $ arguments = func_get_args ( ) ; $ filename = array_shift ( $ arguments ) ; $ className = $ this -> buildClassNameByFileName ( $ filename ) ; $ ib = new InstanceBuilder ( ) ; return $ ib -> build ( $ className , $ arguments ) ; } | Builds an instance Heavily relies on PSR - 0 autoloader |
26,743 | protected function hasParent ( $ id , array $ relationships ) { foreach ( $ relationships as $ parentId => $ children ) { if ( $ parentId == 0 ) { continue ; } if ( in_array ( $ id , $ children ) ) { return true ; } } return false ; } | Determines whether given id has a parent |
26,744 | private function getParam ( $ param , $ default = null ) { if ( isset ( $ this -> query [ $ param ] ) ) { return $ this -> query [ $ param ] ; } else { return $ default ; } } | Returns parameter s value from query |
26,745 | private function isSortedByMethod ( $ column , $ value ) { return $ this -> isSortedBy ( $ column ) && $ this -> getParam ( FilterInvoker :: FILTER_PARAM_DESC ) == $ value ; } | Determines whether a column has been sorted either by ASC or DESC method |
26,746 | public function getColumnSortingUrl ( $ column ) { $ data = array ( FilterInvoker :: FILTER_PARAM_PAGE => $ this -> getCurrentPageNumber ( ) , FilterInvoker :: FILTER_PARAM_DESC => ! $ this -> isSortedByDesc ( $ column ) , FilterInvoker :: FILTER_PARAM_SORT => $ column ) ; return FilterInvoker :: createUrl ( array_merge ( $ this -> query , $ data ) , $ this -> route ) ; } | Returns sorting URL for a particular column |
26,747 | public function withToken ( Token $ token ) { $ card = $ this -> with ( 'token' , $ token ) ; if ( null !== $ card -> number ) { $ lastDigits = strlen ( $ card -> number ) <= 4 ? $ card -> number : substr ( $ card -> number , - 4 ) ; $ card -> number = "XXXX-XXXX-XXXX-" . $ lastDigits ; } $ card -> cvv = null ; return $ card ; } | Sets token value . |
26,748 | public function asArray ( ) { $ array = [ ] ; $ properties = ( new \ ReflectionClass ( $ this ) ) -> getProperties ( ReflectionProperty :: IS_PUBLIC ) ; foreach ( $ properties as $ object ) { $ value = $ object -> getValue ( $ this ) ; if ( ! isset ( $ value ) ) { continue ; } $ property = $ object -> getName ( ) ; if ( ! empty ( $ this -> mappings ) && isset ( $ this -> mappings [ $ property ] ) ) { $ property = $ this -> mappings [ $ property ] ; } $ array [ $ property ] = $ value ; } return new \ ArrayIterator ( $ array ) ; } | The array representation of database object . |
26,749 | public function importDatabaseToService ( $ service = null , $ import_path = null , $ copy_to_service = false , $ localhost = false ) { $ destination = $ this -> resolveDatabaseImportDestination ( $ import_path , $ service , $ copy_to_service , $ localhost ) ; $ command = $ this -> resolveDatabaseImportCommand ( ) -> command ( "< {$destination}" ) ; $ this -> executeEngineCommand ( $ command , $ service , [ ] , false , $ localhost ) ; return $ this ; } | Import database dump into a service . |
26,750 | public function getDatabaseInfo ( ServiceDbInterface $ instance = null , $ allow_override = true ) { if ( ! isset ( $ instance ) ) { $ engine = $ this -> getEngineInstance ( ) ; $ instance = $ engine -> getServiceInstanceByInterface ( ServiceDbInterface :: class ) ; if ( $ instance === false ) { throw new \ RuntimeException ( 'Unable to find a service for the database instance.' ) ; } } $ database = $ this -> getServiceInstanceDatabase ( $ instance ) ; if ( ! $ allow_override || ! isset ( $ this -> databaseOverride ) ) { return $ database ; } foreach ( get_object_vars ( $ this -> databaseOverride ) as $ property => $ value ) { if ( empty ( $ value ) ) { continue ; } $ method = 'set' . ucwords ( $ property ) ; if ( ! method_exists ( $ database , $ method ) ) { continue ; } $ database = call_user_func_array ( [ $ database , $ method ] , [ $ value ] ) ; } return $ database ; } | Get database information based on services . |
26,751 | public function getEnvPhpVersion ( ) { $ engine = $ this -> getEngineInstance ( ) ; $ instance = $ engine -> getServiceInstanceByType ( 'php' ) ; if ( empty ( $ instance ) ) { throw new \ RuntimeException ( 'No php service has been found.' ) ; } $ service = $ instance [ 0 ] ; return $ service -> getVersion ( ) ; } | Get environment PHP version . |
26,752 | public function initBehat ( ) { $ root_path = ProjectX :: projectRoot ( ) ; if ( $ this -> hasBehat ( ) && ! file_exists ( "$root_path/tests/Behat/features" ) ) { $ this -> taskBehat ( ) -> option ( 'init' ) -> option ( 'config' , "{$root_path}/tests/Behat/behat.yml" ) -> run ( ) ; } return $ this ; } | Initialize Behat for the project . |
26,753 | public function setupPhpCodeSniffer ( ) { $ root_path = ProjectX :: projectRoot ( ) ; $ this -> taskWriteToFile ( "{$root_path}/phpcs.xml.dist" ) -> text ( $ this -> loadTemplateContents ( 'phpcs.xml.dist' ) ) -> place ( 'PROJECT_ROOT' , $ this -> getInstallRoot ( ) ) -> run ( ) ; $ this -> composer -> addRequires ( [ 'squizlabs/php_codesniffer' => static :: PHPCS_VERSION , ] , true ) ; return $ this ; } | Setup PHP code sniffer . |
26,754 | public function packagePhpBuild ( $ build_root ) { $ project_root = ProjectX :: projectRoot ( ) ; $ stack = $ this -> taskFilesystemStack ( ) ; if ( file_exists ( "{$project_root}/patches" ) ) { $ stack -> mirror ( "{$project_root}/patches" , "{$build_root}/patches" ) ; } $ stack -> copy ( "{$project_root}/composer.json" , "{$build_root}/composer.json" ) ; $ stack -> copy ( "{$project_root}/composer.lock" , "{$build_root}/composer.lock" ) ; $ stack -> run ( ) ; return $ this ; } | Package PHP build . |
26,755 | public function updateComposer ( $ lock = false ) { $ update = $ this -> taskComposerUpdate ( ) ; if ( $ lock ) { $ update -> option ( 'lock' ) ; } $ update -> run ( ) ; return $ this ; } | Update composer packages . |
26,756 | public function hasComposerPackage ( $ vendor , $ dev = false ) { $ packages = ! $ dev ? $ this -> composer -> getRequire ( ) : $ this -> composer -> getRequireDev ( ) ; return isset ( $ packages [ $ vendor ] ) ; } | Has composer package . |
26,757 | protected function extractArchive ( $ filename , $ destination , $ service = null , $ localhost = false ) { $ mime_type = null ; if ( file_exists ( $ filename ) && $ localhost ) { $ mime_type = mime_content_type ( $ filename ) ; } else { $ engine = $ this -> getEngineInstance ( ) ; if ( $ engine instanceof DockerEngineType ) { $ mime_type = $ engine -> getFileMimeType ( $ filename , $ service ) ; } } $ command = null ; switch ( $ mime_type ) { case 'application/gzip' : case 'application/x-gzip' : $ command = ( new CommandBuilder ( 'gunzip' , $ localhost ) ) -> command ( "-c {$filename} > {$destination}" ) ; break ; } if ( ! isset ( $ command ) ) { return $ filename ; } if ( file_exists ( $ destination ) && $ localhost ) { $ this -> _remove ( $ destination ) ; } $ this -> executeEngineCommand ( $ command , $ service , [ ] , false , $ localhost ) ; return $ destination ; } | Extract archive within appropriate environment . |
26,758 | protected function resolveDatabaseImportPath ( $ import_path = null ) { if ( ! isset ( $ import_path ) ) { $ import_path = $ this -> doAsk ( new Question ( 'Input the path to the database file: ' ) ) ; if ( ! file_exists ( $ import_path ) ) { throw new \ Exception ( 'The path to the database file does not exist.' ) ; } } return new \ SplFileInfo ( $ import_path ) ; } | Resolve database import path . |
26,759 | protected function resolveDatabaseImportDestination ( $ import_path , $ service , $ copy_to_service = false , $ localhost = false ) { $ path = $ this -> resolveDatabaseImportPath ( $ import_path ) ; $ filename = $ path -> getFilename ( ) ; $ extract_filename = substr ( $ filename , 0 , strrpos ( $ filename , '.' ) ) ; if ( ! $ localhost ) { if ( $ copy_to_service ) { $ engine = $ this -> getEngineInstance ( ) ; if ( $ engine instanceof DockerEngineType ) { $ engine -> copyFileToService ( $ path -> getRealPath ( ) , '/tmp' , $ service ) ; } } return $ this -> extractArchive ( "/tmp/{$filename}" , "/tmp/{$extract_filename}" , $ service , $ localhost ) ; } return $ this -> extractArchive ( $ path -> getRealPath ( ) , "/tmp/{$extract_filename}" , null , $ localhost ) ; } | Resolve database import destination . |
26,760 | protected function resolveDatabaseServiceInstance ( $ service = null ) { $ engine = $ this -> getEngineInstance ( ) ; $ services = $ engine -> getServiceInstanceByGroup ( 'database' ) ; if ( ! isset ( $ service ) || ! isset ( $ services [ $ service ] ) ) { if ( count ( $ services ) > 1 ) { $ options = array_keys ( $ services ) ; $ service = $ this -> doAsk ( new ChoiceQuestion ( 'Select the database service to use for import: ' , $ options ) ) ; } else { $ options = array_keys ( $ services ) ; $ service = reset ( $ options ) ; } } if ( ! isset ( $ services [ $ service ] ) ) { throw new \ RuntimeException ( 'Unable to resolve database service.' ) ; } return $ services [ $ service ] ; } | Resolve database service instance . |
26,761 | protected function resolveDatabaseImportCommand ( $ service = null ) { $ instance = $ this -> resolveDatabaseServiceInstance ( $ service ) ; $ database = $ this -> getDatabaseInfo ( $ instance ) ; switch ( $ database -> getProtocol ( ) ) { case 'mysql' : return ( new MysqlCommand ( ) ) -> host ( $ database -> getHostname ( ) ) -> username ( $ database -> getUser ( ) ) -> password ( $ database -> getPassword ( ) ) -> database ( $ database -> getDatabase ( ) ) ; case 'pgsql' : return ( new PgsqlCommand ( ) ) -> host ( $ database -> getHostname ( ) ) -> username ( $ database -> getUser ( ) ) -> password ( $ database -> getPassword ( ) ) -> database ( $ database -> getDatabase ( ) ) ; } } | Resolve database import command . |
26,762 | protected function hasDatabaseConnection ( $ host , $ port = 3306 , $ seconds = 30 ) { $ hostChecker = $ this -> getHostChecker ( ) ; $ hostChecker -> setHost ( $ host ) -> setPort ( $ port ) ; return $ hostChecker -> isPortOpenRepeater ( $ seconds ) ; } | Check if host has database connection . |
26,763 | protected function getServiceInstanceDatabase ( ServiceDbInterface $ instance ) { $ port = current ( $ instance -> getHostPorts ( ) ) ; return ( new Database ( $ this -> databaseInfoMapping ( ) ) ) -> setPort ( $ port ) -> setUser ( $ instance -> username ( ) ) -> setPassword ( $ instance -> password ( ) ) -> setProtocol ( $ instance -> protocol ( ) ) -> setHostname ( $ instance -> getName ( ) ) -> setDatabase ( $ instance -> database ( ) ) ; } | Get a service instance database object . |
26,764 | protected function mergeProjectComposerTemplate ( ) { if ( $ contents = $ this -> loadTemplateContents ( 'composer.json' , 'json' ) ) { $ this -> composer = $ this -> composer -> update ( $ contents ) ; } return $ this ; } | Merge project composer template . |
26,765 | protected function setupComposerPackages ( ) { $ platform = $ this -> getPlatformInstance ( ) ; if ( $ platform instanceof ComposerPackageInterface ) { $ platform -> alterComposer ( $ this -> composer ) ; } $ this -> saveComposer ( ) ; return $ this ; } | Setup composer packages . |
26,766 | private function composer ( ) { $ composer_file = $ this -> composerFile ( ) ; return file_exists ( $ composer_file ) ? ComposerConfig :: createFromFile ( $ composer_file ) : new ComposerConfig ( ) ; } | Composer config instance . |
26,767 | public function setAvailablePostage ( $ country , $ code ) { $ postage_areas = new ShippingCalculator ( $ code , $ country ) ; $ postage_areas -> setCost ( $ this -> SubTotalCost ) -> setWeight ( $ this -> TotalWeight ) -> setItems ( $ this -> TotalItems ) ; $ postage_areas = $ postage_areas -> getPostageAreas ( ) ; Session :: set ( "Checkout.AvailablePostage" , $ postage_areas ) ; return $ this ; } | Set postage that is available to the shopping cart based on the country and zip code submitted |
26,768 | public function isCollection ( ) { if ( Checkout :: config ( ) -> click_and_collect ) { $ type = Session :: get ( "Checkout.Delivery" ) ; return ( $ type == "collect" ) ? true : false ; } else { return false ; } } | Are we collecting the current cart? If click and collect is disabled then this returns false otherwise checks if the user has set this via a session . |
26,769 | public function isDeliverable ( ) { $ deliverable = false ; foreach ( $ this -> getItems ( ) as $ item ) { if ( $ item -> Deliverable ) { $ deliverable = true ; } } return $ deliverable ; } | Determine if the current cart contains delivereable items . This is used to determine setting and usage of delivery and postage options in the checkout . |
26,770 | public function emptycart ( ) { $ this -> extend ( "onBeforeEmpty" ) ; $ this -> removeAll ( ) ; $ this -> save ( ) ; $ this -> setSessionMessage ( "bad" , _t ( "Checkout.EmptiedCart" , "Shopping cart emptied" ) ) ; return $ this -> redirectBack ( ) ; } | Action that will clear shopping cart and associated sessions |
26,771 | public function save ( ) { Session :: clear ( "Checkout.PostageID" ) ; $ this -> extend ( "onBeforeSave" ) ; Session :: set ( "Checkout.ShoppingCart.Items" , serialize ( $ this -> items ) ) ; Session :: set ( "Checkout.ShoppingCart.Discount" , serialize ( $ this -> discount ) ) ; if ( $ data = Session :: get ( "Form.Form_PostageForm.data" ) ) { $ country = $ data [ "Country" ] ; $ code = $ data [ "ZipCode" ] ; $ this -> setAvailablePostage ( $ country , $ code ) ; } } | Save the current products list and postage to a session . |
26,772 | public function getSubTotalCost ( ) { $ total = 0 ; foreach ( $ this -> items as $ item ) { if ( $ item -> SubTotal ) { $ total += $ item -> SubTotal ; } } return $ total ; } | Find the cost of all items in the cart without any tax . |
26,773 | public function getDiscountAmount ( ) { $ total = 0 ; $ discount = 0 ; foreach ( $ this -> items as $ item ) { if ( $ item -> Price ) { $ total += ( $ item -> Price * $ item -> Quantity ) ; } if ( $ item -> Discount ) { $ discount += ( $ item -> TotalDiscount ) ; } } if ( $ discount > $ total ) { $ discount = $ total ; } return $ discount ; } | Find the total discount based on discount items added . |
26,774 | public function doAddDiscount ( $ data , $ form ) { $ code_to_search = $ data [ 'DiscountCode' ] ; if ( ! $ this -> discount || ( $ this -> discount && $ this -> discount -> Code != $ code_to_search ) ) { $ code = Discount :: get ( ) -> filter ( "Code" , $ code_to_search ) -> exclude ( "Expires:LessThan" , date ( "Y-m-d" ) ) -> first ( ) ; if ( $ code ) { $ this -> discount = $ code ; } } $ this -> save ( ) ; return $ this -> redirectBack ( ) ; } | Action that will find a discount based on the code |
26,775 | public function doSetPostage ( $ data , $ form ) { $ country = $ data [ "Country" ] ; $ code = $ data [ "ZipCode" ] ; $ this -> setAvailablePostage ( $ country , $ code ) ; $ postage = Session :: get ( "Checkout.AvailablePostage" ) ; if ( array_key_exists ( "PostageID" , $ data ) && $ data [ "PostageID" ] ) { if ( $ postage && $ postage -> exists ( ) && $ postage -> find ( "ID" , $ data [ "PostageID" ] ) ) { $ id = $ data [ "PostageID" ] ; } else { $ id = $ postage -> first ( ) -> ID ; } $ data [ "PostageID" ] = $ id ; Session :: set ( "Checkout.PostageID" , $ id ) ; } else { if ( $ postage && $ postage -> exists ( ) ) { $ data [ "PostageID" ] = $ postage -> first ( ) -> ID ; Session :: set ( "Checkout.PostageID" , $ postage -> first ( ) -> ID ) ; } } Session :: set ( "Form.{$form->FormName()}.data" , $ data ) ; $ url = Controller :: join_links ( $ this -> Link ( ) , "#{$form->FormName()}" ) ; return $ this -> redirect ( $ url ) ; } | Method that deals with get postage details and setting the postage |
26,776 | public function iFillTheUiSelectWithAndSelectElement2 ( $ id , $ item ) { $ items = explode ( "-" , $ item ) ; if ( count ( $ items ) > 0 ) { $ item = $ items [ 0 ] . '-' . ( ( int ) $ items [ 1 ] - 1 ) ; } else { $ item = "0-" . ( ( int ) $ item - 1 ) ; } $ idItem = sprintf ( "#ui-select-choices-row-%s" , $ item ) ; $ this -> iClickTheElement ( sprintf ( "#%s > div.ui-select-match.ng-scope > span" , $ id ) ) ; $ this -> spin ( function ( $ context ) use ( $ idItem ) { $ element = $ context -> findElement ( $ idItem ) ; return $ element != null ; } , 20 ) ; $ element = $ this -> findElement ( $ idItem ) ; $ element -> click ( ) ; } | Selecccionar datos en select de tipo UI |
26,777 | protected function generatePageUrl ( $ route , array $ parameters = array ( ) ) { $ path = $ this -> generateUrl ( $ route , $ parameters ) ; if ( 'Selenium2Driver' === strstr ( get_class ( $ this -> getSession ( ) -> getDriver ( ) ) , 'Selenium2Driver' ) ) { return sprintf ( '%s%s' , $ this -> getMinkParameter ( 'base_url' ) , $ path ) ; } return $ path ; } | Generate page url . This method uses simple convention where page argument is prefixed with sylius_ and used as route name passed to router generate method . |
26,778 | public function iWaitForTextToDisappear ( $ text ) { $ this -> spin ( function ( FeatureContext $ context ) use ( $ text ) { try { $ context -> assertPageContainsText ( $ text ) ; } catch ( \ Behat \ Mink \ Exception \ ResponseTextException $ e ) { return true ; } return false ; } ) ; } | Espera que un texto desaparesca de la pagina |
26,779 | public function spin ( $ lambda , $ wait = 15 , $ errorCallback = null ) { $ time = time ( ) ; $ stopTime = $ time + $ wait ; while ( time ( ) < $ stopTime ) { try { if ( $ lambda ( $ this ) ) { return ; } } catch ( \ Exception $ e ) { } usleep ( 250000 ) ; } if ( $ errorCallback !== null ) { $ errorCallback ( $ this ) ; } throw new \ Exception ( "Spin function timed out after {$wait} seconds" ) ; } | Espera hasta que devuelva true la funcion pasada Based on Behat s own example |
26,780 | public function addRequires ( array $ requires , $ dev = false ) { foreach ( $ requires as $ vendor => $ version ) { if ( ! isset ( $ vendor ) || ! isset ( $ version ) ) { continue ; } if ( ! $ dev ) { $ this -> addRequire ( $ vendor , $ version ) ; } else { $ this -> addDevRequire ( $ vendor , $ version ) ; } } return $ this ; } | Add an array of required packages . |
26,781 | public function addRequire ( $ vendor , $ version ) { if ( ! isset ( $ this -> require [ $ vendor ] ) ) { $ this -> require [ $ vendor ] = $ version ; } return $ this ; } | Add a single require package . |
26,782 | public function addDevRequire ( $ vendor , $ version ) { if ( ! isset ( $ this -> require_dev [ $ vendor ] ) ) { $ this -> require_dev [ $ vendor ] = $ version ; } return $ this ; } | Add a single development require package . |
26,783 | public function addExtra ( $ key , array $ options ) { if ( ! isset ( $ this -> extra [ $ key ] ) ) { $ this -> extra [ $ key ] = $ options ; } return $ this ; } | Add extra options . |
26,784 | public function getStat ( $ stat ) { if ( isset ( $ this -> stats [ $ stat ] ) ) { return $ this -> stats [ $ stat ] ; } return false ; } | Get the value of a given stat |
26,785 | public function getDefaultAddress ( ) { if ( $ this -> cached_address ) { return $ this -> cached_address ; } else { $ address = $ this -> owner -> Addresses ( ) -> sort ( "Default" , "DESC" ) -> first ( ) ; $ this -> cached_address = $ address ; return $ address ; } } | Get the default address from our list of addreses . If no default is set we should return the first in the list . |
26,786 | public function getDiscount ( ) { $ discounts = ArrayList :: create ( ) ; foreach ( $ this -> owner -> Groups ( ) as $ group ) { foreach ( $ group -> Discounts ( ) as $ discount ) { $ discounts -> add ( $ discount ) ; } } $ discounts -> sort ( "Amount" , "DESC" ) ; return $ discounts -> first ( ) ; } | Get a discount from the groups this member is in |
26,787 | public function buildRef ( ItemReferenceInterface $ item , array $ config ) { $ mask = $ config [ 'mask' ] ; $ className = $ config [ 'className' ] ; $ field = $ config [ 'field' ] ; $ qb = $ this -> sequenceGenerator -> createQueryBuilder ( ) ; $ qb -> from ( $ className , 'p' ) ; return $ this -> sequenceGenerator -> generateNext ( $ qb , $ mask , $ field , [ ] , $ config ) ; } | Construye la referencia por defecto |
26,788 | public function setRef ( ItemReferenceInterface $ item ) { $ className = ClassUtils :: getRealClass ( get_class ( $ item ) ) ; $ classMap = $ this -> getClassMap ( ) ; if ( ! isset ( $ classMap [ $ className ] ) ) { throw new LogicException ( sprintf ( "No ha definido la configuracion de '%s' para generar su referencia" , $ className ) ) ; } $ resolver = new \ Symfony \ Component \ OptionsResolver \ OptionsResolver ( ) ; $ resolver -> setDefined ( [ "method" , "field" , "options" , "mask" ] ) ; $ resolver -> setDefaults ( [ 'method' => 'buildRef' , 'field' => 'ref' , 'use_cache' => false , ] ) ; $ config = $ resolver -> resolve ( $ classMap [ $ className ] ) ; $ config [ 'className' ] = $ className ; $ method = $ config [ 'method' ] ; $ ref = $ this -> $ method ( $ item , $ config ) ; $ item -> setRef ( $ ref ) ; return $ ref ; } | Establece la referencia aun objeto |
26,789 | function setSequenceGenerator ( \ Tecnocreaciones \ Bundle \ ToolsBundle \ Service \ SequenceGenerator $ sequenceGenerator ) { $ this -> sequenceGenerator = $ sequenceGenerator ; } | Establece el generador de secuencia |
26,790 | public function renderTabs ( \ Tecnoready \ Common \ Model \ Tab \ Tab $ tab , array $ parameters = [ ] ) { $ parameters [ "tab" ] = $ tab ; return $ this -> container -> get ( 'templating' ) -> render ( $ this -> config [ "tabs" ] [ "template" ] , $ parameters ) ; } | Render base tabs |
26,791 | public function asPlainText ( ) : string { return $ this -> text ?? $ this -> text = ( new Html2Text ( $ this -> html ) ) -> getText ( ) ; } | Convert this content into a plain text . |
26,792 | public function packSchema ( ) : array { $ result = [ ] ; foreach ( $ this -> schemas as $ class => $ schema ) { $ item = [ ODMInterface :: D_INSTANTIATOR => $ schema -> getInstantiator ( ) , ODMInterface :: D_PRIMARY_CLASS => $ schema -> resolvePrimary ( $ this ) , ODMInterface :: D_SCHEMA => $ schema -> packSchema ( $ this ) , ] ; if ( ! $ schema -> isEmbedded ( ) ) { $ item [ ODMInterface :: D_SOURCE_CLASS ] = $ this -> getSource ( $ class ) ; $ item [ ODMInterface :: D_DATABASE ] = $ schema -> getDatabase ( ) ; $ item [ ODMInterface :: D_COLLECTION ] = $ schema -> getCollection ( ) ; } $ result [ $ class ] = $ item ; } return $ result ; } | Pack declared schemas in a normalized form . |
26,793 | public function createIndexes ( ) { foreach ( $ this -> schemas as $ class => $ schema ) { if ( $ schema -> isEmbedded ( ) ) { continue ; } $ collection = $ this -> manager -> database ( $ schema -> getDatabase ( ) ) -> selectCollection ( $ schema -> getCollection ( ) ) ; foreach ( $ schema -> getIndexes ( ) as $ index ) { $ collection -> createIndex ( $ index -> getIndex ( ) , $ index -> getOptions ( ) ) ; } } } | Create all declared indexes . |
26,794 | private function prepare ( $ mimeType , $ baseName ) { @ ob_end_clean ( ) ; if ( ini_get ( 'zlib.output_compression' ) ) { ini_set ( 'zlib.output_compression' , 'Off' ) ; } $ headers = array ( 'Content-Type' => $ mimeType , 'Content-Disposition' => sprintf ( 'attachment; filename="%s"' , rawurldecode ( $ baseName ) ) , 'Content-Transfer-Encoding' => 'binary' , 'Accept-Ranges' => 'bytes' , 'Cache-control' => 'private' , 'Pragma' => 'private' , 'Expires' => 'Thu, 21 Jul 1999 05:00:00 GMT' ) ; $ this -> headerBag -> appendPairs ( $ headers ) -> send ( ) -> clear ( ) ; } | Prepares initial headers to be sent with minor tweaks |
26,795 | private function preload ( $ target , $ alias ) { if ( ! is_file ( $ target ) || ! is_readable ( $ target ) ) { throw new RuntimeException ( 'Either invalid file supplied or its not readable' ) ; } if ( $ alias === null ) { $ baseName = FileManager :: getBaseName ( $ target ) ; } else { $ baseName = $ alias ; } $ mime = FileManager :: getMimeType ( $ target ) ; $ this -> prepare ( $ mime , $ baseName ) ; } | Preloads all required params |
26,796 | public function download ( $ target , $ alias = null ) { $ this -> preload ( $ target , $ alias ) ; $ size = filesize ( $ target ) ; if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { list ( $ a , $ range ) = explode ( "=" , $ _SERVER [ 'HTTP_RANGE' ] , 2 ) ; list ( $ range ) = explode ( "," , $ range , 2 ) ; list ( $ range , $ range_end ) = explode ( "-" , $ range ) ; $ range = intval ( $ range ) ; if ( ! $ range_end ) { $ range_end = $ size - 1 ; } else { $ range_end = intval ( $ range_end ) ; } $ new_length = $ range_end - $ range + 1 ; $ headers = array ( 'Content-Length' => $ new_length , 'Content-Range' => sprintf ( 'bytes %s' , $ range - $ range_end / $ size ) ) ; $ this -> headerBag -> setStatusCode ( 206 ) -> setPairs ( $ headers ) -> send ( ) ; } else { $ new_length = $ size ; $ this -> headerBag -> appendPair ( 'Content-Length' , $ size ) -> send ( ) -> clear ( ) ; } $ chunksize = 1024 * 1024 ; $ bytes_send = 0 ; $ target = fopen ( $ target , 'r' ) ; if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { fseek ( $ target , $ range ) ; } while ( ! feof ( $ target ) && ( ! connection_aborted ( ) ) && ( $ bytes_send < $ new_length ) ) { $ buffer = fread ( $ target , $ chunksize ) ; print ( $ buffer ) ; flush ( ) ; $ bytes_send += strlen ( $ buffer ) ; } fclose ( $ target ) ; } | Sends downloadable headers for a file |
26,797 | final protected function redirectToRoute ( $ route ) { $ url = $ this -> urlBuilder -> build ( $ route ) ; if ( $ url !== null ) { $ this -> response -> redirect ( $ url ) ; } else { throw new RuntimeException ( sprintf ( 'Unknown route supplied for redirection "%s"' , $ route ) ) ; } } | Redirects to given route |
26,798 | final protected function getQueryFilter ( FilterableServiceInterface $ service , $ perPageCount , $ route ) { $ invoker = new FilterInvoker ( $ this -> request -> getQuery ( ) , $ route ) ; return $ invoker -> invoke ( $ service , $ perPageCount ) ; } | Applies filtering method from the service that implements corresponding interface That s just a shortcut method |
26,799 | public function getOptions ( $ key = null ) { if ( $ key == null ) { return $ this -> options ; } else { return $ this -> options [ $ key ] ; } } | Returns current options for a matched controller |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.