idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
5,800
|
public static function model ( $ model , $ handler = null ) { $ model_data = call_user_func ( $ model . '::_model' ) ; return Query :: select ( $ model_data [ 'table' ] , null , $ model_data [ 'handler' ] ) -> fetch_handler ( $ model . '::_fetch_handler' ) ; }
|
Create a select query with an model assignment
|
5,801
|
public static function last ( $ table , $ key = null , $ handler = null ) { return Query :: select ( $ table ) -> last ( $ key , $ handler ) ; }
|
Get the last result by key
|
5,802
|
public static function insert ( $ table , $ values = array ( ) , $ handler = null ) { return Query :: insert ( $ table , $ values , $ handler ) ; }
|
Create an insert query object
|
5,803
|
public function modalInfoAction ( $ id ) { $ oCustomer = CustomerQuery :: create ( ) -> findOneById ( $ id ) ; return $ this -> render ( 'SlashworksAppBundle:Customer:modal_info.html.twig' , array ( 'customer' => $ oCustomer ) ) ; }
|
Modal info window for customerinformations
|
5,804
|
public function newAction ( ) { $ oCustomer = new Customer ( ) ; $ form = $ this -> createCreateForm ( $ oCustomer ) ; return $ this -> render ( 'SlashworksAppBundle:Customer:new.html.twig' , array ( 'entity' => $ oCustomer , 'form' => $ form -> createView ( ) , ) ) ; }
|
Displays a form to create a new Customer entity .
|
5,805
|
public function editAction ( $ id ) { $ oCustomer = CustomerQuery :: create ( ) -> findOneById ( $ id ) ; if ( count ( $ oCustomer ) === 0 ) { throw $ this -> createNotFoundException ( 'Unable to find Customer entity.' ) ; } $ oEditForm = $ this -> createEditForm ( $ oCustomer ) ; $ oDeleteForm = $ this -> createDeleteForm ( $ id ) ; return $ this -> render ( 'SlashworksAppBundle:Customer:edit.html.twig' , array ( 'entity' => $ oCustomer , 'edit_form' => $ oEditForm -> createView ( ) , 'delete_form' => $ oDeleteForm -> createView ( ) , ) ) ; }
|
Displays a form to edit an existing Customer entity .
|
5,806
|
public function updateAction ( Request $ request , $ id ) { $ oCustomer = CustomerQuery :: create ( ) -> findOneById ( $ id ) ; if ( count ( $ oCustomer ) === 0 ) { throw $ this -> createNotFoundException ( 'Unable to find Customer entity.' ) ; } $ deleteForm = $ this -> createDeleteForm ( $ id ) ; $ editForm = $ this -> createEditForm ( $ oCustomer ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isValid ( ) ) { $ sLogoPath = $ this -> _handleLogoUpload ( $ request , $ oCustomer ) ; $ oCustomer -> setLogo ( $ sLogoPath ) ; $ oCustomer -> save ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'backend_system_customer' ) ) ; } return $ this -> render ( 'SlashworksAppBundle:Customer:edit.html.twig' , array ( 'entity' => $ oCustomer , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ) ; }
|
Update existing customer
|
5,807
|
private function _handleLogoUpload ( Request & $ request , Customer & $ oCustomer ) { $ sLogoPath = "" ; $ oFiles = $ request -> files ; $ aFiles = $ oFiles -> get ( "slashworks_appbundle_customer" ) ; $ sUploadPath = __DIR__ . "/../../../../web/files/customers" ; if ( isset ( $ aFiles [ 'logo' ] ) ) { if ( ! empty ( $ aFiles [ 'logo' ] ) ) { $ oUploadedFile = $ aFiles [ 'logo' ] ; $ sUniqId = sha1 ( uniqid ( mt_rand ( ) , true ) ) ; $ sFileName = $ sUniqId . '.' . $ oUploadedFile -> guessExtension ( ) ; $ oUploadedFile -> move ( $ sUploadPath , $ sFileName ) ; $ sLogoPath = $ sFileName ; } } return $ sLogoPath ; }
|
Handle Logo uplaod
|
5,808
|
private function createCreateForm ( Customer $ oCustomer ) { $ form = $ this -> createForm ( new CustomerType ( array ( "language" => $ this -> get ( 'request' ) -> getLocale ( ) ) ) , $ oCustomer , array ( 'action' => $ this -> generateUrl ( 'backend_system_customer_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
|
Creates a form to create a Customer entity .
|
5,809
|
private function createEditForm ( Customer $ oCustomer ) { $ oForm = $ this -> createForm ( new CustomerType ( array ( "language" => $ this -> get ( 'request' ) -> getLocale ( ) ) ) , $ oCustomer , array ( 'action' => $ this -> generateUrl ( 'backend_system_customer_update' , array ( 'id' => $ oCustomer -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ oForm -> add ( 'submit' , 'submit' , array ( 'label' => 'Update' ) ) ; return $ oForm ; }
|
Create form for editing customer
|
5,810
|
protected function sendMessage ( BaseMessageInterface $ message , $ baseUrl , array $ options = array ( ) ) { $ client = $ this -> createClient ( sprintf ( '%s/%s' , $ baseUrl , $ this -> flowApiToken ) ) ; $ response = $ client -> post ( null , array_merge ( $ options , [ 'headers' => [ 'Content-Type' => 'application/json' ] , 'json' => $ message -> getData ( ) ] ) ) ; $ message -> setResponse ( $ response ) ; return ! $ message -> hasResponseErrors ( ) ; }
|
Sends a message to a flow
|
5,811
|
public function findFiles ( ) { $ search = ( new Finder ( ) ) -> files ( ) ; foreach ( $ this -> paths as $ path ) { if ( is_readable ( $ path ) ) { $ search -> in ( $ path ) ; } } foreach ( $ this -> files as $ pattern ) { $ search -> name ( $ pattern ) ; } $ array = array ( ) ; foreach ( $ search as $ f ) { $ array [ ] = $ f -> getRealPath ( ) ; } return $ array ; }
|
Return an array of file paths to config files
|
5,812
|
public function hasRole ( $ role ) { if ( ! $ this -> roles -> where ( 'token' , $ role ) -> isEmpty ( ) ) { return true ; } foreach ( $ this -> groups as $ group ) { if ( ! $ group -> roles -> where ( 'token' , $ role ) -> isEmpty ( ) ) { return true ; } } return false ; }
|
Check if user has given role
|
5,813
|
public function hasPermission ( $ permission ) { if ( ! $ this -> permissions -> where ( 'token' , $ permission ) -> isEmpty ( ) ) { return true ; } foreach ( $ this -> groups as $ group ) { foreach ( $ group -> roles as $ role ) { if ( ! $ role -> permissions -> where ( 'token' , $ permission ) -> isEmpty ( ) ) { return true ; } } } foreach ( $ this -> roles as $ role ) { if ( ! $ role -> permissions -> where ( 'token' , $ permission ) -> isEmpty ( ) ) { return true ; } } return false ; }
|
Check if user has given permission
|
5,814
|
public function extractArgs ( $ args ) { foreach ( $ args as $ k => $ v ) { if ( property_exists ( $ this , $ k ) ) { $ this -> $ k = $ v ; } else { throw new \ InvalidArgumentException ( "{$k} is not a valid option." ) ; } } }
|
Loops through a given array and it the key exists as a property on this object it is assigned .
|
5,815
|
public function getDisplayValue ( $ formid = null ) { if ( $ formid && isset ( $ _SESSION [ $ formid ] [ $ this -> name ] ) ) { $ value = $ _SESSION [ $ formid ] [ $ this -> name ] ; } else if ( isset ( $ _POST [ $ this -> name ] ) ) { $ value = $ _POST [ $ this -> name ] ; } else { $ value = $ this -> defaultValue ; } return $ this -> cleanValue ( $ value ) ; }
|
Get the value to display in the form field . Either the value in the session post data the default value or nothing .
|
5,816
|
protected function cleanValue ( $ value ) { if ( is_array ( $ value ) ) { return array_map ( function ( $ v ) { return $ this -> cleanValue ( $ v ) ; } , $ value ) ; } else { return stripslashes ( $ value ) ; } }
|
Clean a value up for repopulation in a form field
|
5,817
|
public function validate ( ) { $ this -> errors = array ( ) ; $ value = $ this -> getRawValue ( ) ; if ( $ this -> required ) { $ passed = $ this -> validateRequired ( $ value ) ; if ( ! $ passed ) return $ this -> errors ; $ this -> validateType ( $ value ) ; $ this -> validatePattern ( $ value ) ; $ this -> validateMaxLength ( $ value ) ; } return $ this -> errors ; }
|
Validate a field
|
5,818
|
public function validateMaxLength ( $ value ) { if ( ! isset ( $ this -> attr [ "maxlength" ] ) ) return true ; $ maxlength = trim ( $ this -> attr [ "maxlength" ] ) ; $ length = strlen ( $ value ) ; if ( $ length > $ maxlength ) { $ this -> errors [ ] = "\"{$this->label}\" contains {$length} characters, but it is limited to {$maxlength} characters. Please shorten the length." ; return false ; } return true ; }
|
Validates the maximum length of a form element .
|
5,819
|
public function validatePattern ( $ value ) { if ( ! isset ( $ this -> attr [ "pattern" ] ) ) return true ; $ pattern = trim ( $ this -> attr [ "pattern" ] , "/" ) ; if ( ! preg_match ( "/{$pattern}/" , $ value ) ) { $ this -> errors [ ] = "\"{$this->label}\" must match the specified pattern." ; return false ; } return true ; }
|
Validates a form element with a pattern attribute .
|
5,820
|
public function uri ( CryptographyEngine $ cryptographyEngine ) { $ uri = parent :: uri ( $ cryptographyEngine ) ; $ params = array ( 'hash' => $ cryptographyEngine -> hash ( $ this -> email ) , ) ; if ( null !== $ this -> action ) $ params [ 'action' ] = $ this -> action ; if ( null !== $ this -> scope ) $ params [ 'scope' ] = $ this -> scope ; $ query = http_build_query ( $ params ) ; return $ uri . ( empty ( $ query ) ? '' : '?' . $ query ) ; }
|
returns query parameter
|
5,821
|
public function response ( Response $ response , CryptographyEngine $ cryptographyEngine ) { $ decryptedResponse = new DecryptedCommandResponse ( $ response ) ; $ decryptedResponse -> assignCryptographyEngine ( $ cryptographyEngine , $ this -> email ) ; return $ decryptedResponse ; }
|
creates a response from http response
|
5,822
|
public function usernameAvailableAction ( Request $ request ) { $ response = array ( 'cssClass' => 'success' , 'text' => 'username is available' , ) ; $ user = $ this -> get ( 'userfriendly_social_user.oauth_user_provider' ) -> findOneByUsernameSlug ( $ request -> get ( 'username_slug' ) ) ; $ currentUser = $ this -> get ( 'security.context' ) -> getToken ( ) -> getUser ( ) ; if ( $ currentUser -> getId ( ) != $ user -> getId ( ) && ! $ this -> get ( 'security.context' ) -> isGranted ( 'ROLE_ADMIN' ) ) { throw new NotFoundHttpException ( ) ; } $ requestedUsername = $ request -> get ( 'username' ) ; $ canonicalUsername = $ this -> get ( 'fos_user.util.username_canonicalizer' ) -> canonicalize ( $ requestedUsername ) ; if ( $ requestedUsername != $ user -> getUsername ( ) ) { $ users = $ repo -> findByUsernameCanonical ( $ canonicalUsername ) ; if ( count ( $ users ) > 0 ) { $ response [ 'cssClass' ] = 'error' ; $ response [ 'text' ] = 'username not available' ; } } return new Response ( json_encode ( $ response ) ) ; }
|
AJAX action for checking username availability
|
5,823
|
private function showAndEdit ( Request $ request , $ action ) { $ user = $ this -> get ( 'userfriendly_social_user.oauth_user_provider' ) -> findOneByUsernameSlug ( $ request -> get ( 'username_slug' ) ) ; if ( $ user ) { $ currentUser = $ this -> get ( 'security.context' ) -> getToken ( ) -> getUser ( ) ; if ( self :: SHOW == $ action || $ currentUser -> getId ( ) == $ user -> getId ( ) || $ this -> get ( 'security.context' ) -> isGranted ( 'ROLE_ADMIN' ) ) { return $ this -> render ( 'UserfriendlySocialUserBundle:Profile:' . $ action . '.html.twig' , array ( 'user' => $ user , ) ) ; } throw new AccessDeniedException ( ) ; } throw new NotFoundHttpException ( ) ; }
|
Private methods for use in this Controller s public methods
|
5,824
|
public function laraException ( Request $ request ) { $ storage = Storage :: disk ( 'local' ) ; $ fileName = base64_decode ( urldecode ( $ request -> get ( 'errors' ) ) ) ; if ( ! $ storage -> exists ( $ fileName ) ) { $ info = null ; } else { $ info = $ storage -> get ( $ fileName ) ; } $ view = self :: VIEW_DEFAULT ; $ errors = [ ] ; if ( is_null ( $ info ) ) { $ errors = [ 'details' => '' , 'message' => 'LaraException' , 'debugCode' => '0' , 'errors' => [ ] , 'routeBack' => '' ] ; } else { $ storage -> delete ( $ fileName ) ; $ data = json_decode ( base64_decode ( $ info ) , true ) ; $ errors = $ data [ 'errors' ] ; $ view = $ data [ 'view' ] ; } return view ( $ view , $ errors ) ; }
|
Controlador encargado de validar que debe retornar si la vista o el response JSON
|
5,825
|
public function initialize ( array $ config ) { $ config = Hash :: merge ( $ this -> _defaultConfig , $ config ) ; $ this -> setConfig ( $ config ) ; }
|
Initialize hook .
|
5,826
|
protected function _clearCacheGroup ( ) { $ cacheGroups = ( array ) $ this -> getConfig ( 'groups' ) ; foreach ( $ cacheGroups as $ group ) { Cache :: clearGroup ( $ group , $ this -> getConfig ( 'config' ) ) ; } }
|
Clear cache group .
|
5,827
|
public function lister ( $ tag , array $ list ) { $ html = '' ; $ class = '' ; if ( $ space = strpos ( $ tag , ' ' ) ) { $ class = trim ( substr ( $ tag , $ space ) ) ; $ tag = substr ( $ tag , 0 , $ space ) ; } foreach ( $ list as $ key => $ value ) { if ( $ tag == 'dl' ) { $ html .= '<dt>' . $ key . '</dt>' ; $ html .= '<dd>' . ( is_array ( $ value ) ? implode ( '</dd><dd>' , $ value ) : $ value ) . '</dd>' ; } else { $ html .= '<li>' . ( is_array ( $ value ) ? $ key . $ this -> lister ( $ tag , $ value ) : $ value ) . '</li>' ; } } return $ this -> page -> tag ( $ tag , array ( 'class' => $ class ) , $ html ) ; }
|
This assists you in making Ordered Unordered and Definition lists . It is especially useful when you are nesting lists within lists . Your code almost looks exactly like you would expect to see it on the big screen . It would have been nice if we could have named this method list but someone has taken that already .
|
5,828
|
public function search ( $ url , array $ form = array ( ) ) { $ html = '' ; $ form = array_merge ( array ( 'name' => 'search' , 'role' => 'search' , 'class' => 'form-horizontal' , 'placeholder' => 'Search' , 'button' => $ this -> icon ( 'search' ) , 'size' => '' , ) , $ form ) ; $ form [ 'method' ] = 'get' ; $ form [ 'action' ] = $ url ; $ input = array ( 'class' => 'form-control' , 'placeholder' => $ form [ 'placeholder' ] ) ; $ button = $ form [ 'button' ] ; $ size = $ form [ 'size' ] ; unset ( $ form [ 'placeholder' ] , $ form [ 'button' ] , $ form [ 'size' ] ) ; $ form = new BPForm ( $ form ) ; $ form -> validator -> set ( $ form -> header [ 'name' ] , 'required' ) ; if ( ! empty ( $ button ) ) { if ( strpos ( $ button , '<button' ) === false ) { $ button = '<button type="submit" class="btn btn-default" title="Search">' . $ button . '</button>' ; } $ html .= '<div class="' . $ this -> prefixClasses ( 'input-group' , array ( 'sm' , 'md' , 'lg' ) , $ size ) . '">' ; $ html .= $ form -> text ( $ form -> header [ 'name' ] , $ input ) ; $ html .= '<div class="input-group-btn">' . $ button . '</div>' ; $ html .= '</div>' ; } else { if ( ! empty ( $ size ) && in_array ( $ size , array ( 'sm' , 'md' , 'lg' ) ) ) { $ input [ 'class' ] .= " input-{$size}" ; } $ html .= $ form -> text ( $ form -> header [ 'name' ] , $ input ) ; } return $ form -> header ( ) . $ html . $ form -> close ( ) ; }
|
This will assist you in creating a search bar for your site .
|
5,829
|
public function icon ( $ symbol , $ prefix = 'glyphicon' , $ tag = 'i' ) { $ base = $ prefix ; $ classes = explode ( ' ' , $ symbol ) ; $ prefix = array ( $ classes [ 0 ] ) ; $ params = '' ; if ( $ space = strpos ( $ tag , ' ' ) ) { $ params = ' ' . trim ( substr ( $ tag , $ space ) ) ; $ tag = substr ( $ tag , 0 , $ space ) ; } if ( $ base == 'glyphicon' ) { $ tag = 'span' ; } return $ this -> addClass ( "<{$tag}{$params}></{$tag}>" , array ( $ tag => $ this -> prefixClasses ( $ base , $ prefix , $ classes ) , ) ) ; }
|
Create an icon without the verbosity .
|
5,830
|
public function button ( $ class , $ name , array $ options = array ( ) ) { $ attributes = array ( 'type' => 'button' ) ; foreach ( $ options as $ key => $ value ) { if ( ! in_array ( $ key , array ( 'dropdown' , 'dropup' , 'active' , 'disabled' , 'pull' ) ) ) { $ attributes [ $ key ] = $ value ; } } $ attributes [ 'class' ] = $ this -> prefixClasses ( 'btn' , array ( 'block' , 'xs' , 'sm' , 'lg' , 'default' , 'primary' , 'success' , 'info' , 'warning' , 'danger' , 'link' ) , $ class ) ; if ( isset ( $ options [ 'dropdown' ] ) || isset ( $ options [ 'dropup' ] ) ) { $ html = '' ; unset ( $ attributes [ 'href' ] ) ; $ class = ( isset ( $ options [ 'dropup' ] ) ) ? 'btn-group dropup' : 'btn-group' ; $ links = ( isset ( $ options [ 'dropup' ] ) ) ? $ options [ 'dropup' ] : $ options [ 'dropdown' ] ; $ html .= '<div class="' . $ class . '">' ; list ( $ dropdown , $ id ) = $ this -> dropdown ( $ links , $ options ) ; if ( is_array ( $ name ) && isset ( $ name [ 'split' ] ) ) { $ html .= $ this -> page -> tag ( 'button' , $ attributes , $ name [ 'split' ] ) ; $ attributes [ 'id' ] = $ id ; $ attributes [ 'class' ] .= ' dropdown-toggle' ; $ attributes [ 'data-toggle' ] = 'dropdown' ; $ attributes [ 'aria-haspopup' ] = 'true' ; $ attributes [ 'aria-expanded' ] = 'false' ; $ html .= $ this -> page -> tag ( 'button' , $ attributes , '<span class="caret"></span>' , '<span class="sr-only">Toggle Dropdown</span>' ) ; } else { $ attributes [ 'id' ] = $ id ; $ attributes [ 'class' ] .= ' dropdown-toggle' ; $ attributes [ 'data-toggle' ] = 'dropdown' ; $ attributes [ 'aria-haspopup' ] = 'true' ; $ attributes [ 'aria-expanded' ] = 'false' ; $ html .= $ this -> page -> tag ( 'button' , $ attributes , $ name , '<span class="caret"></span>' ) ; } $ html .= $ dropdown ; $ html .= '</div>' ; return $ html ; } elseif ( isset ( $ options [ 'href' ] ) ) { unset ( $ attributes [ 'type' ] ) ; return $ this -> page -> tag ( 'a' , $ attributes , $ name ) ; } else { return $ this -> page -> tag ( 'button' , $ attributes , $ name ) ; } }
|
A button by itself is easy enough but when you start including dropdowns and groups your markup can get ugly quick . Follow the examples . We ll start simple and go from there .
|
5,831
|
public function group ( $ class , array $ buttons , $ form = '' ) { $ attributes = array ( 'class' => $ this -> prefixClasses ( 'btn-group' , array ( 'xs' , 'sm' , 'lg' , 'justified' , 'vertical' ) , $ class ) ) ; if ( $ form == 'checkbox' || $ form == 'radio' ) { $ attributes [ 'data-toggle' ] = 'buttons-' . $ form ; } if ( strpos ( $ class , 'justified' ) !== false ) { $ buttons = '<div class="btn-group" role="group">' . implode ( '</div><div class="btn-group" role="group">' , $ buttons ) . '</div>' ; } else { $ buttons = implode ( '' , $ buttons ) ; } $ attributes [ 'role' ] = 'group' ; return $ this -> page -> tag ( 'div' , $ attributes , $ buttons ) ; }
|
Group your buttons together .
|
5,832
|
public function tabs ( array $ links , array $ options = array ( ) ) { $ class = 'nav nav-tabs' ; if ( isset ( $ options [ 'align' ] ) ) { switch ( $ options [ 'align' ] ) { case 'justified' : $ class .= ' nav-justified' ; break ; case 'left' : case 'right' : $ class .= ' pull-' . $ options [ 'align' ] ; break ; } } return $ this -> page -> tag ( 'ul' , array ( 'class' => $ class ) , $ this -> links ( 'li' , $ links , $ options ) ) ; }
|
Creates a Bootstrap tabs nav menu .
|
5,833
|
public function pills ( array $ links , array $ options = array ( ) ) { $ class = 'nav nav-pills' ; if ( isset ( $ options [ 'align' ] ) ) { switch ( $ options [ 'align' ] ) { case 'justified' : $ class .= ' nav-justified' ; break ; case 'vertical' : case 'stacked' : $ class .= ' nav-stacked' ; break ; case 'left' : case 'right' : $ class .= ' pull-' . $ options [ 'align' ] ; break ; } } return $ this -> page -> tag ( 'ul' , array ( 'class' => $ class ) , $ this -> links ( 'li' , $ links , $ options ) ) ; }
|
Creates a Bootstrap pills nav menu .
|
5,834
|
public function breadcrumbs ( array $ links ) { if ( empty ( $ links ) ) { return '' ; } foreach ( $ links as $ name => $ href ) { if ( is_array ( $ href ) ) { list ( $ dropdown , $ id ) = $ this -> dropdown ( $ href ) ; $ link = $ this -> page -> tag ( 'a' , array ( 'href' => '#' , 'data-toggle' => 'dropdown' , 'id' => $ id ) , $ name , '<b class="caret"></b>' ) ; $ links [ $ name ] = '<li class="dropdown">' . $ link . $ dropdown . '</li>' ; } else { $ links [ $ name ] = '<li><a href="' . $ href . '">' . $ name . '</a></li>' ; } if ( $ name === 0 ) { $ name = $ href ; } } array_pop ( $ links ) ; return '<ul class="breadcrumb">' . implode ( ' ' , $ links ) . ' <li class="active">' . $ name . '</li></ul>' ; }
|
Creates a Bootstrap styled breadcrumb trail . The last link is automatically activated .
|
5,835
|
public function alert ( $ type , $ alert , $ dismissable = true ) { $ html = '' ; $ class = 'alert alert-' . $ type ; if ( $ dismissable ) { $ class .= ' alert-dismissable' ; } $ html .= '<div class="' . $ class . '" role="alert">' ; if ( $ dismissable ) { $ html .= '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>' ; } $ html .= $ this -> addClass ( $ alert , array ( 'h([1-6]){1}' => 'alert-heading' , 'a' => 'alert-link' ) ) ; $ html .= '</div>' ; return $ html ; }
|
Creates Bootstrap alert messages .
|
5,836
|
public function progress ( $ percent , $ class = '' , $ display = false ) { $ html = '' ; $ classes = ( array ) $ class ; foreach ( ( array ) $ percent as $ key => $ progress ) { $ class = ( isset ( $ classes [ $ key ] ) ) ? $ classes [ $ key ] : '' ; $ class = $ this -> prefixClasses ( 'progress-bar' , array ( 'success' , 'info' , 'warning' , 'danger' , 'striped' ) , $ class ) ; $ html .= $ this -> page -> tag ( 'div' , array ( 'class' => $ class , 'style' => 'width:' . $ progress . '%;' , 'role' => 'progressbar' , 'aria-valuenow' => $ progress , 'aria-valuemin' => 0 , 'aria-valuemax' => 100 , ) , $ display !== false ? $ progress . '%' : '<span class="sr-only">' . $ progress . '% Complete</span>' ) ; } return '<div class="progress">' . $ html . '</div>' ; }
|
Creates every flavor of progress bar that Bootstrap has to offer .
|
5,837
|
public function panel ( $ class , array $ sections ) { $ html = '' ; foreach ( $ sections as $ panel => $ content ) { if ( ! is_numeric ( $ panel ) ) { $ panel = substr ( $ panel , 0 , 4 ) ; } switch ( ( string ) $ panel ) { case 'head' : $ html .= '<div class="panel-heading">' . $ this -> addClass ( $ content , array ( 'h([1-6]){1}' => 'panel-title' ) ) . '</div>' ; break ; case 'body' : $ html .= '<div class="panel-body">' . $ content . '</div>' ; break ; case 'foot' : $ html .= '<div class="panel-footer">' . $ content . '</div>' ; break ; default : $ html .= $ content ; break ; } } return $ this -> page -> tag ( 'div' , array ( 'class' => $ this -> prefixClasses ( 'panel' , array ( 'default' , 'primary' , 'success' , 'info' , 'warning' , 'danger' ) , $ class ) , ) , $ html ) ; }
|
Creates a Bootstrap panel component .
|
5,838
|
public function accordion ( $ class , array $ sections , $ open = 1 ) { $ html = '' ; $ count = 0 ; $ id = $ this -> page -> id ( 'accordion' ) ; foreach ( $ sections as $ head => $ body ) { ++ $ count ; $ heading = $ this -> page -> id ( 'heading' ) ; $ collapse = $ this -> page -> id ( 'collapse' ) ; $ in = ( $ open == $ count ) ? ' in' : '' ; $ attributes = array ( 'role' => 'button' , 'data-toggle' => 'collapse' , 'data-parent' => '#' . $ id , 'href' => '#' . $ collapse , 'aria-expanded' => ! empty ( $ in ) ? 'true' : 'false' , 'aria-controls' => $ collapse , ) ; $ begin = strpos ( $ head , '>' ) + 1 ; $ end = strrpos ( $ head , '</' ) ; $ head = substr ( $ head , 0 , $ begin ) . $ this -> page -> tag ( 'a' , $ attributes , substr ( $ head , $ begin , $ end - $ begin ) ) . substr ( $ head , $ end ) ; $ head = substr ( $ this -> panel ( $ class , array ( 'head' => $ head ) ) , 0 , - 6 ) ; $ html .= substr_replace ( $ head , ' role="tab" id="' . $ heading . '"' , strpos ( $ head , 'class="panel-heading"' ) + 21 , 0 ) ; $ html .= $ this -> page -> tag ( 'div' , array ( 'id' => $ collapse , 'class' => 'panel-collapse collapse' . $ in , 'role' => 'tabpanel' , 'aria-labelledby' => $ heading , ) , strpos ( $ body , 'class="list-group"' ) ? $ body : '<div class="panel-body">' . $ body . '</div>' ) ; $ html .= '</div>' ; } return $ this -> page -> tag ( 'div' , array ( 'class' => 'panel-group' , 'id' => $ id , 'role' => 'tablist' , 'aria-multiselectable' => 'true' , ) , $ html ) ; }
|
Bootstrap accordions are basically collapsible panels . That is essentially what you are creating here .
|
5,839
|
public function carousel ( array $ images , array $ options = array ( ) ) { $ html = '' ; $ id = $ this -> page -> id ( 'carousel' ) ; $ options = array_merge ( array ( 'interval' => 5000 , 'indicators' => true , 'controls' => true , ) , $ options ) ; if ( $ options [ 'indicators' ] ) { $ indicators = array_keys ( array_values ( $ images ) ) ; $ html .= '<ol class="carousel-indicators">' ; $ html .= '<li data-target="#' . $ id . '" data-slide-to="' . array_shift ( $ indicators ) . '" class="active"></li>' ; foreach ( $ indicators as $ num ) { $ html .= '<li data-target="#' . $ id . '" data-slide-to="' . $ num . '"></li>' ; } $ html .= '</ol>' ; } $ html .= '<div class="carousel-inner" role="listbox">' ; foreach ( $ images as $ key => $ value ) { $ class = ( isset ( $ class ) ) ? 'item' : 'item active' ; $ img = ( ! is_numeric ( $ key ) ) ? $ key : $ value ; $ caption = ( ! is_numeric ( $ key ) ) ? '<div class="carousel-caption">' . $ value . '</div>' : '' ; $ html .= '<div class="' . $ class . '">' . $ img . $ caption . '</div>' ; } $ html .= '</div>' ; if ( $ options [ 'controls' ] ) { if ( is_array ( $ options [ 'controls' ] ) ) { list ( $ left , $ right ) = $ options [ 'controls' ] ; if ( strpos ( $ left , '<' ) === false ) { $ left = $ this -> icon ( $ left , 'glyphicon' , 'span aria-hidden="true"' ) ; } if ( strpos ( $ right , '<' ) === false ) { $ right = $ this -> icon ( $ right , 'glyphicon' , 'span aria-hidden="true"' ) ; } } else { $ left = $ this -> icon ( 'chevron-left' , 'glyphicon' , 'span aria-hidden="true"' ) ; $ right = $ this -> icon ( 'chevron-right' , 'glyphicon' , 'span aria-hidden="true"' ) ; } $ html .= $ this -> page -> tag ( 'a' , array ( 'class' => 'left carousel-control' , 'href' => '#' . $ id , 'role' => 'button' , 'data-slide' => 'prev' , ) , $ left , '<span class="sr-only">Previous</span>' ) ; $ html .= $ this -> page -> tag ( 'a' , array ( 'class' => 'right carousel-control' , 'href' => '#' . $ id , 'role' => 'button' , 'data-slide' => 'next' , ) , $ right , '<span class="sr-only">Next</span>' ) ; } return $ this -> page -> tag ( 'div' , array ( 'id' => $ id , 'class' => 'carousel slide' , 'data-ride' => 'carousel' , 'data-interval' => $ options [ 'interval' ] , ) , $ html ) ; }
|
Creates a Bootstrap carousel for cycling through elements . Those elements don t necessarily need to be images but pretty much they always are .
|
5,840
|
public function setKeyName ( $ keyName ) { $ this -> keyName = ( string ) $ keyName ; $ this -> keyCode = null ; $ this -> charPressed = null ; return $ this ; }
|
Set the key name for triggering the action
|
5,841
|
public function setCharPressed ( $ charPressed ) { $ this -> keyName = null ; $ this -> keyCode = null ; $ this -> charPressed = ( string ) $ charPressed ; return $ this ; }
|
Set the character to press for triggering the action
|
5,842
|
public function boot ( Container $ app ) { $ app -> afterResolving ( function ( Factory $ factory , $ app ) { $ factory -> addExtension ( 'php' , 'php' , function ( ) { return new PhpEngine ( ) ; } ) ; $ factory -> addExtension ( 'blade.php' , 'blade' , function ( ) use ( $ app ) { return new CompilerEngine ( $ app -> make ( BladeCompiler :: class ) ) ; } ) ; $ factory -> addExtension ( 'md' , 'markdown' , function ( ) use ( $ app ) { return new CompilerEngine ( $ app -> make ( Markdown :: class ) ) ; } ) ; } ) ; $ app -> when ( BladeCompiler :: class ) -> needs ( '$cachePath' ) -> give ( vfsStream :: setup ( 'root/.blade' ) -> url ( ) ) ; }
|
Set up the various view engines .
|
5,843
|
public function getData ( $ rp , $ metric , $ tags , $ granularity = 'daily' , $ startDt = null , $ endDt = '2100-12-01T00:00:00Z' , $ timezone = 'UTC' ) { $ points = [ ] ; try { $ pointsRp = $ this -> mapper -> getRpPoints ( $ rp , $ metric , $ tags , $ granularity , $ startDt , $ endDt , $ timezone ) ; $ pointsTmp = $ this -> mapper -> getPoints ( $ metric , $ tags , $ granularity , $ endDt , $ timezone ) ; if ( count ( $ pointsRp ) > 0 || count ( $ pointsTmp ) > 0 ) { $ points = $ this -> combineSumPoints ( $ pointsRp , $ this -> fixTimeForGranularity ( $ pointsTmp , $ granularity ) ) ; } return $ points ; } catch ( Exception $ e ) { throw new AnalyticsException ( "Analytics client period get data exception" , 0 , $ e ) ; } }
|
Get analytics data in right time zone by period and granularity
|
5,844
|
public function getTotal ( $ rp , $ metric , $ tags ) { try { $ todayDt = date ( "Y-m-d" ) . "T00:00:00Z" ; return $ this -> mapper -> getRpSum ( 'forever' , $ metric , $ tags ) + $ this -> mapper -> getRpSum ( $ rp , $ metric , $ tags , $ todayDt ) + $ this -> mapper -> getSum ( $ metric , $ tags ) ; } catch ( Exception $ e ) { throw new AnalyticsException ( "Analytics client get total exception" , 0 , $ e ) ; } }
|
Returns analytics total for right metric
|
5,845
|
private function fixTimeForGranularity ( $ points , $ granularity ) { if ( $ granularity != $ this -> mapper :: GRANULARITY_DAILY ) { return $ points ; } foreach ( $ points as & $ value ) { $ date = substr ( $ value [ 'time' ] , 0 , 10 ) ; $ offset = substr ( $ value [ 'time' ] , - 6 ) ; $ value [ 'time' ] = $ date . "T00:00:00" . $ offset ; } return $ points ; }
|
Fix time part for non - downsampled data
|
5,846
|
private function combineSumPoints ( $ points1 , $ points2 ) { $ pointsCount = count ( $ points1 ) ; $ currPoint = 0 ; foreach ( $ points2 as $ point2 ) { $ pointFound = false ; while ( $ currPoint < $ pointsCount ) { $ point1 = $ points1 [ $ currPoint ] ; if ( $ point1 [ 'time' ] == $ point2 [ 'time' ] ) { $ points1 [ $ currPoint ] [ 'sum' ] += $ point2 [ 'sum' ] ; $ currPoint ++ ; $ pointFound = true ; break ; } $ currPoint ++ ; } if ( ! $ pointFound ) { $ points1 [ ] = $ point2 ; } } return $ points1 ; }
|
Combine downsampled and non - downsampled points
|
5,847
|
public function context ( $ context = null ) { if ( is_null ( $ context ) ) { return $ this -> context ; } $ this -> context = $ context ; return $ this ; }
|
Set field context of exception
|
5,848
|
public function args ( ) { $ this -> args = func_get_args ( ) ; $ params = array_merge ( array ( $ this -> formatMessage ) , $ this -> args ) ; $ this -> message = call_user_func_array ( 'sprintf' , $ params ) ; return $ this ; }
|
Get the arrguments passed and build message by them .
|
5,849
|
public function copy ( $ sourceDir , $ destinyDir ) { $ dir = opendir ( $ sourceDir ) ; $ this -> mkdir ( $ destinyDir ) ; while ( false !== ( $ file = readdir ( $ dir ) ) ) { if ( ( $ file != '.' ) && ( $ file != '..' ) ) { if ( is_dir ( $ sourceDir . '/' . $ file ) ) { $ this -> copy ( $ sourceDir . '/' . $ file , $ destinyDir . '/' . $ file ) ; } else { copy ( $ sourceDir . '/' . $ file , $ destinyDir . '/' . $ file ) ; } } } closedir ( $ dir ) ; }
|
Copy directory to destiny directory
|
5,850
|
public function getDocumentManager ( ) { if ( null === $ this -> dm ) { $ this -> dm = $ this -> getServiceLocator ( ) -> get ( 'doctrine.documentmanager.odm_default' ) ; } return $ this -> dm ; }
|
Retorna o DocumentManager .
|
5,851
|
public static function maker ( $ param , $ param2 = null ) { if ( ! is_null ( $ param2 ) ) { return static :: create ( $ param , $ param2 ) ; } $ param = explode ( ' ' , $ param ) ; $ element = array_shift ( $ param ) ; return static :: create ( $ element , implode ( ' ' , $ param ) ) ; }
|
The maker is like a development shortcut to create html elements on the go
|
5,852
|
public static function attr ( $ attr = array ( ) ) { $ buffer = " " ; foreach ( $ attr as $ key => $ value ) { switch ( $ key ) { case 'class' : if ( is_array ( $ value ) ) { $ value = implode ( ' ' , $ value ) ; } break ; case 'style' : if ( is_array ( $ value ) ) { $ style = $ value ; $ value = "" ; foreach ( $ style as $ k => $ v ) { $ value .= $ k . ':' . $ v . ';' ; } } break ; } $ buffer .= $ key . '="' . $ value . '" ' ; } return substr ( $ buffer , 0 , - 1 ) ; }
|
generates html attribute string
|
5,853
|
public static function tag ( $ name , $ param1 = null , $ param2 = null ) { return static :: create ( $ name , $ param1 , $ param2 ) ; }
|
generates an html tag
|
5,854
|
public function add_class ( $ class ) { if ( ! isset ( $ this -> attr [ 'class' ] ) || ! is_array ( $ this -> attr [ 'class' ] ) ) { $ this -> _sanitize_class ( ) ; } if ( strpos ( $ class , ' ' ) !== false ) { $ class = explode ( ' ' , $ class ) ; } if ( is_string ( $ class ) ) { $ class = array ( $ class ) ; } foreach ( $ class as $ c ) { $ this -> attr [ 'class' ] [ ] = $ c ; } return $ this ; }
|
add html class
|
5,855
|
public function remove_class ( $ class ) { if ( ! isset ( $ this -> attr [ 'class' ] ) || ! is_array ( $ this -> attr [ 'class' ] ) ) { $ this -> _sanitize_class ( ) ; } $ this -> attr [ 'class' ] = array_diff ( $ this -> attr [ 'class' ] , array ( $ class ) ) ; return $ this ; }
|
remove html class
|
5,856
|
private function _sanitize_class ( ) { if ( isset ( $ this -> attr [ 'class' ] ) && is_string ( $ this -> attr [ 'class' ] ) ) { $ this -> attr [ 'class' ] = explode ( ' ' , $ this -> attr [ 'class' ] ) ; } if ( ! isset ( $ this -> attr [ 'class' ] ) || ! is_array ( $ this -> attr [ 'class' ] ) ) { $ this -> attr [ 'class' ] = array ( ) ; } }
|
clean the classes attribute
|
5,857
|
public function getConnectionConfig ( $ name = null ) { if ( is_null ( $ name ) ) { $ name = $ this -> defaultConfigName ; } if ( isset ( $ this -> connectionConfigs [ $ name ] ) ) { return $ this -> connectionConfigs [ $ name ] ; } return null ; }
|
Get connection config .
|
5,858
|
public function getConnection ( $ name = null , $ forceNew = false ) { if ( ! $ forceNew && isset ( $ this -> connections [ $ name ] ) ) { return $ this -> connections [ $ name ] ; } $ config = $ this -> getConnectionConfig ( $ name ) ; if ( ! $ config ) { return null ; } $ pdoArgs = [ $ config [ 'dsn' ] , $ config [ 'username' ] , $ config [ 'password' ] ] ; $ options = [ PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION ] ; if ( isset ( $ config [ 'options' ] ) ) { $ options = $ config [ 'options' ] + $ options ; } $ pdoArgs [ ] = $ options ; $ this -> connections [ $ name ] = new PDO ( ... $ pdoArgs ) ; return $ this -> connections [ $ name ] ; }
|
Get a connection by name .
|
5,859
|
public function parseDate ( $ string ) { try { return new \ DateTime ( $ string ) ; } catch ( ParsingException $ ex ) { $ exception = new ParsingException ( 'The date is ' . 'not parsable' , 0 , $ ex ) ; throw $ exception ; } }
|
parse string expected to be a date and transform to a DateTime object
|
5,860
|
protected function recomposePattern ( array $ terms , array $ supportedTerms , $ domain = NULL ) { $ recomposed = '' ; if ( $ domain !== NULL ) { $ recomposed .= '@' . $ domain . ' ' ; } foreach ( $ supportedTerms as $ term ) { if ( array_key_exists ( $ term , $ terms ) && $ term !== '_default' ) { $ recomposed .= ' ' . $ term . ':' ; $ recomposed .= ( mb_stristr ( ' ' , $ terms [ $ term ] ) === FALSE ) ? $ terms [ $ term ] : '(' . $ terms [ $ term ] . ')' ; } } if ( $ terms [ '_default' ] !== '' ) { $ recomposed .= ' ' . $ terms [ '_default' ] ; } if ( mb_strcut ( $ recomposed , 0 , 1 ) === ' ' ) { $ recomposed = mb_strcut ( $ recomposed , 1 ) ; } return $ recomposed ; }
|
recompose a pattern retaining only supported terms
|
5,861
|
public static function copyFromButtonable ( Buttonable $ tabButtonable ) { $ valueObject = new static ( ) ; $ valueObject -> setButtonLabel ( $ tabButtonable -> getButtonLabel ( ) ) ; $ valueObject -> setFullButtonLabel ( $ tabButtonable -> getFullButtonLabel ( ) ) ; $ valueObject -> setButtonLeftIcon ( $ tabButtonable -> getButtonLeftIcon ( ) ) ; $ valueObject -> setButtonRightIcon ( $ tabButtonable -> getButtonRightIcon ( ) ) ; $ valueObject -> setButtonMode ( $ tabButtonable -> getButtonMode ( ) ) ; return $ valueObject ; }
|
Creates a copy of an Buttonable
|
5,862
|
protected function requirePackage ( Package $ package ) { $ version = $ this -> chooseVersion ( $ package ) ; passthru ( sprintf ( 'composer require %s:%s' , $ package -> getName ( ) , $ version ) ) ; $ this -> comment ( 'Package ' . $ package -> getName ( ) . ' installed' ) ; $ versions = $ package -> getVersions ( ) ; $ v = array_get ( $ versions , $ version ) ; passthru ( sprintf ( 'php artisan package:process %s %s' , $ package -> getName ( ) , base64_encode ( serialize ( $ v ) ) ) ) ; }
|
Installs package .
|
5,863
|
protected function searchPackage ( $ packageName ) { $ this -> comment ( 'Searching for package...' ) ; $ packages = $ this -> packagist -> search ( $ packageName ) ; $ total = count ( $ packages ) ; if ( $ total === 0 ) { $ this -> comment ( 'No packages found' ) ; exit ; } $ this -> comment ( 'Found ' . $ total . ' packages:' ) ; foreach ( $ packages as $ i => $ package ) { $ this -> getOutput ( ) -> writeln ( sprintf ( '[%d] <info>%s</info> (%s)' , $ i + 1 , $ package -> getName ( ) , $ package -> getDescription ( ) ) ) ; } $ this -> choosePackage ( $ packages ) ; }
|
Perform search on packagist and ask package select .
|
5,864
|
protected function choosePackage ( $ packages ) { $ choose = $ this -> ask ( 'Select package by number [1]:' , '1' ) ; if ( ! is_numeric ( $ choose ) or ! isset ( $ packages [ $ choose - 1 ] ) ) { $ this -> error ( 'Incorrect value given!' ) ; $ this -> choosePackage ( $ packages ) ; } else { $ index = $ choose - 1 ; $ result = $ packages [ $ index ] ; $ this -> comment ( 'Your choice: ' . $ result -> getName ( ) ) ; $ package = $ this -> getPackage ( $ result -> getName ( ) ) ; } }
|
Ask package select from a list .
|
5,865
|
protected function buildParams ( array $ params ) { $ normalizedParameters = array ( ) ; foreach ( $ params as $ parameter ) { if ( $ parameter instanceof GeneratorInstance ) { $ normalizedParameters [ ] = sprintf ( '$di->get(%s)' , '\'' . $ parameter -> getName ( ) . '\'' ) ; } else { $ normalizedParameters [ ] = var_export ( $ parameter , true ) ; } } return $ normalizedParameters ; }
|
Generates parameter strings to be used as injections replacing reference parameters with their respective getters
|
5,866
|
public function execAction ( Request $ request ) { ignore_user_abort ( true ) ; set_time_limit ( 0 ) ; $ this -> get ( 'anime_db.command' ) -> execute ( $ request -> get ( 'command' ) , 0 ) ; return new Response ( ) ; }
|
Execute command in background .
|
5,867
|
public function beforeMarshal ( Event $ event , \ ArrayObject $ data , \ ArrayObject $ options ) { $ this -> _prepareParamsData ( $ data ) ; }
|
Callback before request data is converted into entities .
|
5,868
|
protected function _prepareParamsData ( \ ArrayObject $ data ) { if ( isset ( $ data [ 'params' ] ) ) { $ params = new JSON ( ( array ) $ data [ 'params' ] ) ; $ data -> offsetSet ( 'params' , $ params ) ; } }
|
Prepare params data .
|
5,869
|
public function boot ( ) { $ registryServiceName = 'service_provider_registry_' . $ this -> id ; $ this -> container -> set ( $ registryServiceName , $ this -> getRegistry ( $ this -> container ) ) ; }
|
At boot time let s fill the container with the registry .
|
5,870
|
public function getSessions ( ) { $ sessions = array ( ) ; $ result = $ this -> curl ( 'GET' , '/sessions' ) ; foreach ( $ result [ 'value' ] as $ session ) { $ sessions [ ] = new WebDriverSession ( $ this -> url . '/session/' . $ session [ 'id' ] ) ; } return $ sessions ; }
|
get a list of active sessions
|
5,871
|
public function getSize ( $ path ) { $ location = $ this -> applyPathPrefix ( $ path ) ; $ response = $ this -> ossClient -> getObjectMeta ( $ this -> bucket , $ location ) ; return [ 'size' => $ response [ 'content-length' ] ] ; }
|
Get the size of a file .
|
5,872
|
public static function charset ( $ charset = null ) { switch ( $ charset ) { case 'pass' : case 'secure' : case 'password' : return static :: SECURE ; break ; case 'key' : return static :: KEY ; break ; case 'alphanum' : return static :: ALPHA_NUM ; break ; case 'alpha' : return static :: ALPHA ; break ; case 'alpha_low' : case 'lowercase' : return static :: ALPHA_LOW ; break ; case 'alpha_up' : case 'uppercase' : return static :: ALPHA_UP ; break ; case 'numeric' : case 'num' : return static :: NUM ; break ; case 'hex' : return static :: HEX ; break ; case 'bin' : return static :: BIN ; break ; default : if ( ! is_null ( $ charset ) ) { return $ charset ; } return static :: charset ( 'alphanum' ) ; break ; } }
|
Get a charset a string containing a set of characters .
|
5,873
|
public static function random ( $ length = 25 , $ charset = null ) { $ charset = static :: charset ( $ charset ) ; $ count = strlen ( $ charset ) ; $ string = '' ; while ( $ length -- ) { $ string .= $ charset [ mt_rand ( 0 , $ count - 1 ) ] ; } return $ string ; }
|
Generate a random string with the given length and charset .
|
5,874
|
public static function capture ( $ callback , $ params = array ( ) ) { if ( is_string ( $ callback ) ) { return $ callback ; } if ( ! is_closure ( $ callback ) ) { return "" ; } if ( ! is_array ( $ params ) ) { $ params = array ( $ params ) ; } ob_start ( ) ; $ return = call_user_func_array ( $ callback , $ params ) ; $ buffer = ob_get_clean ( ) ; if ( ! is_null ( $ return ) ) { return $ return ; } return $ buffer ; }
|
Try to get a string from a callback reading the output buffer
|
5,875
|
public static function htmlentities ( $ string , $ recursive = false ) { if ( is_array ( $ string ) ) { foreach ( $ string as $ key => $ item ) { if ( $ recursive ) { if ( is_array ( $ item ) ) { $ string [ $ key ] = static :: htmlentities ( $ item , $ recursive ) ; } } if ( is_string ( $ item ) ) { $ string [ $ key ] = htmlentities ( $ item ) ; } } return $ string ; } return htmlentities ( $ string , ENT_QUOTES , ClanCats :: $ config -> charset ) ; }
|
Does the same as the PHP native htmlentities function but you can pass arrays .
|
5,876
|
public static function suffix ( $ string , $ sep = '-' ) { return substr ( $ string , strrpos ( $ string , $ sep ) + strlen ( $ sep ) ) ; }
|
Get the last part of a string
|
5,877
|
public static function clean_url ( $ string , $ sep = null ) { $ string = strtolower ( static :: replace_accents ( trim ( $ string ) ) ) ; $ string = str_replace ( array ( ' ' , '&' , '\r\n' , '\n' , '+' , ',' , '.' , '_' ) , '-' , $ string ) ; $ string = preg_replace ( array ( '/[^a-z0-9\-]/' , '/[\-]+/' , ) , array ( '' , '-' ) , $ string ) ; if ( ! is_null ( $ sep ) ) { $ string = str_replace ( '-' , $ sep , $ string ) ; } return trim ( $ string , '-' ) ; }
|
Try to form a string to url valid segment . It will remove all special characters replace accents characters remove and replace whitespaces breaks etc ..
|
5,878
|
public static function replace ( $ string , $ arr , $ count = null ) { return str_replace ( array_keys ( $ arr ) , array_values ( $ arr ) , $ string , $ count ) ; }
|
str_replace using key = > value of an array
|
5,879
|
public static function preg_replace ( $ arr , $ string , $ count = null ) { return preg_replace ( array_keys ( $ arr ) , array_values ( $ arr ) , $ string , $ count ) ; }
|
preg replace using key = > value of an array
|
5,880
|
public static function lower ( $ string , $ encoding = null ) { if ( is_null ( $ encoding ) ) { $ encoding = ClanCats :: $ config -> charset ; } return mb_strtolower ( $ string , $ encoding ) ; }
|
Converts an string to lowercase using the system encoding
|
5,881
|
public static function upper ( $ string , $ encoding = null ) { if ( is_null ( $ encoding ) ) { $ encoding = ClanCats :: $ config -> charset ; } return mb_strtoupper ( $ string , $ encoding ) ; }
|
Converts an string to uppercase using the system encoding
|
5,882
|
public static function cut ( $ string , $ key , $ cut_key = true , $ last = false ) { if ( $ last ) { $ pos = strrpos ( $ string , $ key ) ; } else { $ pos = strpos ( $ string , $ key ) ; } if ( $ pos === false ) { return $ string ; } if ( ! $ cut_key ) { $ pos += strlen ( $ key ) ; } return substr ( $ string , 0 , $ pos ) ; }
|
Cuts a string after another string .
|
5,883
|
public static function bytes ( $ size , $ round = 2 ) { $ unit = array ( 'b' , 'kb' , 'mb' , 'gb' , 'tb' , 'pb' ) ; return @ round ( $ size / pow ( 1024 , ( $ i = floor ( log ( $ size , 1024 ) ) ) ) , $ round ) . $ unit [ $ i ] ; }
|
Convert bytes to a human readable format
|
5,884
|
public function localize ( array $ translatableStrings ) { if ( NULL === $ translatableStrings ) { return NULL ; } $ language = $ this -> requestStack -> getCurrentRequest ( ) -> getLocale ( ) ; if ( isset ( $ translatableStrings [ $ language ] ) ) { return $ translatableStrings [ $ language ] ; } else { foreach ( $ this -> fallbackLocales as $ locale ) { if ( array_key_exists ( $ locale , $ translatableStrings ) ) { return $ translatableStrings [ $ locale ] ; } } } return '' ; }
|
return the string in current locale if it exists .
|
5,885
|
public function increment ( $ key , $ delta = 1 ) { if ( $ this -> has ( $ key ) ) { $ this -> set ( $ key , $ this -> get ( $ key ) + $ delta ) ; } else { $ this -> set ( $ key , $ delta ) ; } return $ this ; }
|
Increment the value stored at the given key by the given delta .
|
5,886
|
public function declareCreation ( string $ table , array $ columns ) { $ source = $ this -> method ( 'up' ) -> getSource ( ) ; $ source -> addLine ( "\$this->table('{$table}')" ) ; foreach ( $ columns as $ name => $ type ) { $ source -> addLine ( " ->addColumn('{$name}', '{$type}')" ) ; } $ source -> addLine ( " ->create();" ) ; $ this -> method ( 'down' ) -> getSource ( ) -> addString ( "\$this->table('{$table}')->drop();" ) ; }
|
Declare table creation with specific set of columns
|
5,887
|
public function apply ( $ method , array $ args = [ ] ) { $ result = new Map ; $ this -> walk ( function ( $ object , $ key ) use ( $ method , $ args , $ result ) { $ result [ $ key ] = call_user_func_array ( [ $ object , $ method ] , $ args ) ; } ) ; return $ result ; }
|
Call the given method on every object in the map and return the results as a new map .
|
5,888
|
public function addFeature ( FeatureInterface $ feature ) { $ this -> features -> set ( $ feature -> getKey ( ) , $ feature ) ; return $ this ; }
|
Add a feature to the container
|
5,889
|
protected function assignUserToUserGroups ( User $ user , array $ userGroupObjects ) { $ ezUserGroups = [ ] ; foreach ( $ userGroupObjects as $ userGroup ) { $ userGroup = $ this -> userGroupManager -> createOrUpdate ( $ userGroup ) ; if ( $ userGroup instanceof UserGroupObject ) { $ ezUserGroup = $ this -> userGroupManager -> find ( $ userGroup ) ; if ( $ ezUserGroup ) { $ ezUserGroups [ $ ezUserGroup -> id ] = $ ezUserGroup ; try { $ this -> userService -> assignUserToUserGroup ( $ user , $ ezUserGroup ) ; } catch ( InvalidArgumentException $ alreadyAssignedException ) { } } } } return $ ezUserGroups ; }
|
Assigns a collection of Transfer user groups from an eZ user and returns the once who were added .
|
5,890
|
protected function unassignUserFromUserGroups ( User $ user , array $ userGroups ) { $ existingUserGroups = $ this -> userService -> loadUserGroupsOfUser ( $ user ) ; foreach ( $ existingUserGroups as $ existingUserGroup ) { if ( ! array_key_exists ( $ existingUserGroup -> id , $ userGroups ) ) { $ this -> userService -> unAssignUserFromUserGroup ( $ user , $ existingUserGroup ) ; } } }
|
Unassigns a collection of eZ UserGroups from an eZ User .
|
5,891
|
public function request ( $ method , $ endpoint , array $ parameters = null ) { $ url = $ this -> config -> getEndpoint ( ) . $ endpoint ; $ headers = array ( 'Authorization' => 'Bearer ' . $ this -> config -> getAccessToken ( ) ) ; return $ this -> client -> request ( $ method , $ url , $ parameters , $ headers ) ; }
|
Send an authenticated api request
|
5,892
|
public function log ( $ message , $ flag ) { $ headers = [ 'token' => $ this -> token , ] ; $ query = $ this -> processLog ( $ message , $ flag ) ; $ response = $ this -> curl :: post ( $ this -> missionControlUrl , $ headers , $ query ) ; if ( $ response -> code != 200 ) { $ this -> error ( 'Unable to message Mission Control, please confirm your token' ) ; } return true ; }
|
Send the log to Mission Control
|
5,893
|
protected function baseRequest ( ) { return [ 'report_referer' => $ this -> server ( 'HTTP_REFERER' , '' ) , 'report_user_agent' => $ this -> server ( 'HTTP_USER_AGENT' , '' ) , 'report_host' => $ this -> server ( 'HTTP_HOST' , '' ) , 'report_server_name' => $ this -> server ( 'SERVER_NAME' , '' ) , 'report_remote_addr' => $ this -> server ( 'REMOTE_ADDR' , '' ) , 'report_server_software' => $ this -> server ( 'SERVER_SOFTWARE' , '' ) , 'report_uri' => $ this -> server ( 'REQUEST_URI' , '' ) , 'report_time' => $ this -> server ( 'REQUEST_TIME' , '' ) , 'report_method' => $ this -> server ( 'REQUEST_METHOD' , '' ) , 'report_query' => $ this -> server ( 'QUERY_STRING' , '' ) , 'app_base' => $ this -> server ( 'DOCUMENT_ROOT' , '' ) , ] ; }
|
Collect basic server info
|
5,894
|
public function addFieldDefinitionObject ( $ identifier , $ fieldDefinition ) { $ this -> data [ 'fields' ] [ $ identifier ] = $ this -> convertToFieldDefintionObject ( $ identifier , $ fieldDefinition ) ; }
|
Convert parameters to FieldDefinitionObject and stores it on the ContentTypeObject .
|
5,895
|
private function setMissingDefaults ( ) { if ( ! isset ( $ this -> data [ 'contenttype_groups' ] ) ) { $ this -> data [ 'contenttype_groups' ] = array ( 'Content' ) ; } if ( $ this -> notSetOrEmpty ( $ this -> data , 'names' ) ) { $ this -> data [ 'names' ] = array ( $ this -> data [ 'main_language_code' ] => $ this -> identifierToReadable ( $ this -> data [ 'identifier' ] ) , ) ; } foreach ( array ( 'name_schema' , 'url_alias_schema' ) as $ schema ) { if ( $ this -> notSetOrEmpty ( $ this -> data , $ schema ) ) { $ this -> data [ $ schema ] = sprintf ( '<%s>' , $ this -> data [ 'fields' ] [ key ( $ this -> data [ 'fields' ] ) ] -> data [ 'identifier' ] ) ; } } }
|
Build default values .
|
5,896
|
function removeTeam ( $ competitionId , $ teamId ) { if ( ! $ competitionId ) { throw new Exception ( 'Invalid competitionId' ) ; } if ( ! $ teamId ) { throw new Exception ( 'Invalid teamId' ) ; } return $ this -> execute ( 'DELETE' , '/competitions/%d/teams/%d/' , array ( $ competitionId , $ teamId ) ) ; }
|
Works only during the registration phase
|
5,897
|
function registerResults ( $ competitionId , array $ results ) { if ( ! $ competitionId ) { throw new Exception ; } if ( ! $ results ) { throw new Exception ; } return $ this -> execute ( 'POST' , '/competitions/%d/results/' , array ( $ competitionId , array ( $ results ) ) ) ; }
|
Register final results of your competition
|
5,898
|
public function del ( $ cookie ) { if ( empty ( $ cookie ) ) throw new CookieException ( "Invalid cookie object or name" ) ; $ name = ( $ cookie instanceof CookieInterface ) ? $ cookie -> getName ( ) : $ cookie ; if ( $ this -> isRegistered ( $ name ) ) { unset ( $ this -> cookies [ $ name ] ) ; } else { throw new CookieException ( "Cookie is not registered" ) ; } return $ this ; }
|
Delete a cookie from the stack
|
5,899
|
public function has ( $ cookie ) { if ( empty ( $ cookie ) ) throw new CookieException ( "Invalid cookie object or name" ) ; $ name = ( $ cookie instanceof CookieInterface ) ? $ cookie -> getName ( ) : $ cookie ; return array_key_exists ( $ name , $ this -> cookies ) ; }
|
Check if a cookie is into the stack
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.