idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
51,900
|
public function copyAssets ( ) { $ base = $ source = $ this -> basePath . "resources" . $ this -> ds . "assets_setup" . $ this -> ds ; $ source = [ $ base . "webpack.mix.js" , $ base . "package.json" , $ base . "package-lock.json" , ] ; $ this -> copyFilesFromSource ( $ source , base_path ( ) , false ) ; }
|
Copy the asset files Copy all css js images asset files
|
51,901
|
private function copyConfig ( ) { $ this -> filesystem -> copy ( $ this -> basePath . "config/config.php" , config_path ( 'titan.php' ) ) ; $ this -> line ( "Config Copied: " . config_path ( 'titan.php' ) ) ; }
|
Copy the config file
|
51,902
|
public function copyEventsAndNotifications ( ) { $ this -> copyFilesFromSource ( $ this -> appPath . 'Events' , app_path ( 'Events' ) ) ; $ this -> copyFilesFromSource ( $ this -> appPath . 'Listeners' , app_path ( 'Listeners' ) ) ; $ this -> copyFilesFromSource ( $ this -> appPath . 'Mail' , app_path ( 'Mail' ) ) ; $ this -> copyFilesFromSource ( $ this -> appPath . 'Events' , app_path ( 'Notifications' ) ) ; $ source = $ this -> appPath . "Providers{$this->ds}EventServiceProvider.php" ; $ this -> copyFilesFromSource ( $ source , app_path ( 'Providers' ) ) ; }
|
Copy the events files Copy all events listeners and notifications
|
51,903
|
private function copyHelpers ( ) { $ this -> copyFilesFromSource ( $ this -> appPath . 'Helpers' , app_path ( 'Helpers' ) ) ; $ source = $ this -> appPath . "Providers{$this->ds}HelperServiceProvider.php" ; $ this -> copyFilesFromSource ( $ source , app_path ( 'Providers' ) ) ; $ this -> line ( "Remember to add 'App\Providers\HelperServiceProvider::class,' in your 'config/app.php' in 'providers'" ) ; }
|
Cope the helpers files
|
51,904
|
private function copyRoutesAndProvider ( ) { $ this -> copyFilesFromSource ( $ this -> basePath . "routes" , base_path ( "routes" ) ) ; $ source = $ this -> appPath . "Providers{$this->ds}RouteServiceProvider.php" ; $ this -> copyFilesFromSource ( $ source , app_path ( 'Providers' ) , "namespace Bpocallaghan\Titan" , "namespace App" ) ; }
|
Copy the route service provider The provider will point to routes in the vendor directory
|
51,905
|
private function copyNewsletter ( ) { $ source = "{$this->appPath}Models{$this->ds}NewsletterSubscriber.php" ; $ this -> copyFilesFromSource ( $ source , app_path ( "Models" ) , 'namespace_views' ) ; $ destination = app_path ( "Http{$this->ds}Controllers{$this->ds}Admin{$this->ds}Newsletter" ) ; $ source = "{$this->appPath}Controllers{$this->ds}Admin{$this->ds}Newsletter{$this->ds}SubscribersController.php" ; $ this -> copyFilesFromSource ( $ source , $ destination , 'namespace_views' ) ; $ destination = base_path ( "resources{$this->ds}views{$this->ds}admin{$this->ds}newsletters" ) ; $ source = "{$this->basePath}resources{$this->ds}views{$this->ds}admin{$this->ds}newsletters" ; $ this -> copyFilesFromSource ( $ source , $ destination ) ; $ source = "{$this->basePath}database{$this->ds}migrations{$this->ds}2017_10_01_181435_create_newsletter_subscribers_table.php" ; $ this -> copyFilesFromSource ( $ source , database_path ( "migrations" ) ) ; }
|
Copy all newsletter related files to application
|
51,906
|
private function copyAuthFiles ( ) { $ source = "{$this->appPath}Models{$this->ds}UserInvite.php" ; $ this -> copyFilesFromSource ( $ source , app_path ( "Models" ) , 'namespace_views' ) ; $ this -> copyFilesFromSource ( $ this -> appPath . "Controllers{$this->ds}Auth" , app_path ( "Http{$this->ds}Controllers{$this->ds}Auth" ) ) ; $ destination = base_path ( "resources{$this->ds}views{$this->ds}auth" ) ; $ source = "{$this->basePath}resources{$this->ds}views{$this->ds}auth" ; $ this -> copyFilesFromSource ( $ source , $ destination ) ; }
|
Copy all auth related files to application
|
51,907
|
private function overrideExistingFiles ( Collection $ files , $ source , $ destination ) { $ answer = true ; $ filesFound = [ ] ; $ files -> map ( function ( SplFileInfo $ file ) use ( $ source , $ destination , & $ filesFound ) { $ subDirectories = '' ; $ fileDestination = $ destination . $ file -> getFilename ( ) ; if ( $ source != $ file -> getPath ( ) . $ this -> ds ) { $ subDirectories = str_replace ( $ source , "" , $ file -> getPath ( ) . $ this -> ds ) ; $ fileDestination = $ destination . $ subDirectories . $ file -> getFilename ( ) ; } if ( $ this -> filesystem -> exists ( $ fileDestination ) ) { $ filesFound [ ] = $ subDirectories . $ file -> getFilename ( ) ; } } ) ; if ( count ( $ filesFound ) >= 1 ) { collect ( $ filesFound ) -> each ( function ( $ file ) { $ this -> info ( " - {$file}" ) ; } ) ; $ answer = $ this -> confirm ( "Above is a list of the files that already exist. Override all files?" ) ; } return $ answer ; }
|
See if any files exist Ask to override or not
|
51,908
|
public function uploadBanner ( $ file , $ path = '' , $ size = [ 'o' => [ 1900 , 500 ] , 'tn' => [ 450 , 212 ] ] ) { $ name = token ( ) ; $ extension = $ file -> guessClientExtension ( ) ; $ filename = $ name . '.' . $ extension ; $ filenameThumb = $ name . '-tn.' . $ extension ; $ imageTmp = Image :: make ( $ file -> getRealPath ( ) ) ; if ( ! $ imageTmp ) { return notify ( ) -> error ( 'Oops' , 'Something went wrong' , 'warning shake animated' ) ; } $ path = upload_path_images ( $ path ) ; $ image = $ imageTmp -> fit ( $ size [ 'o' ] [ 0 ] , $ size [ 'o' ] [ 1 ] ) -> save ( $ path . $ filename ) ; $ image -> fit ( $ size [ 'tn' ] [ 0 ] , $ size [ 'tn' ] [ 1 ] ) -> save ( $ path . $ filenameThumb ) ; return $ filename ; }
|
Upload the banner image create a thumb as well
|
51,909
|
public function moveFile ( $ file , $ path = '' ) { $ name = token ( ) ; $ extension = $ file -> guessClientExtension ( ) ; $ filename = $ name . '.' . $ extension ; $ imageTmp = Image :: make ( $ file -> getRealPath ( ) ) ; if ( ! $ imageTmp ) { return notify ( ) -> error ( 'Oops' , 'Something went wrong' , 'warning shake animated' ) ; } $ path = upload_path_images ( $ path ) ; $ image = $ imageTmp -> save ( $ path . $ filename ) ; return $ filename ; }
|
Move the tmp file to desired location
|
51,910
|
private function findChildrenPages ( Page $ page ) { $ pages = Page :: where ( 'parent_id' , $ page -> id ) -> orderBy ( 'header_order' ) -> get ( ) ; return $ pages ; }
|
Get the children pages
|
51,911
|
public function scopeNPerGroup ( $ query , $ group , $ n = 10 ) { $ table = ( $ this -> getTable ( ) ) ; $ query -> from ( DB :: raw ( "(SELECT @rank:=0, @group:=0) as vars, {$table}" ) ) ; if ( ! $ query -> getQuery ( ) -> columns ) { $ query -> select ( "{$table}.*" ) ; } $ groupAlias = 'group_' . md5 ( time ( ) ) ; $ rankAlias = 'rank_' . md5 ( time ( ) ) ; $ query -> addSelect ( DB :: raw ( "@rank := IF(@group = {$group}, @rank+1, 1) as {$rankAlias}, @group := {$group} as {$groupAlias}" ) ) ; $ query -> getQuery ( ) -> orders = ( array ) $ query -> getQuery ( ) -> orders ; array_unshift ( $ query -> getQuery ( ) -> orders , [ 'column' => $ group , 'direction' => 'asc' ] ) ; $ subQuery = $ query -> toSql ( ) ; $ newBase = $ this -> newQuery ( ) -> from ( DB :: raw ( "({$subQuery}) as {$table}" ) ) -> mergeBindings ( $ query -> getQuery ( ) ) -> where ( $ rankAlias , '<=' , $ n ) -> getQuery ( ) ; $ query -> setQuery ( $ newBase ) ; }
|
query scope nPerGroup
|
51,912
|
public function update ( $ user ) { $ user = User :: find ( $ user ) ; if ( ! $ user ) { return redirect_to_resource ( ) ; } $ attributes = request ( ) -> validate ( [ 'firstname' => 'required' , 'lastname' => 'required' , 'cellphone' => 'required' , 'telephone' => 'nullable' , 'born_at' => 'nullable' , 'etokens' => 'nullable' , 'email' => 'required|email|' . Rule :: unique ( 'users' ) -> ignore ( $ user -> id ) , 'roles' => 'required|array' , ] ) ; unset ( $ attributes [ 'roles' ] ) ; $ this -> updateEntry ( $ user , $ attributes ) ; $ user -> roles ( ) -> sync ( input ( 'roles' ) ) ; return redirect_to_resource ( ) ; }
|
Update the specified client in storage .
|
51,913
|
private function getPaginator ( ) { $ perPage = 40 ; $ page = input ( 'page' , 1 ) ; $ itemsObj = $ this -> fetchEntries ( ) ; $ items = $ itemsObj [ 'items' ] ; $ total = $ itemsObj [ 'total' ] ; $ baseUrl = config ( 'app.url' ) . "/admin/accounts/clients" ; $ paginator = new LengthAwarePaginator ( $ items -> forPage ( $ page , $ perPage ) , count ( $ items ) , $ perPage , $ page , [ 'path' => $ baseUrl , 'originalEntries' => $ total ] ) ; return $ paginator ; }
|
Fetch the client paginator
|
51,914
|
private function fetchEntries ( ) { $ items = User :: whereRole ( Role :: $ USER ) -> orderBy ( 'firstname' ) -> get ( ) ; $ total = $ items -> count ( ) ; if ( session ( 'filtered' ) ) { $ client = session ( 'filter_fullname' , '' ) ; if ( strlen ( $ client ) >= 2 ) { $ items = $ items -> filter ( function ( $ item ) use ( $ client ) { return ( stristr ( $ item -> fullname , $ client ) !== false ) ; } ) ; } $ cellphone = session ( 'filter_cellphone' , '' ) ; if ( strlen ( $ cellphone ) >= 2 ) { $ items = $ items -> filter ( function ( $ item ) use ( $ cellphone ) { return ( stristr ( $ item -> cellphone , $ cellphone ) !== false ) ; } ) ; } $ email = session ( 'filter_email' , '' ) ; if ( strlen ( $ email ) >= 2 ) { $ items = $ items -> filter ( function ( $ item ) use ( $ email ) { return ( stristr ( $ item -> email , $ email ) !== false ) ; } ) ; } } return [ 'items' => $ items , 'total' => $ total ] ; }
|
Fetch the users
|
51,915
|
public static function getPopularPages ( ) { $ ids = Page :: where ( 'slug' , '/' ) -> orWhere ( 'url' , '=' , '' ) -> orWhere ( 'url' , 'LIKE' , '/auth%' ) -> orWhere ( 'url' , 'LIKE' , '/account%' ) -> get ( ) -> pluck ( 'id' , 'id' ) -> values ( ) -> toArray ( ) ; $ items = Page :: where ( 'is_hidden' , 0 ) -> whereNotIn ( 'id' , $ ids ) -> orderBy ( 'views' , 'DESC' ) -> get ( ) -> take ( 5 ) ; return $ items ; return $ items ; }
|
Get the popular pages
|
51,916
|
public function scopeWhereRole ( $ query , $ role ) { return $ query -> whereHas ( 'roles' , function ( $ query ) use ( $ role ) { return $ query -> where ( 'keyword' , $ role ) ; } ) ; }
|
Query Scope Get all the users that has the role
|
51,917
|
public function attachRole ( $ roleSlug ) { $ role = Role :: where ( 'keyword' , $ roleSlug ) -> first ( ) ; $ this -> roles ( ) -> attach ( [ $ role -> id ] ) ; return $ this -> roles ; }
|
Attach a Role to the user from the role slug
|
51,918
|
public function syncRoles ( $ roles , $ detach = false ) { foreach ( $ roles as $ k => $ slug ) { $ role = Role :: where ( 'keyword' , $ slug ) -> first ( ) ; $ this -> roles ( ) -> syncWithoutDetaching ( [ $ role -> id ] ) ; } return $ this -> roles ; }
|
Sync the roles
|
51,919
|
public function detachRole ( $ roleSlug ) { $ role = Role :: where ( 'keyword' , $ roleSlug ) -> first ( ) ; $ this -> roles ( ) -> detach ( [ $ role -> id ] ) ; return $ this -> roles ; }
|
Remove a role from the user
|
51,920
|
public function store ( Request $ request ) { $ this -> validate ( $ request , Tag :: $ rules , Tag :: $ messages ) ; $ row = $ this -> createEntry ( Tag :: class , $ request -> only ( 'name' ) ) ; return redirect_to_resource ( ) ; }
|
Store a newly created tag in storage .
|
51,921
|
public function update ( Tag $ tag , Request $ request ) { $ this -> validate ( $ request , Tag :: $ rules , Tag :: $ messages ) ; $ this -> updateEntry ( $ tag , $ request -> only ( 'name' ) ) ; return redirect_to_resource ( ) ; }
|
Update the specified tag in storage .
|
51,922
|
public function destroy ( Tag $ tag , Request $ request ) { $ this -> deleteEntry ( $ tag , $ request ) ; return redirect_to_resource ( ) ; }
|
Remove the specified tag from storage .
|
51,923
|
public function index ( ) { save_resource_url ( ) ; $ items = User :: with ( 'roles' ) -> whereRole ( Role :: $ BASE_ADMIN ) -> get ( ) ; return $ this -> view ( 'titan::accounts.administrators.index' , compact ( 'items' ) ) ; }
|
Show all the administrators
|
51,924
|
public function edit ( User $ administrator ) { $ roles = Role :: getAllLists ( ) ; return $ this -> view ( 'titan::accounts.administrators.create_edit' , compact ( 'roles' ) ) -> with ( 'item' , $ administrator ) ; }
|
Show the form for editing the specified faq .
|
51,925
|
public function update ( User $ administrator , Request $ request ) { $ this -> validate ( $ request , [ 'firstname' => 'required' , 'lastname' => 'required' , 'roles' => 'required|array' , ] ) ; $ this -> updateEntry ( $ administrator , $ request -> only ( [ 'firstname' , 'lastname' , 'cellphone' , 'telephone' , 'born_at' ] ) ) ; $ administrator -> roles ( ) -> sync ( input ( 'roles' ) ) ; return redirect_to_resource ( ) ; }
|
Update the specified faq in storage .
|
51,926
|
public function destroy ( User $ administrator , Request $ request ) { if ( $ administrator -> id <= 3 ) { notify ( ) -> warning ( 'Whoops' , 'You can not delete this user.' ) ; } else { $ this -> deleteEntry ( $ administrator , $ request ) ; } return redirect_to_resource ( ) ; }
|
Remove the specified faq from storage .
|
51,927
|
private function findActivePageTiers ( ) { $ name = 'About Us' ; $ items = collect ( ) ; if ( $ this -> page -> parent_id > 0 ) { $ rows = Page :: where ( 'parent_id' , $ this -> page -> parent_id ) -> orderBy ( 'header_order' ) -> get ( ) ; if ( $ items -> count ( ) > 1 ) { $ items = $ rows ; $ name = $ this -> page -> parent -> name ; } } return ( object ) [ 'name' => $ name , 'items' => $ items , ] ; }
|
Get the active page tiers and the parent
|
51,928
|
public function store ( ) { $ attributes = request ( ) -> validate ( DocumentCategory :: $ rules , DocumentCategory :: $ messages ) ; $ category = $ this -> createEntry ( DocumentCategory :: class , $ attributes ) ; return redirect_to_resource ( ) ; }
|
Store a newly created document_category in storage .
|
51,929
|
public function update ( DocumentCategory $ category ) { $ attributes = request ( ) -> validate ( DocumentCategory :: $ rules , DocumentCategory :: $ messages ) ; $ category = $ this -> updateEntry ( $ category , $ attributes ) ; return redirect_to_resource ( ) ; }
|
Update the specified document_category in storage .
|
51,930
|
public function index ( ) { save_resource_url ( ) ; $ items = PhotoAlbum :: with ( 'photos' ) -> get ( ) ; return $ this -> view ( 'titan::photos.albums.index' ) -> with ( 'items' , $ items ) ; }
|
Display a listing of photo_album .
|
51,931
|
public function store ( Request $ request ) { $ attributes = request ( ) -> validate ( PhotoAlbum :: $ rules , PhotoAlbum :: $ messages ) ; $ album = $ this -> createEntry ( PhotoAlbum :: class , $ attributes ) ; return redirect_to_resource ( ) ; }
|
Store a newly created photo_album in storage .
|
51,932
|
public function update ( PhotoAlbum $ album , Request $ request ) { $ attributes = request ( ) -> validate ( PhotoAlbum :: $ rules , PhotoAlbum :: $ messages ) ; $ album = $ this -> updateEntry ( $ album , $ attributes ) ; return redirect_to_resource ( ) ; }
|
Update the specified photo_album in storage .
|
51,933
|
public function destroy ( PhotoAlbum $ album , Request $ request ) { $ this -> deleteEntry ( $ album , $ request ) ; return redirect_to_resource ( ) ; }
|
Remove the specified photo_album from storage .
|
51,934
|
protected function getKey ( $ key , $ labelValues , $ prefix = '' ) { if ( is_array ( $ labelValues ) ) { $ labelHash = $ this -> getLabelHash ( $ labelValues ) ; } else { $ labelHash = $ labelValues ; } return $ this -> getPrefix ( ) . '|' . $ prefix . '|' . $ key . '|' . $ labelHash ; }
|
Make the base retrieval key for some set of labels and a specific metric key
|
51,935
|
public static function create ( string $ name = 'G' , bool $ directional = true ) : self { $ graph = new self ( ) ; $ graph -> setName ( $ name ) -> setType ( $ directional ? 'digraph' : 'graph' ) ; return $ graph ; }
|
Factory method to instantiate a Graph so that you can use fluent coding to chain everything .
|
51,936
|
public function setPath ( string $ path ) : self { $ realpath = realpath ( $ path ) ; if ( $ path && $ path === $ realpath ) { $ this -> path = $ path . DIRECTORY_SEPARATOR ; } return $ this ; }
|
Sets the path for the execution . Only needed if it is not in the PATH env .
|
51,937
|
public function addGraph ( self $ graph ) : self { $ graph -> setType ( 'subgraph' ) ; $ this -> graphs [ $ graph -> getName ( ) ] = $ graph ; return $ this ; }
|
Adds a subgraph to this graph ; automatically changes the type to subgraph .
|
51,938
|
public function findNode ( string $ name ) { if ( isset ( $ this -> nodes [ $ name ] ) ) { return $ this -> nodes [ $ name ] ; } foreach ( $ this -> graphs as $ graph ) { $ node = $ graph -> findNode ( $ name ) ; if ( $ node ) { return $ node ; } } return null ; }
|
Finds a node in this graph or any of its subgraphs .
|
51,939
|
public function export ( string $ type , string $ filename ) : self { $ type = escapeshellarg ( $ type ) ; $ filename = escapeshellarg ( $ filename ) ; $ tmpfile = ( string ) tempnam ( sys_get_temp_dir ( ) , 'gvz' ) ; file_put_contents ( $ tmpfile , ( string ) $ this ) ; $ tmpfileArg = escapeshellarg ( $ tmpfile ) ; $ output = [ ] ; $ code = 0 ; exec ( $ this -> path . "dot -T${type} -o${filename} < ${tmpfileArg} 2>&1" , $ output , $ code ) ; unlink ( $ tmpfile ) ; if ( $ code !== 0 ) { throw new Exception ( 'An error occurred while creating the graph; GraphViz returned: ' . implode ( PHP_EOL , $ output ) ) ; } return $ this ; }
|
Exports this graph to a generated image .
|
51,940
|
public static function getInstance ( ) { $ self = get_called_class ( ) ; if ( ! isset ( self :: $ instances [ $ self ] ) ) { self :: $ instances [ $ self ] = new $ self ; } return self :: $ instances [ $ self ] ; }
|
Returns instance if instance does not exist then creates new one and returns it
|
51,941
|
private function getError ( $ code , $ id = null , $ data = null ) { return [ 'jsonrpc' => '2.0' , 'id' => $ id , 'error' => [ 'code' => $ code , 'message' => isset ( $ this -> errorMessages [ $ code ] ) ? $ this -> errorMessages [ $ code ] : $ this -> errorMessages [ self :: INTERNALERROR ] , 'data' => $ data , ] , ] ; }
|
Get Error Response
|
51,942
|
private function getDocDescription ( $ comment ) { $ result = null ; if ( preg_match ( '/\*\s+([^@]*)\s+/s' , $ comment , $ matches ) ) { $ result = str_replace ( '*' , "\n" , trim ( trim ( $ matches [ 1 ] , '*' ) ) ) ; } return $ result ; }
|
Get Doc Comment
|
51,943
|
private function resetVars ( ) { $ this -> response = $ this -> calls = [ ] ; $ this -> hasCalls = $ this -> isBatchCall = false ; }
|
Reset Local Class Vars after Execute
|
51,944
|
public static function create ( string $ name , string $ label = null ) : self { return new self ( $ name , $ label ) ; }
|
Factory method used to assist with fluent interface handling .
|
51,945
|
public function check ( Receipt $ receipt ) { try { return $ this -> send ( $ receipt , true ) ; } catch ( ServerException $ e ) { return false ; } }
|
Checking the accuracy of data sent
|
51,946
|
private function processWarnings ( $ warnings ) { $ msgs = [ 1 => 'DIC poplatnika v datove zprave se neshoduje s DIC v certifikatu' , 2 => 'Chybny format DIC poverujiciho poplatnika' , 3 => 'Chybna hodnota PKP' , 4 => 'Datum a cas prijeti trzby je novejsi nez datum a cas prijeti zpravy' , 5 => 'Datum a cas prijeti trzby je vyrazne v minulosti ' ] ; $ this -> lastWarnings = array ( ) ; if ( is_array ( $ warnings ) ) { foreach ( $ warnings as $ warning ) { $ this -> lastWarnings [ ] = [ 'code' => $ warning -> kod_varov , 'message' => isset ( $ msgs [ $ warning -> kod_varov ] ) ? $ msgs [ $ warning -> kod_varov ] : '' ] ; } } else { $ this -> lastWarnings [ ] = [ 'code' => $ warnings -> kod_varov , 'message' => isset ( $ msgs [ $ warnings -> kod_varov ] ) ? $ msgs [ $ warnings -> kod_varov ] : '' ] ; } }
|
Convert warning codes from response to array with messages .
|
51,947
|
public function Output2Base64 ( $ AvatarSize = 0 ) { if ( ! $ AvatarSize ) { $ AvatarSize = $ this -> AvatarSize ; } ob_start ( ) ; imagepng ( $ this -> Resize ( $ AvatarSize ) ) ; $ content = ob_get_contents ( ) ; ob_end_clean ( ) ; return 'data:image/png;base64,' . base64_encode ( $ content ) ; }
|
Output Base64 encoded image data
|
51,948
|
public function dispatchUntil ( ActionEvent $ event , callable $ callback ) : void { foreach ( $ this -> getListeners ( $ event ) as $ listenerHandler ) { $ listener = $ listenerHandler -> getActionEventListener ( ) ; $ listener ( $ event ) ; if ( $ event -> propagationIsStopped ( ) ) { return ; } if ( $ callback ( $ event ) === true ) { return ; } } }
|
Trigger an event until the given callback returns a boolean true
|
51,949
|
public function setName ( $ name ) { if ( null !== $ name ) { Assert :: string ( $ name , 'The command name must be a string or null. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The command name must not be empty.' ) ; Assert :: greaterThan ( strlen ( $ name ) , 1 , sprintf ( 'The command name should contain at least two characters. Got: "%s"' , $ name ) ) ; } parent :: setName ( $ name ) ; return $ this ; }
|
Sets the name of the command .
|
51,950
|
public function setShortName ( $ shortName ) { if ( null !== $ shortName ) { Assert :: string ( $ shortName , 'The short command name must be a string or null. Got: %s' ) ; Assert :: notEmpty ( $ shortName , 'The short command name must not be empty.' ) ; Assert :: regex ( $ shortName , '~^[a-zA-Z]$~' , 'The short command name must contain a single letter. Got: %s' ) ; } if ( null === $ shortName && false === $ this -> longNamePreferred ) { $ this -> longNamePreferred = null ; } $ this -> shortName = $ shortName ; return $ this ; }
|
Sets the short option name of the command .
|
51,951
|
public function register ( $ name , $ handler ) { Assert :: string ( $ name , 'The handler name must be a string. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The handler name must not be empty.' ) ; if ( ! is_object ( $ handler ) ) { Assert :: isCallable ( $ handler , 'The handler must be a callable or an object. Got: %s' ) ; } $ this -> handlers [ $ name ] = $ handler ; if ( ! $ this -> selectedHandler ) { $ this -> selectedHandler = $ name ; } }
|
Registers a command handler for the given name .
|
51,952
|
public function unregister ( $ name ) { unset ( $ this -> handlers [ $ name ] ) ; if ( $ name === $ this -> selectedHandler ) { reset ( $ this -> handlers ) ; $ this -> selectedHandler = key ( $ this -> handlers ) ; } }
|
Unregisters the command handler for the given name .
|
51,953
|
public function selectHandler ( $ handler ) { if ( ! is_callable ( $ handler ) ) { Assert :: string ( $ handler , 'The selected handler must be a callable or a string. Got: %s' ) ; if ( ! isset ( $ this -> handlers [ $ handler ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The handler "%s" does not exist.' , $ handler ) ) ; } } $ this -> selectedHandler = $ handler ; }
|
Selects the executed handler .
|
51,954
|
public static function forArgumentName ( $ name , $ code = 0 , Exception $ cause = null ) { return new static ( sprintf ( 'The argument "%s" does not exist.' , $ name ) , $ code , $ cause ) ; }
|
Creates an exception for the given argument name .
|
51,955
|
public static function forPosition ( $ position , $ code = 0 , Exception $ cause = null ) { return new static ( sprintf ( 'The argument at position %s does not exist.' , $ position ) , $ code , $ cause ) ; }
|
Creates an exception for the given argument position .
|
51,956
|
public function bg ( $ color ) { Assert :: nullOrOneOf ( $ color , self :: $ colors , 'The color must be null or one of the Style::* color constants. Got: "%s"' ) ; $ this -> bgColor = $ color ; return $ this ; }
|
Sets the background color .
|
51,957
|
public static function asciiBorder ( ) { if ( ! self :: $ asciiBorder ) { self :: $ asciiBorder = new static ( ) ; self :: $ asciiBorder -> headerCellFormat = ' %s ' ; self :: $ asciiBorder -> cellFormat = ' %s ' ; self :: $ asciiBorder -> borderStyle = BorderStyle :: ascii ( ) ; } return clone self :: $ asciiBorder ; }
|
A style that uses ASCII characters for drawing borders .
|
51,958
|
public static function solidBorder ( ) { if ( ! self :: $ solidBorder ) { self :: $ solidBorder = new static ( ) ; self :: $ solidBorder -> headerCellFormat = ' %s ' ; self :: $ solidBorder -> cellFormat = ' %s ' ; self :: $ solidBorder -> borderStyle = BorderStyle :: solid ( ) ; } return clone self :: $ solidBorder ; }
|
A style that uses Unicode characters for drawing solid borders .
|
51,959
|
public function getColumnAlignments ( $ nbColumns ) { return array_slice ( array_replace ( array_fill ( 0 , $ nbColumns , $ this -> defaultColumnAlignment ) , $ this -> columnAlignments ) , 0 , $ nbColumns ) ; }
|
Returns the alignments of the table columns .
|
51,960
|
public function getColumnAlignment ( $ column ) { return isset ( $ this -> columnAlignments [ $ column ] ) ? $ this -> columnAlignments [ $ column ] : $ this -> defaultColumnAlignment ; }
|
Returns the alignment of a given column .
|
51,961
|
public function setColumnAlignments ( array $ alignments ) { $ this -> columnAlignments = array ( ) ; foreach ( $ alignments as $ column => $ alignment ) { $ this -> setColumnAlignment ( $ column , $ alignment ) ; } return $ this ; }
|
Sets the alignments of the table columns .
|
51,962
|
public function setColumnAlignment ( $ column , $ alignment ) { Assert :: oneOf ( $ alignment , Alignment :: all ( ) , 'The column alignment must be one of the Alignment constants. Got: %s' ) ; $ this -> columnAlignments [ $ column ] = $ alignment ; return $ this ; }
|
Sets the alignment of a given column .
|
51,963
|
public function setDefaultColumnAlignment ( $ alignment ) { Assert :: oneOf ( $ alignment , Alignment :: all ( ) , 'The default column alignment must be one of the Alignment constants. Got: %s' ) ; $ this -> defaultColumnAlignment = $ alignment ; return $ this ; }
|
Returns the default column alignment .
|
51,964
|
public static function ascii ( ) { if ( ! self :: $ ascii ) { self :: $ ascii = new static ( ) ; self :: $ ascii -> lineVLChar = '|' ; self :: $ ascii -> lineVCChar = '|' ; self :: $ ascii -> lineVRChar = '|' ; self :: $ ascii -> lineHTChar = '-' ; self :: $ ascii -> lineHCChar = '-' ; self :: $ ascii -> lineHBChar = '-' ; self :: $ ascii -> cornerTLChar = '+' ; self :: $ ascii -> cornerTRChar = '+' ; self :: $ ascii -> cornerBLChar = '+' ; self :: $ ascii -> cornerBRChar = '+' ; self :: $ ascii -> crossingCChar = '+' ; self :: $ ascii -> crossingLChar = '+' ; self :: $ ascii -> crossingRChar = '+' ; self :: $ ascii -> crossingTChar = '+' ; self :: $ ascii -> crossingBChar = '+' ; } return clone self :: $ ascii ; }
|
A style that uses ASCII characters only .
|
51,965
|
public function render ( IO $ io , $ indentation = 0 ) { if ( $ this -> config -> getDisplayName ( ) && $ this -> config -> getVersion ( ) ) { $ paragraph = new Paragraph ( "{$this->config->getDisplayName()} version <c1>{$this->config->getVersion()}</c1>" ) ; } elseif ( $ this -> config -> getDisplayName ( ) ) { $ paragraph = new Paragraph ( "{$this->config->getDisplayName()}" ) ; } else { $ paragraph = new Paragraph ( 'Console Tool' ) ; } $ paragraph -> render ( $ io , $ indentation ) ; }
|
Renders the name and version .
|
51,966
|
public static function forOptionName ( $ name , $ code = 0 , Exception $ cause = null ) { return new static ( sprintf ( 'The option "%s%s" does not exist.' , strlen ( $ name ) > 1 ? '--' : '-' , $ name ) , $ code , $ cause ) ; }
|
Creates an exception for the given option name .
|
51,967
|
public function add ( Command $ command ) { $ name = $ command -> getName ( ) ; $ this -> commands [ $ name ] = $ command ; if ( $ shortName = $ command -> getShortName ( ) ) { $ this -> shortNameIndex [ $ shortName ] = $ name ; } foreach ( $ command -> getAliases ( ) as $ alias ) { $ this -> aliasIndex [ $ alias ] = $ name ; } ksort ( $ this -> aliasIndex ) ; }
|
Adds a command to the collection .
|
51,968
|
public function get ( $ name ) { if ( isset ( $ this -> commands [ $ name ] ) ) { return $ this -> commands [ $ name ] ; } if ( isset ( $ this -> shortNameIndex [ $ name ] ) ) { return $ this -> commands [ $ this -> shortNameIndex [ $ name ] ] ; } if ( isset ( $ this -> aliasIndex [ $ name ] ) ) { return $ this -> commands [ $ this -> aliasIndex [ $ name ] ] ; } throw NoSuchCommandException :: forCommandName ( $ name ) ; }
|
Returns a command by its name .
|
51,969
|
public function remove ( $ name ) { if ( isset ( $ this -> aliasIndex [ $ name ] ) ) { $ this -> remove ( $ this -> aliasIndex [ $ name ] ) ; return ; } if ( isset ( $ this -> shortNameIndex [ $ name ] ) ) { $ this -> remove ( $ this -> shortNameIndex [ $ name ] ) ; return ; } unset ( $ this -> commands [ $ name ] ) ; foreach ( $ this -> shortNameIndex as $ shortName => $ targetName ) { if ( $ name === $ targetName ) { unset ( $ this -> shortNameIndex [ $ shortName ] ) ; } } foreach ( $ this -> aliasIndex as $ alias => $ targetName ) { if ( $ name === $ targetName ) { unset ( $ this -> aliasIndex [ $ alias ] ) ; } } }
|
Removes the command with the given name from the collection .
|
51,970
|
public function contains ( $ name ) { return isset ( $ this -> commands [ $ name ] ) || isset ( $ this -> shortNameIndex [ $ name ] ) || isset ( $ this -> aliasIndex [ $ name ] ) ; }
|
Returns whether the collection contains a command with the given name .
|
51,971
|
public function getNames ( $ includeAliases = false ) { $ names = array_keys ( $ this -> commands ) ; if ( $ includeAliases ) { $ names = array_merge ( $ names , array_keys ( $ this -> aliasIndex ) ) ; } sort ( $ names ) ; return $ names ; }
|
Returns the names of all commands in the collection .
|
51,972
|
public function parseValue ( $ value ) { $ nullable = ( $ this -> flags & self :: NULLABLE ) ; if ( $ this -> flags & self :: BOOLEAN ) { return StringUtil :: parseBoolean ( $ value , $ nullable ) ; } if ( $ this -> flags & self :: INTEGER ) { return StringUtil :: parseInteger ( $ value , $ nullable ) ; } if ( $ this -> flags & self :: FLOAT ) { return StringUtil :: parseFloat ( $ value , $ nullable ) ; } return StringUtil :: parseString ( $ value , $ nullable ) ; }
|
Parses an option value .
|
51,973
|
public static function isSupported ( ) { if ( null === self :: $ supported ) { self :: $ supported = function_exists ( 'cli_set_process_title' ) || function_exists ( 'setproctitle' ) ; } return self :: $ supported ; }
|
Returns whether process titles can be set .
|
51,974
|
public static function resetProcessTitle ( ) { $ processTitle = self :: $ processTitles ? array_pop ( self :: $ processTitles ) : null ; self :: changeProcessTitleTo ( $ processTitle ) ; }
|
Resets the title of the PHP process to the previous value .
|
51,975
|
public function add ( Component $ element ) { $ this -> elements [ ] = $ element ; $ this -> indentations [ ] = $ this -> currentIndentation ; if ( $ element instanceof LabeledParagraph ) { $ this -> alignment -> add ( $ element , $ this -> currentIndentation ) ; $ element -> setAlignment ( $ this -> alignment ) ; } return $ this ; }
|
Adds a renderable element to the layout .
|
51,976
|
public function render ( IO $ io , $ indentation = 0 ) { $ this -> alignment -> align ( $ io , $ indentation ) ; foreach ( $ this -> elements as $ i => $ element ) { $ element -> render ( $ io , $ this -> indentations [ $ i ] + $ indentation ) ; } $ this -> elements = array ( ) ; }
|
Renders all elements in the layout .
|
51,977
|
public function render ( IO $ io , $ indentation = 0 ) { if ( ! $ io -> isVerbose ( ) ) { $ io -> errorLine ( 'fatal: ' . $ this -> exception -> getMessage ( ) ) ; return ; } $ exception = $ this -> exception ; $ this -> renderException ( $ io , $ exception ) ; if ( $ io -> isVeryVerbose ( ) ) { while ( $ exception = $ exception -> getPrevious ( ) ) { $ io -> errorLine ( 'Caused by:' ) ; $ this -> renderException ( $ io , $ exception ) ; } } }
|
Renders the exception trace .
|
51,978
|
public function getCommandNames ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ commandNames = $ this -> commandNames ; if ( $ includeBase && $ this -> baseFormat ) { $ commandNames = array_merge ( $ this -> baseFormat -> getCommandNames ( ) , $ commandNames ) ; } return $ commandNames ; }
|
Returns the command names .
|
51,979
|
public function hasCommandNames ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( count ( $ this -> commandNames ) > 0 ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasCommandNames ( ) ; } return false ; }
|
Returns whether the format contains any command names .
|
51,980
|
public function getCommandOption ( $ name , $ includeBase = true ) { Assert :: string ( $ name , 'The option name must be a string or an integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The option name must not be empty.' ) ; Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( isset ( $ this -> commandOptions [ $ name ] ) ) { return $ this -> commandOptions [ $ name ] ; } if ( isset ( $ this -> commandOptionsByShortName [ $ name ] ) ) { return $ this -> commandOptionsByShortName [ $ name ] ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> getCommandOption ( $ name ) ; } throw NoSuchOptionException :: forOptionName ( $ name ) ; }
|
Returns a command option by its long or short name .
|
51,981
|
public function getCommandOptions ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ commandOptions = array_values ( $ this -> commandOptions ) ; if ( $ includeBase && $ this -> baseFormat ) { $ commandOptions = array_merge ( $ this -> baseFormat -> getCommandOptions ( ) , $ commandOptions ) ; } return $ commandOptions ; }
|
Returns all command options of the format .
|
51,982
|
public function hasCommandOption ( $ name , $ includeBase = true ) { Assert :: string ( $ name , 'The option name must be a string or an integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The option name must not be empty.' ) ; Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( isset ( $ this -> commandOptions [ $ name ] ) || isset ( $ this -> commandOptionsByShortName [ $ name ] ) ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasCommandOption ( $ name ) ; } return false ; }
|
Returns whether the format contains a specific command option .
|
51,983
|
public function hasCommandOptions ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( count ( $ this -> commandOptions ) > 0 ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasCommandOptions ( ) ; } return false ; }
|
Returns whether the format contains command options .
|
51,984
|
public function getArguments ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ arguments = $ this -> arguments ; if ( $ includeBase && $ this -> baseFormat ) { $ arguments = array_replace ( $ this -> baseFormat -> getArguments ( ) , $ arguments ) ; } return $ arguments ; }
|
Returns all arguments of the format .
|
51,985
|
public function hasArgument ( $ name , $ includeBase = true ) { if ( ! is_int ( $ name ) ) { Assert :: string ( $ name , 'The argument name must be a string or an integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The argument name must not be empty.' ) ; } Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ arguments = is_int ( $ name ) ? array_values ( $ this -> getArguments ( $ includeBase ) ) : $ this -> getArguments ( $ includeBase ) ; return isset ( $ arguments [ $ name ] ) ; }
|
Returns whether the format contains a specific argument .
|
51,986
|
public function hasMultiValuedArgument ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( $ this -> hasMultiValuedArg ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasMultiValuedArgument ( ) ; } return false ; }
|
Returns whether the format contains a multi - valued argument .
|
51,987
|
public function hasOptionalArgument ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( $ this -> hasOptionalArg ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasOptionalArgument ( ) ; } return false ; }
|
Returns whether the format contains an optional argument .
|
51,988
|
public function hasRequiredArgument ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( ! $ this -> hasOptionalArg && count ( $ this -> arguments ) > 0 ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasRequiredArgument ( ) ; } return false ; }
|
Returns whether the format contains a required argument .
|
51,989
|
public function hasArguments ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( count ( $ this -> arguments ) > 0 ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasArguments ( ) ; } return false ; }
|
Returns whether the format contains any argument .
|
51,990
|
public function getNumberOfArguments ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( $ this -> hasMultiValuedArg ) { return PHP_INT_MAX ; } return count ( $ this -> getArguments ( $ includeBase ) ) ; }
|
Returns the number of arguments .
|
51,991
|
public function getNumberOfRequiredArguments ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ arguments = $ this -> getArguments ( $ includeBase ) ; $ count = 0 ; foreach ( $ arguments as $ argument ) { if ( ! $ argument -> isRequired ( ) ) { continue ; } if ( $ argument -> isMultiValued ( ) ) { return PHP_INT_MAX ; } ++ $ count ; } return $ count ; }
|
Returns the number of required arguments .
|
51,992
|
public function getOption ( $ name , $ includeBase = true ) { Assert :: string ( $ name , 'The option name must be a string or an integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The option name must not be empty.' ) ; Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( isset ( $ this -> options [ $ name ] ) ) { return $ this -> options [ $ name ] ; } if ( isset ( $ this -> optionsByShortName [ $ name ] ) ) { return $ this -> optionsByShortName [ $ name ] ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> getOption ( $ name ) ; } throw NoSuchOptionException :: forOptionName ( $ name ) ; }
|
Returns an option by its long or short name .
|
51,993
|
public function getOptions ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; $ options = $ this -> options ; if ( $ includeBase && $ this -> baseFormat ) { $ options = array_replace ( $ options , $ this -> baseFormat -> getOptions ( ) ) ; } return $ options ; }
|
Returns all options of the format .
|
51,994
|
public function hasOption ( $ name , $ includeBase = true ) { Assert :: string ( $ name , 'The option name must be a string or an integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The option name must not be empty.' ) ; Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( isset ( $ this -> options [ $ name ] ) || isset ( $ this -> optionsByShortName [ $ name ] ) ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasOption ( $ name ) ; } return false ; }
|
Returns whether the format contains a specific option .
|
51,995
|
public function hasOptions ( $ includeBase = true ) { Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( count ( $ this -> options ) > 0 ) { return true ; } if ( $ includeBase && $ this -> baseFormat ) { return $ this -> baseFormat -> hasOptions ( ) ; } return false ; }
|
Returns whether the format contains options .
|
51,996
|
private function createBuilderForElements ( array $ elements , ArgsFormat $ baseFormat = null ) { $ builder = new ArgsFormatBuilder ( $ baseFormat ) ; foreach ( $ elements as $ element ) { if ( $ element instanceof CommandName ) { $ builder -> addCommandName ( $ element ) ; } elseif ( $ element instanceof CommandOption ) { $ builder -> addCommandOption ( $ element ) ; } elseif ( $ element instanceof Option ) { $ builder -> addOption ( $ element ) ; } elseif ( $ element instanceof Argument ) { $ builder -> addArgument ( $ element ) ; } else { throw new InvalidArgumentException ( sprintf ( 'Expected instances of CommandName, CommandOption, ' . 'Option or Argument. Got: %s' , is_object ( $ element ) ? get_class ( $ element ) : gettype ( $ element ) ) ) ; } } return $ builder ; }
|
Creates a format builder for a set of arguments and options .
|
51,997
|
public function setCellAlignment ( $ alignment ) { Assert :: oneOf ( $ alignment , Alignment :: all ( ) , 'The cell alignment must be one of the Alignment constants. Got: %s' ) ; $ this -> cellAlignment = $ alignment ; return $ this ; }
|
Sets the cell alignment .
|
51,998
|
public function getEstimatedNbColumns ( $ maxTotalWidth ) { $ i = 0 ; $ rowWidth = 0 ; while ( isset ( $ this -> cells [ $ i ] ) ) { $ rowWidth += StringUtil :: getLength ( $ this -> cells [ $ i ] ) ; if ( $ rowWidth > $ maxTotalWidth ) { return $ i ; } ++ $ i ; } return $ i ; }
|
Returns an estimated number of columns for the given maximum width .
|
51,999
|
public function fit ( $ maxTotalWidth , $ nbColumns , Formatter $ formatter ) { $ this -> resetState ( $ maxTotalWidth , $ nbColumns ) ; $ this -> initRows ( $ formatter ) ; if ( $ this -> totalWidth <= $ maxTotalWidth ) { return ; } $ this -> wrapColumns ( $ formatter ) ; }
|
Fits the added cells into the given maximum total width with the given number of columns .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.