idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
33,900
public function usedVATOnDate ( $ date ) { $ period = $ this -> getPeriod ( $ date ) ; return ! is_null ( $ period ) && ! empty ( $ period -> getStandardRate ( ) ) ; }
Did this country use VAT on the given date .
33,901
public function getIndex ( ) { $ front_page = config ( 'mustard.front_page' , '/buy' ) ; if ( view ( ) -> exists ( config ( 'mustard.front_page' ) ) ) { return view ( config ( 'mustard.front_page' ) ) ; } session ( ) -> reflash ( ) ; return mustard_redirect ( config ( 'mustard.front_page' ) ) ; }
Redirect index requests or return view .
33,902
protected function normalizeKey ( $ key ) { if ( preg_match ( static :: $ arrayKey , $ key , $ matches ) ) { $ key = $ matches [ 1 ] ; return $ key ; } return $ key ; }
Return a key that can be used on the current subject .
33,903
public function getAjaxBlockAction ( Request $ request , $ _ajaxController ) { $ response = new Response ( ) ; $ response -> headers -> set ( 'Content-Type' , 'application/json' ) ; try { list ( $ controllerParams , $ controllerQuery ) = $ this -> getControllerParams ( $ request , $ _ajaxController ) ; $ controllerResponse = $ this -> forward ( $ _ajaxController , $ controllerParams , $ controllerQuery ) ; $ responseContent = array ( 'block' => $ controllerResponse -> getContent ( ) , ) ; } catch ( AjaxBlocksException $ ex ) { $ responseContent = array ( 'error' => array ( 'code' => $ ex -> getCode ( ) , 'error' => $ ex -> getMessage ( ) , ) , ) ; $ response -> setStatusCode ( 406 ) ; } catch ( \ Exception $ ex ) { $ responseContent = array ( 'error' => array ( 'code' => AjaxBlocksErrorCodes :: UNKNOWN_EXCEPTION , 'error' => get_class ( $ ex ) . '(' . $ ex -> getCode ( ) . '): ' . $ ex -> getMessage ( ) , ) , ) ; $ response -> setStatusCode ( 500 ) ; } $ response -> setContent ( json_encode ( $ responseContent ) ) ; return $ response ; }
Gets a request for an ajax block and calls the right controller to build it
33,904
private function getControllerParams ( Request $ request , $ controllerString ) { $ query = $ request -> query -> all ( ) ; $ methodParameters = $ this -> getControllerParameters ( $ controllerString ) ; $ parameters = array ( ) ; foreach ( $ methodParameters as $ methodParameter ) { $ parameterName = $ methodParameter -> getName ( ) ; if ( 'request' === $ parameterName ) continue ; if ( isset ( $ query [ $ parameterName ] ) ) { $ parameters [ $ parameterName ] = $ query [ $ parameterName ] ; unset ( $ query [ $ parameterName ] ) ; } } return array ( $ parameters , $ query ) ; }
Searches in the request for the parameters required by the destination controller
33,905
private function getControllerParameters ( $ controllerString ) { $ controllerInfo = explode ( ':' , $ controllerString ) ; if ( count ( $ controllerInfo ) !== 3 ) { throw new AjaxBlocksException ( "$controllerString is not a correct controller name." , AjaxBlocksErrorCodes :: WRONG_CONTROLLER_NAME ) ; } try { $ bundle = $ this -> get ( 'kernel' ) -> getBundle ( $ controllerInfo [ 0 ] ) ; } catch ( \ Exception $ ex ) { throw new AjaxBlocksException ( "Bundle \"$controllerInfo[0]\" does not exist or is not loaded." , AjaxBlocksErrorCodes :: BUNDLE_DOES_NOT_EXIST ) ; } $ namespace = $ bundle -> getNamespace ( ) ; $ controllerName = $ controllerInfo [ 1 ] . 'Controller' ; $ controllerMethod = $ controllerInfo [ 2 ] . 'Action' ; $ className = $ namespace . '\\Controller\\' . $ controllerName ; if ( ! class_exists ( $ className ) ) { throw new AjaxBlocksException ( "Class \"$className\" does not exist." , AjaxBlocksErrorCodes :: CONTROLLER_CLASS_DOES_NOT_EXISTS ) ; } $ reflectionClass = new \ ReflectionClass ( $ className ) ; if ( ! $ reflectionClass -> hasMethod ( $ controllerMethod ) ) { throw new AjaxBlocksException ( "Class \"$className\" does not have a method called \"$controllerMethod\"." , AjaxBlocksErrorCodes :: CONTROLLER_CLASS_METHOD_DOES_NOT_EXISTS ) ; } $ controller = $ reflectionClass -> getMethod ( $ controllerMethod ) ; if ( ! $ controller -> isPublic ( ) ) { throw new AjaxBlocksException ( "Method \"$controllerMethod\" of class \"$className\" is not public or is not callable." , AjaxBlocksErrorCodes :: CONTROLLER_IS_NOT_CALLABLE ) ; } return $ controller -> getParameters ( ) ; }
Get the parameters for the requested controller
33,906
public function connect ( ) { if ( $ this -> connection -> isOpened ( ) ) { throw new LogicException ( 'It is not possible to re-open the connection to the EPP server.' ) ; } $ this -> connection -> open ( ) ; $ xml = $ this -> connection -> read ( ) ; $ this -> logger -> info ( 'Greeting on connection to the EPP server.' , [ 'body' => $ xml ] ) ; $ greeting = new Greeting ( $ xml ) ; if ( ! $ greeting -> isSuccess ( ) ) { throw new ConnectionException ( 'Invalid greeting on connection to the EPP server.' ) ; } return $ greeting ; }
Opening the connection to the EPP server .
33,907
public function send ( RequestInterface $ request ) { if ( ! $ this -> connection -> isOpened ( ) ) { throw new LogicException ( 'Cannot send request to the not open connection. Call connect() before send().' ) ; } if ( ! $ request -> isBuilt ( ) ) { $ request -> build ( ) ; } $ requestXML = $ request -> saveXML ( ) ; $ this -> logger -> info ( 'EPP request body.' , [ 'body' => $ requestXML ] ) ; $ this -> connection -> write ( $ requestXML ) ; $ responseXML = $ this -> connection -> read ( ) ; $ this -> logger -> info ( 'EPP response body.' , [ 'body' => $ responseXML ] ) ; $ responseClass = $ request -> getResponseClass ( ) ; $ response = new $ responseClass ( $ responseXML ) ; foreach ( $ this -> extensionStack as $ extension ) { $ this -> logger -> debug ( sprintf ( 'Handle response in \'%s\' extension.' , get_class ( $ extension ) ) ) ; $ extension -> handleResponse ( $ response ) ; } return $ response ; }
Send EPP request .
33,908
public function pushExtension ( ExtensionInterface $ extension ) { array_unshift ( $ this -> extensionStack , $ extension ) ; $ extension -> setupNamespaces ( $ this ) ; return $ this ; }
Add extension in stack .
33,909
public function run ( $ request ) { $ units = array ( 'seconds' , 'hours' , 'minutes' , 'days' , 'weeks' , 'months' , 'years' ) ; $ unit = $ request -> requestVar ( 'unit' ) ; if ( ! $ unit || ! in_array ( $ unit , $ units ) ) { throw new RuntimeException ( "Please specify a 'unit' parameter. Possible values: " . implode ( ', ' , $ units ) ) ; } $ count = $ request -> requestVar ( 'count' ) ; if ( ! $ count ) { throw new RuntimeException ( "Please specify a 'count' parameter for the number of $unit you want to to keep." ) ; } $ stamp = strtotime ( "-{$count} $unit" ) ; $ date = date ( 'Y-m-d H:i:s' ) ; $ count = SentEmail :: get ( ) -> filter ( array ( 'Created:LessThan' => $ date ) ) -> count ( ) ; DB :: query ( "DELETE FROM \"SentEmail\" WHERE Created < '$date'" ) ; echo "Deleted $count records." ; }
Execute the task
33,910
public function compose ( $ toEmail , $ toName , $ subject , $ view , array $ data = array ( ) , $ options = null ) { $ this -> toEmail = $ toEmail ; $ this -> toName = $ toName ; $ this -> subject = $ subject ; $ this -> view = $ view ; $ this -> data = $ data ; $ this -> options = $ options ; return $ this ; }
Compose an activation mail .
33,911
protected function prepareField ( array $ data ) { return array_merge ( [ 'default' => null , 'position' => 0 , 'flash' => true , 'validate' => [ ] , 'label' => null , 'label_options' => [ ] , 'comment' => null , 'type' => 'text' , 'name' => null , 'value' => null , 'options' => [ 'id' => null ] , 'resource' => null , 'use_default' => false , ] , $ data ) ; }
Merge field defaults
33,912
protected function biteTongueOnTwitter ( $ phrase ) { if ( mb_strlen ( $ this -> whisper ) <= 140 ) { return $ this -> whisper ; } $ phraseLength = mb_strlen ( $ phrase ) ; $ numberToRemove = ( int ) ceil ( abs ( $ phraseLength - ( 140 / 3 ) ) ) ; $ removed = 0 ; $ words = preg_split ( '/\s+/' , $ phrase ) ; while ( $ removed < $ numberToRemove ) { foreach ( $ words as $ index => $ word ) { if ( mb_strlen ( $ words [ $ index ] ) <= 3 ) { $ removed ++ ; continue ; } $ words [ $ index ] = substr_replace ( $ words [ $ index ] , '' , rand ( 1 , mb_strlen ( $ words [ $ index ] ) - 2 ) , 1 ) ; $ removed ++ ; if ( $ removed == $ numberToRemove ) { break ; } } } return $ this -> speaks ( implode ( ' ' , $ words ) ) ; }
Hacky implementation detail to clamp Zalgo text to 140 characters when it is in a mood for Twitter .
33,913
public static function _wrapStart ( $ callee ) { $ uid = isset ( $ callee [ 'file' ] ) ? crc32 ( $ callee [ 'file' ] . $ callee [ 'line' ] ) : 'no-file' ; if ( isset ( self :: $ _usedColors [ $ uid ] ) ) { $ class = self :: $ _usedColors [ $ uid ] ; } else { $ class = sizeof ( self :: $ _usedColors ) ; self :: $ _usedColors [ $ uid ] = $ class ; } $ class = "kint_{$class}" ; return "<div class=\"kint {$class}\">" ; }
called for each dump opens the html tag
33,914
protected function processClassStatement ( Class_ $ statement , string $ prefix , array $ uses = [ ] ) : void { $ class = $ statement ; $ fullClassName = $ prefix . '\\' . ( string ) $ class -> name ; $ this -> classes [ $ fullClassName ] = [ 'file' => $ this -> file , 'line' => $ class -> getAttribute ( 'startLine' ) , 'name' => $ fullClassName , 'docblock' => $ this -> getDocBlock ( $ class , $ uses ) , ] ; foreach ( $ statement -> stmts as $ method ) { if ( ! ( $ method instanceof ClassMethod ) ) { continue ; } $ this -> processClassMethod ( $ method , $ fullClassName , $ uses ) ; } }
Process class statements .
33,915
protected function processClassMethod ( ClassMethod $ method , string $ fullClassName , array $ uses = [ ] ) : void { $ fullMethodName = $ fullClassName . '::' . $ method -> name ; $ type = $ method -> returnType ; if ( $ type instanceof NullableType ) { $ type = [ 'null' , $ this -> mapClassAndNamespace ( $ uses , ( string ) $ type -> type ) ] ; sort ( $ type ) ; } else { if ( ! is_null ( $ type ) ) { $ type = ( string ) $ type ; } } $ type = $ this -> mapClassAndNamespace ( $ uses , $ type ) ; $ thisMethod = [ 'file' => $ this -> file , 'class' => $ fullClassName , 'name' => $ fullMethodName , 'line' => $ method -> getAttribute ( 'startLine' ) , 'return' => $ type , 'params' => [ ] , 'docblock' => $ this -> getDocBlock ( $ method , $ uses ) , ] ; foreach ( $ method -> params as $ param ) { $ type = $ this -> getClassMethodReturnType ( $ param , $ uses ) ; if ( ! isset ( $ param -> var ) ) { throw new RuntimeException ( 'Access to an undefined property PhpParser\Node\Param::$var' ) ; } if ( ! isset ( $ param -> var -> name ) ) { throw new RuntimeException ( 'Access to an undefined property PhpParser\Node\Param::$var->$name' ) ; } if ( ! is_string ( $ param -> var -> name ) ) { throw new RuntimeException ( 'Access to invalid property PhpParser\Node\Param::$var->$name' ) ; } $ thisMethod [ 'params' ] [ '$' . $ param -> var -> name ] = $ type ; } $ this -> methods [ $ fullMethodName ] = $ thisMethod ; }
Process class method .
33,916
protected function processDocBlock ( $ text , array $ uses = [ ] ) : array { $ parser = new DocBlockParser ( $ text ) ; $ rtn = [ 'params' => [ ] , 'return' => null , 'inheritdoc' => false , ] ; if ( isset ( $ parser -> tags [ 'param' ] ) ) { $ rtn = $ this -> processDocBlockParams ( $ parser -> tags [ 'param' ] , $ uses , $ rtn ) ; } if ( isset ( $ parser -> tags [ 'return' ] ) ) { $ rtn [ 'return' ] = $ this -> getDocBlockReturnType ( $ parser -> tags [ 'return' ] , $ uses ) ; } if ( stripos ( $ parser -> comment , '@inheritdoc' ) !== false ) { $ rtn [ 'inheritdoc' ] = true ; } return $ rtn ; }
Use Paul Scott s docblock parser to parse a docblock then return the relevant parts .
33,917
protected function updateEntity ( Entity $ entity ) { $ action = \ Schema :: hasTable ( $ entity -> getTable ( ) ) ? 'update' : 'create' ; $ this -> migrations [ $ action ] [ $ entity -> getTable ( ) ] [ 'cols' ] = $ this -> buildTable ( $ entity ) ; if ( $ action == 'create' && $ entity -> timestamps ) $ this -> migrations [ $ action ] [ $ entity -> getTable ( ) ] [ 'cols' ] [ ] = '$table->timestamps();' ; }
Update the entity
33,918
protected function buildTable ( Entity $ entity ) { $ attributes = $ this -> prepareRelationships ( $ entity ) + $ entity -> getAttributeConfig ( ) ; foreach ( event ( new SchemaPrepare ( $ entity ) ) as $ attrs ) { foreach ( ( array ) $ attrs as $ key => $ value ) { $ attributes [ $ key ] = $ this -> applyAttributeDefaults ( $ value ) ; } } return $ this -> addAttributes ( $ entity -> getTable ( ) , $ attributes ) ; }
Build our table
33,919
public function run ( ) { $ this -> timer = new Timer ( $ this -> name , true ) ; if ( ! is_callable ( $ this -> callback ) ) { throw new \ RuntimeException ( 'No callback provided' ) ; } call_user_func ( $ this -> callback ) ; $ this -> timer -> tick ( ) ; }
Execute the callback function
33,920
public function account ( $ mustInit = true ) { if ( $ mustInit ) $ this -> _init ( ) ; $ params = array ( 'api' => $ this -> api_key , ) ; $ query = http_build_query ( $ params ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , Config :: get ( 'semaphore::url.sms.account' ) . '?' . $ query ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; return $ response ; }
Check account balance and status
33,921
private function registerCourier ( ) { $ this -> app -> bind ( 'CodeZero\Courier\Courier' , function ( $ app ) { $ curlRequest = $ app -> make ( 'CodeZero\Curl\Request' ) ; $ responseParser = $ app -> make ( 'CodeZero\Courier\CurlResponseParser' ) ; $ cache = $ app -> make ( 'CodeZero\Courier\Cache\Cache' ) ; return new CurlCourier ( $ curlRequest , $ responseParser , $ cache ) ; } ) ; }
Register the courier service binding
33,922
private function sendMessage ( ) { try { $ this -> mailer -> send ( $ this -> message_layout -> getViewLayout ( ) , $ this -> message_layout -> getMessageVariables ( ) , function ( $ message ) { if ( config ( 'pigeon.dev.override' ) ) { $ message -> to ( config ( 'pigeon.dev.override_email' ) ) ; } else { $ message -> to ( $ this -> to ) ; } $ message -> subject ( $ this -> subject ) -> cc ( $ this -> cc ) -> bcc ( $ this -> bcc ) -> replyTo ( $ this -> reply_to ) -> sender ( $ this -> sender ) ; if ( ! empty ( $ this -> from ) ) { $ message -> from ( $ this -> from ) ; } foreach ( $ this -> attachments as $ a ) { $ message -> attach ( $ a [ 'path' ] , $ a [ 'options' ] ) ; } } ) ; } catch ( ErrorException $ e ) { $ msg = 'Pigeon could not send message: ' . $ e -> getMessage ( ) ; $ this -> logger -> error ( $ msg ) ; return false ; } catch ( \ Swift_TransportException $ e ) { $ msg = 'SMTP failure: ' . $ e -> getMessage ( ) ; $ this -> logger -> error ( $ msg ) ; return false ; } return true ; }
Send Message with View
33,923
private function sendRawMessage ( $ message ) { try { $ this -> mailer -> raw ( $ message , function ( $ message ) { if ( config ( 'pigeon.dev.override' ) ) { $ message -> to ( config ( 'pigeon.dev.override_email' ) ) ; } else { $ message -> to ( $ this -> to ) ; } $ message -> subject ( $ this -> subject ) -> cc ( $ this -> cc ) -> bcc ( $ this -> bcc ) -> replyTo ( $ this -> reply_to ) -> sender ( $ this -> sender ) ; if ( ! empty ( $ this -> from ) ) { $ message -> from ( $ this -> from ) ; } foreach ( $ this -> attachments as $ a ) { $ message -> attach ( $ a [ 'path' ] , $ a [ 'options' ] ) ; } } ) ; } catch ( ErrorException $ e ) { $ msg = 'Pigeon could not send message: ' . $ e -> getMessage ( ) ; $ this -> logger -> error ( $ msg ) ; return false ; } catch ( \ Swift_TransportException $ e ) { $ msg = 'SMTP failure: ' . $ e -> getMessage ( ) ; $ this -> logger -> error ( $ msg ) ; return false ; } return true ; }
Send Raw Message
33,924
public static function isArrayable ( $ value ) { if ( $ value instanceof ManagesItemsInterface || $ value instanceof ManagesItemsTrait || $ value instanceof Traversable || is_array ( $ value ) ) { return true ; } return false ; }
Returns true if value can be used as array or traversed .
33,925
protected function createSiteAdminGroup ( ) { $ sitePerimeter = $ this -> createPerimeter ( SiteInterface :: ENTITY_TYPE , array ( $ this -> getReference ( 'site2' ) -> getSiteId ( ) ) ) ; $ sadmin2 = new Group ( ) ; $ sadmin2 -> addLabel ( 'en' , 'Site admin demo' ) ; $ sadmin2 -> addLabel ( 'fr' , 'Admin site demo' ) ; $ sadmin2 -> setSite ( $ this -> getReference ( 'site2' ) ) ; $ sadmin2 -> addRole ( ContributionRoleInterface :: SITE_ADMIN ) ; $ sadmin2 -> addPerimeter ( $ sitePerimeter ) ; return $ sadmin2 ; }
Create Site 2 Admin group
33,926
public function save ( $ key , $ data , $ timeout ) { $ callable = $ this -> options [ 'save' ] ; if ( ! is_callable ( $ callable ) ) { return false ; } return call_user_func_array ( $ callable , array ( $ key , $ data , $ timeout ) ) ; }
Save a cache entry via the adapter
33,927
public function find ( $ id ) { if ( $ this -> refresh ) { $ this -> forget ( $ id ) ; } return $ this -> cache -> remember ( $ this -> keyPrefix . $ id . implode ( '-' , $ this -> with ) , $ this -> minutesToCache , function ( ) use ( $ id ) { return $ this -> decorated -> find ( $ id ) ; } ) ; }
finds a model by id
33,928
public function findOrFail ( $ id ) { if ( $ this -> refresh ) { $ this -> forget ( $ id ) ; } return $ this -> cache -> remember ( $ this -> keyPrefix . $ id , $ this -> minutesToCache , function ( ) use ( $ id ) { return $ this -> decorated -> findOrFail ( $ id ) ; } ) ; }
finds a model by id fails with ModelNotFoundException when not found
33,929
protected function renderItem ( $ color ) { return Html :: tag ( 'div' , ( Html :: tag ( 'div' , Html :: tag ( 'div' , '' , [ 'class' => 'circle' ] ) , [ 'class' => 'circle-clipper left' ] ) . Html :: tag ( 'div' , Html :: tag ( 'div' , '' , [ 'class' => 'circle' ] ) , [ 'class' => 'gap-patch' ] ) . Html :: tag ( 'div' , Html :: tag ( 'div' , '' , [ 'class' => 'circle' ] ) , [ 'class' => 'circle-clipper right' ] ) ) , [ 'class' => 'spinner-layer spinner-' . $ color ] ) ; }
Generates the preloader item .
33,930
protected function voteOnAttribute ( $ attribute , $ subject , TokenInterface $ token ) { if ( $ this -> isSuperAdmin ( $ token ) ) { return true ; } if ( ContributionActionInterface :: READ == $ attribute ) { return true ; } $ actionMapping = array ( ContributionActionInterface :: TRASH_RESTORE => ContributionRoleInterface :: TRASH_RESTORER , ContributionActionInterface :: TRASH_PURGE => ContributionRoleInterface :: TRASH_SUPRESSOR ) ; return $ this -> hasRole ( $ token , $ actionMapping [ $ attribute ] ) ; }
Everyone can read the trash item but you can only purge or restore items with the matching role
33,931
public function getHeader ( $ header_key ) { if ( ! isset ( $ this -> headers [ $ header_key ] ) ) return false ; return $ this -> headers [ $ header_key ] ; }
Get a specific message header .
33,932
public static function fromAMQPMessage ( AMQPMessage $ message ) { $ envelope = new self ( ) ; $ envelope -> app_id = $ message -> has ( 'app_id' ) ? $ message -> get ( 'app_id' ) : '' ; $ envelope -> body = $ message -> body ; $ envelope -> content_encoding = $ message -> has ( 'content_encoding' ) ? $ message -> get ( 'content_encoding' ) : '' ; $ envelope -> content_type = $ message -> has ( 'content_type' ) ? $ message -> get ( 'content_type' ) : '' ; $ envelope -> correlation_id = $ message -> has ( 'correlation_id' ) ? $ message -> get ( 'correlation_id' ) : '' ; $ envelope -> delivery_mode = $ message -> has ( 'delivery_mode' ) ? $ message -> get ( 'delivery_mode' ) : '' ; $ envelope -> delivery_tag = $ message -> has ( 'delivery_tag' ) ? $ message -> get ( 'delivery_tag' ) : '' ; $ envelope -> exchange_name = $ message -> has ( 'exchange' ) ? $ message -> get ( 'exchange' ) : '' ; $ envelope -> expiration = $ message -> has ( 'expiration' ) ? $ message -> get ( 'expiration' ) : '' ; $ envelope -> headers = $ message -> has ( 'application_headers' ) ? $ message -> get ( 'application_headers' ) -> getNativeData ( ) : '' ; $ envelope -> message_id = $ message -> has ( 'message_id' ) ? $ message -> get ( 'message_id' ) : '' ; $ envelope -> priority = $ message -> has ( 'priority' ) ? $ message -> get ( 'priority' ) : '' ; $ envelope -> reply_to = $ message -> has ( 'reply_to' ) ? $ message -> get ( 'reply_to' ) : '' ; $ envelope -> routing_key = $ message -> has ( 'routing_key' ) ? $ message -> get ( 'routing_key' ) : '' ; $ envelope -> timestamp = $ message -> has ( 'timestamp' ) ? $ message -> get ( 'timestamp' ) : '' ; $ envelope -> type = $ message -> has ( 'type' ) ? $ message -> get ( 'type' ) : '' ; $ envelope -> user_id = $ message -> has ( 'user_id' ) ? $ message -> get ( 'user_id' ) : '' ; $ envelope -> is_redelivery = $ message -> has ( 'redelivered' ) ? $ message -> get ( 'redelivered' ) : '' ; return $ envelope ; }
Build AMQPEnvelope from a php - amqplib message ;
33,933
public function all ( ) { $ data = parent :: all ( ) ; $ data [ 'folder' ] = $ this -> route ( 'folder' ) ; $ data [ 'file' ] = $ this -> route ( 'file' ) ; $ data [ 'width' ] = $ this -> query ( 'width' ) ; $ data [ 'height' ] = $ this -> query ( 'height' ) ; $ data [ 'w' ] = $ this -> query ( 'w' ) ; $ data [ 'h' ] = $ this -> query ( 'h' ) ; return $ data ; }
Adds route params to be validated
33,934
public function startCounter ( ) : float { $ this -> startTime = microtime ( true ) ; $ this -> startMem = memory_get_usage ( ) ; return $ this -> startTime ; }
Start debug counter .
33,935
protected function getTimeout ( $ xml ) { $ tz = date_default_timezone_get ( ) ; date_default_timezone_set ( 'UTC' ) ; $ xml = @ new \ SimpleXMLElement ( $ xml ) ; $ dt = ( int ) strtotime ( $ xml -> cachedUntil ) ; $ time = time ( ) ; date_default_timezone_set ( $ tz ) ; return max ( 1 , $ dt - $ time ) ; }
Return the number of seconds the XML is valid . Will never be less than 1 .
33,936
protected function init ( ) { $ method = $ this -> options [ 'persistent' ] ? 'pconnect' : 'connect' ; try { if ( strpos ( $ this -> options [ 'host' ] , '/' ) === 0 ) { $ this -> redis -> { $ method } ( $ this -> options [ 'host' ] ) ; } else { $ this -> redis -> { $ method } ( $ this -> options [ 'host' ] , $ this -> options [ 'port' ] ) ; } if ( $ this -> options [ 'auth' ] ) { $ this -> redis -> auth ( $ this -> options [ 'auth' ] ) ; } } catch ( \ Exception $ e ) { throw new PhealException ( 'Connecting to cache failed!' , null , $ e ) ; } }
Initialize redis connection
33,937
public function getAllowedOperations ( ) { return [ self :: OPERATION_REQUEST , self :: OPERATION_CANCEL , self :: OPERATION_APPROVE , self :: OPERATION_REJECT , self :: OPERATION_QUERY , ] ; }
Getting the array of the allowed operations .
33,938
public function help ( $ level = null ) { $ vars = $ this -> _data -> __var ; unset ( $ vars [ '__env' ] ) ; unset ( $ vars [ 'app' ] ) ; if ( $ level ) Debug :: level ( $ level ) ; ddd ( $ vars ) ; }
Help debug method
33,939
protected function bindEntities ( ) { $ entities = $ this -> app -> config [ 'entity' ] ; foreach ( $ entities as $ e => $ config ) { $ this -> app -> bind ( "entity.$e" , function ( $ app , $ default ) use ( $ config ) { return new $ config [ 'class' ] ; } ) ; } }
Bind all registered entities to the application so we can easily instantiate them anywhere we need them .
33,940
protected function getBasePacket ( MetricInterface $ metric , $ timestamp ) { $ packet = $ this -> buildTimestamp ( $ timestamp ) ; $ packet .= $ this -> buildString ( self :: PART_TYPE_HOST , $ this -> host ) ; $ packet .= $ this -> buildString ( self :: PART_TYPE_PLUGIN , $ metric -> getName ( ) ) ; return $ packet ; }
The length field of those parts must therefore always be set to 12
33,941
public function getPerimetersConfiguration ( $ siteId ) { $ perimetersConfiguration = array ( ) ; foreach ( $ this -> strategies as $ strategy ) { $ perimetersConfiguration = array_merge ( $ perimetersConfiguration , array ( $ strategy -> getType ( ) => $ strategy -> getPerimeterConfiguration ( $ siteId ) ) ) ; } return $ perimetersConfiguration ; }
get perimeters configuration
33,942
public function next ( $ eye = '-' ) { if ( ! isset ( $ this -> states [ ++ $ this -> index ] ) ) { $ this -> index = 0 ; } $ state = $ this -> states [ $ this -> index ] ; foreach ( $ state as & $ line ) { $ line = str_pad ( str_replace ( '%' , $ eye , $ line ) , $ this -> getWidth ( ) ) ; } return $ state ; }
Gets the next cat state in the rolling index .
33,943
private function setStates ( array $ states ) { if ( empty ( $ states ) ) { throw new \ InvalidArgumentException ( 'You must provide cat states' ) ; } $ height = count ( $ states [ 0 ] ) ; $ width = 0 ; foreach ( $ states as $ state ) { if ( ! is_array ( $ state ) ) { throw new \ InvalidArgumentException ( 'States must be an array of strings' ) ; } if ( count ( $ state ) !== $ height ) { throw new \ InvalidArgumentException ( 'Height must be the same for all states' ) ; } foreach ( $ state as $ line ) { if ( ! is_string ( $ line ) ) { throw new \ InvalidArgumentException ( 'States must be an array of strings' ) ; } $ width = max ( $ width , strlen ( $ line ) ) ; } } $ this -> states = $ states ; $ this -> width = $ width ; $ this -> height = $ height ; }
Sets custom cat states .
33,944
public function includeXSL ( $ files , $ prepend = false ) { $ files = ( array ) $ files ; foreach ( $ files as $ file ) { if ( ! in_array ( $ file , $ this -> xslfiles , true ) ) { if ( $ prepend ) { array_unshift ( $ this -> xslfiles , $ file ) ; } else { $ this -> xslfiles [ ] = $ file ; } } } }
Adds XSL file to list of files to include .
33,945
public static function image ( $ mixSize = '400x350' , $ background = '000' , $ foregroundColor = 'fff' , $ text = null , $ format = 'jpg' ) { return "//dummyimage.com/$mixSize/$background/$foregroundColor" . ( ! $ text ? : '&text=' . urlencode ( $ text ) ) ; }
Generate a dummy image link
33,946
public static function text ( $ param = array ( ) ) { $ defParam = array ( 'amount' => 128 , 'what' => 'bytes' , 'start' => 'yes' , 'lang' => 'en' ) ; if ( is_integer ( $ param ) ) { $ param = array ( 'amount' => $ param ) ; } $ param = array_merge ( $ defParam , $ param ) ; $ json = Utils :: getJSON ( 'http://json-lipsum.appspot.com/?' . http_build_query ( $ param ) ) ; if ( isset ( $ json -> lipsum ) && strpos ( '--' , $ json -> lipsum ) ) { return implode ( ' -- ' , $ json -> lipsum ) ; } elseif ( isset ( $ json -> lipsum ) ) { return $ json -> lipsum ; } else { return 'Error Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ; } }
Generate a dummy text
33,947
public static function title ( $ param = null ) { if ( is_integer ( $ param ) ) { $ param = array ( 'amount' => $ param ) ; } if ( ! is_array ( $ param ) ) { $ param = array ( ) ; } $ defParam = array ( 'amount' => 30 , 'what' => 'bytes' , 'start' => 'yes' , 'lang' => 'en' ) ; $ param = array_merge ( $ defParam , $ param ) ; $ json = Utils :: getJSON ( 'http://json-lipsum.appspot.com/?' . http_build_query ( $ param ) ) ; if ( isset ( $ json -> lipsum ) ) { return $ json -> lipsum ; } else { return 'Error Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ; } }
Generate a dummy title
33,948
public static function video ( $ mixWidth = null , $ height = null ) { $ defParam = array ( 'width' => 560 , 'height' => 315 , 'src' => '//www.youtube.com/embed/0af00UcTO-c' , 'frameborder' => 0 , 'allowfullscreen' => 'true' ) ; $ param = array ( ) ; if ( is_integer ( $ mixWidth ) ) { $ param [ 'width' ] = $ mixWidth ; } if ( ! $ height && is_integer ( $ height ) ) { $ param [ 'height' ] = $ height ; } $ param = array_merge ( $ defParam , $ param ) ; return '<iframe ' . Html :: attributes ( $ param ) . '></iframe>' ; }
Generate a Youtube video iframe
33,949
protected function respond ( $ data , $ status = Response :: HTTP_OK , $ headers = [ ] ) : JsonResponse { if ( $ data instanceof ElementInterface ) { $ data = new Document ( $ data ) ; } if ( $ data instanceof Document ) { $ data = $ data -> toArray ( ) ; } return response ( ) -> json ( $ data , $ status , $ headers ) -> header ( 'Content-Type' , ApiRequestHandler :: CONTENT_TYPE ) ; }
respond json api
33,950
public function check ( $ scope , $ name , $ keyType , $ accessMask ) { $ type = ( $ keyType == 'Account' ) ? 'Character' : $ keyType ; if ( ! $ keyType || ! in_array ( $ type , array ( 'Character' , 'Corporation' ) ) || ! isset ( $ this -> bits [ strtolower ( $ scope ) ] [ strtolower ( $ name ) ] ) ) { return true ; } $ check = $ this -> bits [ strtolower ( $ scope ) ] [ strtolower ( $ name ) ] ; if ( $ check [ 0 ] == $ type ) { if ( is_int ( $ check [ 1 ] ) && ( int ) $ accessMask & ( int ) $ check [ 1 ] ) { return true ; } } throw new AccessException ( sprintf ( 'Pheal blocked an API call (%s/%s) which is not allowed by the given keyType/accessMask (%s/%d)' , $ scope , $ name , $ keyType , $ accessMask ) ) ; }
Check if the api key is allowed to make this api call
33,951
public function actionDelete ( ) { if ( isset ( $ _POST [ 'id' ] ) ) { $ id = $ _POST [ 'id' ] ; $ model = Media :: findOne ( $ id ) ; if ( ! empty ( $ model ) && $ model -> delete ( ) ) { \ Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return [ 'code' => 200 , 'message' => \ Yii :: t ( 'app' , "The file {$model->name} has been deleted successfully!" ) ] ; } } return [ 'code' => 404 , 'message' => \ Yii :: t ( 'app' , 'Selected file could not be found' ) ] ; }
Delete stored item after user confirmed 1 - Delete stored record 2 - Delete related files
33,952
public static function array_assign_subkey ( $ arr , $ sKeyOrArray = 'id' ) { $ aNew = array ( ) ; $ c = array ( "old_key" => "_key" ) ; if ( is_string ( $ sKeyOrArray ) ) { $ c [ 'key' ] = $ sKeyOrArray ; } elseif ( is_array ( $ sKeyOrArray ) ) { $ c = array_merge ( $ c , $ sKeyOrArray ) ; } foreach ( $ arr as $ key => $ v ) { if ( is_object ( $ v ) ) { if ( isset ( $ v -> $ c [ 'key' ] ) ) { if ( ! isset ( $ c [ 'delete_old_key' ] ) ) $ v -> { $ c [ 'old_key' ] } = $ key ; $ aNew [ $ v -> { $ c [ 'key' ] } ] = $ v ; } } elseif ( is_array ( $ v ) ) { if ( isset ( $ v [ $ c [ 'key' ] ] ) ) { if ( ! isset ( $ c [ 'delete_old_key' ] ) ) $ v [ $ c [ 'old_key' ] ] = $ key ; $ aNew [ $ v [ $ c [ 'key' ] ] ] = $ v ; } } } return $ aNew ; }
Array_assign_key assign the key
33,953
public static function array_diverse ( $ array ) { $ result = array ( ) ; foreach ( $ array as $ key1 => $ value1 ) { if ( is_array ( $ value1 ) ) { foreach ( $ value1 as $ key2 => $ value2 ) { $ result [ $ key2 ] [ $ key1 ] = $ value2 ; } } else { $ result [ 0 ] [ $ key1 ] = $ value1 ; } } return $ result ; }
Diverse array with a specific value
33,954
public static function array_filter_values ( $ array , $ params = [ ] ) { if ( is_string ( $ params ) ) { $ params = array ( 'with' => $ params ) ; } if ( isset ( $ params [ 'with' ] ) ) { $ data = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( preg_match ( '/' . $ params [ 'with' ] . '/i' , $ value ) ) { $ data [ $ key ] = $ value ; } } return $ data ; } else { return array_filter ( $ array ) ; } }
Array filters with particular values
33,955
public static function array_next_element ( $ arr , $ nested_key , $ iteration = 1 ) { foreach ( $ arr as $ key => $ v ) { current ( $ arr ) ; if ( $ key == $ nested_key ) { for ( $ i = 0 ; $ i < $ iteration ; $ i ++ ) { $ return = next ( $ arr ) ; } if ( ! empty ( $ return ) ) { return $ return ; } else { return false ; } } next ( $ arr ) ; } return false ; }
return the next element of a specific key
33,956
public static function array_prev_element ( $ arr , $ nested_key , $ iteration = 1 ) { foreach ( $ arr as $ key => $ v ) { if ( $ key == $ nested_key ) { for ( $ i = 0 ; $ i < $ iteration ; $ i ++ ) { $ return = prev ( $ arr ) ; } if ( ! empty ( $ return ) ) { return $ return ; } else { return false ; } } next ( $ arr ) ; } return false ; }
return the prev element of a specific key
33,957
public static function arrayToCSV ( $ array , $ downloadFile = null ) { if ( $ downloadFile ) { header ( 'Content-Type: application/csv' ) ; header ( 'Content-Disposition: attachement; filename="' . $ downloadFile . '"' ) ; } ob_start ( ) ; $ f = fopen ( 'php://output' , 'w' ) or ( "Can't open php://output" ) ; $ n = 0 ; foreach ( $ array as $ line ) { $ n ++ ; if ( ! fputcsv ( $ f , $ line ) ) { ( "Can't write line $n: $line" ) ; } } fclose ( $ f ) or ( "Can't close php://output" ) ; $ str = ob_get_contents ( ) ; ob_end_clean ( ) ; if ( ! $ downloadFile ) { return $ str ; } echo $ str ; }
Transform an array into a csv
33,958
public static function csvToArray ( $ file , $ param = array ( 'length' => 0 , 'delimiter' => ';' , 'enclosure' => '"' , 'escape' => '\\' , 'skipFirstRow' => false , 'indexFromFirstRow' => false ) ) { $ defParam = array ( 'length' => 0 , 'delimiter' => ';' , 'enclosure' => '"' , 'escape' => '\\' , 'skipFirstRow' => false , 'indexFromFirstRow' => false ) ; $ param = array_merge ( $ defParam , $ param ) ; $ handle = fopen ( $ file , 'r' ) ; $ data = array ( ) ; $ first = true ; $ index = false ; while ( ( $ line = fgetcsv ( $ handle , $ param [ 'length' ] , $ param [ 'delimiter' ] , $ param [ 'enclosure' ] , $ param [ 'escape' ] ) ) !== FALSE ) { if ( $ first ) { if ( $ param [ 'indexFromFirstRow' ] ) { $ index = $ line ; } } if ( $ param [ 'indexFromFirstRow' ] && ! $ first || ( $ param [ 'indexFromFirstRow' ] && $ param [ 'skipFirstRow' ] !== true ) ) { $ newline = array ( ) ; foreach ( $ line as $ key => $ value ) { if ( isset ( $ index [ $ key ] ) ) { $ newline [ $ index [ $ key ] ] = $ value ; } else { $ newline [ ] = $ value ; } } $ data [ ] = $ newline ; } elseif ( ! $ first || ( $ first && $ param [ 'skipFirstRow' ] !== true ) ) { $ data [ ] = $ line ; } $ first = false ; } fclose ( $ handle ) ; return $ data ; }
Transform a CSV file to array
33,959
public static function dot_array ( $ arrayDotted ) { $ array = array ( ) ; foreach ( $ arrayDotted as $ key => $ value ) { self :: array_set ( $ array , $ key , $ value ) ; } return $ array ; }
Transform an ArrayDotted to an array
33,960
public static function flatten ( $ array , $ glue = ':' , $ reset = true , $ indexed = true ) { static $ return = array ( ) ; static $ curr_key = array ( ) ; if ( $ reset ) { $ return = array ( ) ; $ curr_key = array ( ) ; } foreach ( $ array as $ key => $ val ) { $ curr_key [ ] = $ key ; if ( is_array ( $ val ) and ( $ indexed or array_values ( $ val ) !== $ val ) ) { static :: flatten_assoc ( $ val , $ glue , false ) ; } else { $ return [ implode ( $ glue , $ curr_key ) ] = $ val ; } array_pop ( $ curr_key ) ; } return $ return ; }
Flattens a multi - dimensional associative array down into a 1 dimensional associative array .
33,961
public static function merge ( ) { $ array = func_get_arg ( 0 ) ; $ Arr = array_slice ( func_get_args ( ) , 1 ) ; if ( ! is_array ( $ array ) ) { throw new \ Exception ( 'Arr::merge() - all arguments must be Array.' ) ; } foreach ( $ Arr as $ arr ) { if ( ! is_array ( $ arr ) ) { throw new \ Exception ( 'Arr::merge() - all arguments must be Array.' ) ; } foreach ( $ arr as $ key => $ value ) { if ( is_int ( $ key ) ) { array_key_exists ( $ key , $ array ) ? array_push ( $ array , $ value ) : $ array [ $ key ] = $ value ; } elseif ( is_array ( $ value ) && array_key_exists ( $ key , $ array ) && is_array ( $ array [ $ key ] ) ) { $ array [ $ key ] = self :: merge ( $ array [ $ key ] , $ value ) ; } else { $ array [ $ key ] = $ value ; } } } return $ array ; }
Merge 2 Arr recursively
33,962
public static function multiexplode ( $ l = array ( ) , $ s = '' ) { $ tr [ 0 ] = explode ( $ l [ 0 ] , $ s ) ; $ msg = array ( ) ; foreach ( $ tr [ 0 ] as $ t ) { $ r = explode ( $ l [ 1 ] , $ t ) ; $ rKey = trim ( $ r [ 0 ] ) ; $ msg [ $ rKey ] = $ r [ 1 ] ; } return $ msg ; }
Explode in multilevel array
33,963
public static function previous_by_key ( $ array , $ key , $ get_value = false , $ strict = false ) { if ( ! is_array ( $ array ) and ! $ array instanceof \ ArrayAccess ) { throw new \ InvalidArgumentException ( 'First parameter must be an array or ArrayAccess object.' ) ; } $ keys = array_keys ( $ array ) ; if ( ( $ index = array_search ( $ key , $ keys , $ strict ) ) === false ) { return false ; } elseif ( ! isset ( $ keys [ $ index - 1 ] ) ) { return null ; } return $ get_value ? $ array [ $ keys [ $ index - 1 ] ] : $ keys [ $ index - 1 ] ; }
Get the previous value or key from an array using the current array key
33,964
public function getBetterButtonsActions ( ) { $ fields = parent :: getBetterButtonsActions ( ) ; $ fields -> push ( BetterButtonCustomAction :: create ( 'resend' , 'Resend' ) -> setRedirectType ( BetterButtonCustomAction :: REFRESH ) ) ; $ this -> extend ( 'updateBetterButtonsActions' , $ fields ) ; return $ fields ; }
Gets a list of actions for the ModelAdmin interface
33,965
public function getCMSFields ( ) { preg_match ( "/<body[^>]*>(.*?)<\/body>/is" , $ this -> Body , $ matches ) ; $ contents = $ matches ? $ matches [ 1 ] : "" ; $ f = FieldList :: create ( ReadonlyField :: create ( 'To' ) , ReadonlyField :: create ( 'Subject' ) , ReadonlyField :: create ( 'BCC' ) , ReadonlyField :: create ( 'CC' ) , HeaderField :: create ( 'Email contents' , 5 ) , LiteralField :: create ( 'BodyContents' , "<div class='field'>{$contents}</div>" ) ) ; $ this -> extend ( 'updateCMSFields' , $ f ) ; return $ f ; }
Gets a list of form fields for editing the record . These records should never be edited so a readonly list of fields is forced .
33,966
public static function carousel ( $ data , $ params = array ( ) , $ formatContent = null ) { $ defaults = array ( 'parent@' => array ( 'id' => 'carousel' , 'class' => 'carousel slide' , 'data-interval' => 'false' , 'data-wrap' => 'true' , ) , 'child@' => array ( 'class' => 'item' ) , 'item_per_slide' => 1 , 'icon_prev' => 'icon-prev' , 'icon_next' => 'icon-next' , ) ; $ params = Arr :: merge ( $ defaults , $ params ) ; $ pagination = '<li data-target="#' . $ params [ 'parent@' ] [ 'id' ] . '" data-slide-to="0" class="active"></li>' ; $ slides = '<div class="' . $ params [ 'child@' ] [ 'class' ] . ' active">' ; $ hideNav = ( $ params [ 'item_per_slide' ] >= count ( $ data ) ? true : false ) ; if ( ! is_array ( $ data ) ) { return null ; } $ i = 0 ; foreach ( $ data as $ key => $ post ) { if ( $ i > 0 && $ i % $ params [ 'item_per_slide' ] == 0 ) { $ pagination .= '<li data-target="#' . $ params [ 'parent@' ] [ 'id' ] . '" data-slide-to="' . ( $ i / intval ( $ params [ 'item_per_slide' ] ) ) . '"></li>' ; $ slides .= '</div><div' . Html :: attributes ( $ params [ 'child@' ] ) . '>' ; } if ( is_null ( $ formatContent ) ) { $ slides .= '<div' . Html :: attributes ( $ params [ 'child@' ] ) . '>' . $ post . '</div>' ; } elseif ( is_callable ( $ formatContent ) ) { $ slides .= $ formatContent ( $ post , $ params , $ i ) ; } $ i ++ ; } $ slides .= '</div>' ; if ( $ hideNav ) { $ output = '<div ' . Html :: attributes ( $ params [ 'parent@' ] ) . '><div class="carousel-inner">' . $ slides . '</div></div><!--/ #' . $ params [ 'parent@' ] [ 'id' ] . ' ; } else { $ output = '<div ' . Html :: attributes ( $ params [ 'parent@' ] ) . '> <ol class="carousel-indicators">' . $ pagination . '</ol> <div class="carousel-inner">' . $ slides . '</div> <a class="left carousel-control" href="#' . $ params [ 'parent@' ] [ 'id' ] . '" data-slide="prev"><span class="' . $ params [ 'icon_prev' ] . '"></span></a> <a class="right carousel-control" href="#' . $ params [ 'parent@' ] [ 'id' ] . '" data-slide="next"><span class="' . $ params [ 'icon_next' ] . '"></span></a> </div><!--/ #' . $ params [ 'parent@' ] [ 'id' ] . ' ; } return $ output ; }
Carousel helper = > generate a carousel helpers
33,967
public static function nav ( $ data , $ params = array ( ) ) { $ defParams = array ( 'active' => null , 'parent' => 'ul' , 'child' => 'li' , 'parent@' => array ( 'class' => 'nav' ) , 'child@' => array ( ) , 'link@' => array ( ) ) ; $ params = array_merge ( $ defParams , $ params ) ; $ html = '<' . $ params [ 'parent' ] . ' ' . Html :: attributes ( $ params [ 'parent@' ] ) . '>' ; foreach ( $ data as $ key => $ value ) { $ html .= '<' . $ params [ 'child' ] . ' ' . Html :: attributes ( $ params [ 'child@' ] ) . '>' ; $ html .= '<a href="' . $ value [ 'link' ] . '"' . Html :: attributes ( $ params [ 'link@' ] ) . '>' . $ value [ 'name' ] . '</a>' ; $ html .= '</' . $ params [ 'child' ] . '>' ; } $ html .= '</' . $ params [ 'parent' ] . '>' ; return $ html ; }
Navbar helper = > generate a navbar helpers
33,968
public static function table ( $ data , $ params = array ( ) ) { $ defParams = array ( 'ajax' => false , 'tfoot' => false , 'table@' => array ( 'class' => 'table' ) , 'thead@' => array ( ) , 'tbody@' => array ( ) , 'tfoot@' => array ( ) ) ; $ params = array_merge_recursive ( $ defParams , $ params ) ; if ( is_array ( $ data ) ) { $ html = '<table ' . Html :: attributes ( $ params [ 'table@' ] ) . '><thead ' . Html :: attributes ( $ params [ 'thead@' ] ) . '><tr>' ; foreach ( reset ( $ data ) as $ key => $ name ) { $ html .= '<th>' . $ key . '</th>' ; } $ html .= '</tr></thead><tbody>' ; if ( $ params [ 'ajax' ] != true ) { foreach ( $ data as $ key => $ row ) { $ html .= '<tr>' ; foreach ( $ row as $ key => $ col ) { $ html .= '<td>' . $ col . '</td>' ; } $ html .= '</tr>' ; } } else { $ html .= '<!--AJAXCALL ; } $ html .= '</tbody>' ; $ html .= '</table>' ; return $ html ; } }
Generate a table structure
33,969
public static function breadcrumb ( $ data , $ params = array ( ) ) { $ defParams = array ( 'parent' => 'ul' , 'child' => 'li' , 'divider' => '<span class="divider">></span>' , 'parent@' => array ( 'class' => 'breadcrumb' ) , 'child@' => array ( ) ) ; $ params = array_merge_recursive ( $ defParams , $ params ) ; $ msg = '<' . $ params [ 'parent' ] . ' ' . Html :: attributes ( $ params [ 'parent@' ] ) . '>' ; foreach ( $ data as $ key => $ value ) { $ attr = $ params [ 'li' ] ; if ( $ key == 0 || $ value [ 'first' ] ) { $ params [ 'child@' ] [ 'class' ] = $ params [ 'child@' ] [ 'class' ] . ' first' ; } if ( $ key == ( count ( $ data ) - 1 ) || $ value [ 'last' ] ) { $ params [ 'child@' ] [ 'class' ] = $ params [ 'child@' ] [ 'class' ] . ' last' ; } $ msg .= '<' . $ params [ 'child' ] . ' ' . Html :: attributes ( $ params [ 'child@' ] ) . '><a href="' . $ value [ 'link' ] . '">' . $ value [ 'name' ] . '</a>' . $ params [ 'divider' ] . '</' . $ params [ 'child' ] . '>' ; } $ msg .= '</' . $ params [ 'parent' ] . '>' ; return $ msg ; }
Breadcrumb helper for bootstrap
33,970
public static function formGroup ( $ label = null , $ type = 'text' , $ name = null ) { $ aParams = func_get_args ( ) ; $ label = $ aParams [ 0 ] ; $ type = $ aParams [ 1 ] ; $ name = $ aParams [ 2 ] or $ label ; unset ( $ aParams [ 0 ] , $ aParams [ 1 ] ) ; $ html = '<div class="form-group" id="form-' . $ name . '">' ; $ html .= Form :: label ( $ name , $ label ) ; $ html .= call_user_func_array ( array ( 'Form' , $ type ) , $ aParams ) ; $ html .= '</div>' ; return $ html ; }
Form helper for Bootstrap
33,971
public static function btn ( $ href , $ content , $ attr = [ 'class' => 'btn btn-default' ] , $ params = array ( 'tag' => 'a' , 'attrHref' => 'href' ) ) { $ params = Arr :: mergeWithDefaultParams ( $ params ) ; if ( preg_match ( '/^fa-/' , $ content ) ) { $ content = "<i class=\"fa " . $ content . '"></i>' ; } elseif ( preg_match ( '/^glyphicon-/' , $ content ) ) { $ content = "<i class=\"glyphicon " . $ content . '"></i>' ; } return '<' . $ params [ 'tag' ] . ' ' . $ params [ 'attrHref' ] . '="' . $ href . '" ' . Html :: attributes ( $ attr ) . '>' . $ content . '</' . $ params [ 'tag' ] . '>' ; }
Add a bootstrap btn helper
33,972
protected function store ( UploadedFile $ uploadedFile , Settings $ settings ) { if ( ! $ settings -> hasFolder ( ) ) { $ settings -> setFolder ( 'default' ) ; } try { $ path = public_path ( config ( 'nodes.assets.providers.publicFolder.subFolder' ) ) . DIRECTORY_SEPARATOR . $ settings -> getFolder ( ) ; if ( ! file_exists ( $ path ) ) { mkdir ( $ path , 0777 , true ) ; } $ content = file_get_contents ( $ uploadedFile -> getPathname ( ) ) ; $ result = file_put_contents ( $ path . DIRECTORY_SEPARATOR . $ settings -> getFileName ( ) . '.' . $ settings -> getFileExtension ( ) , $ content ) ; if ( ! $ result ) { throw new NodesException ( 'Failed to save' , 500 ) ; } } catch ( Exception $ e ) { throw new AssetsUploadFailedException ( 'Could not save the file to public folder. Reason: ' . $ e -> getMessage ( ) ) ; } return $ settings -> getFilePath ( ) ; }
Save file to folder .
33,973
protected function httpDelete ( $ uri ) { $ this -> log [ ] = [ 'request' => [ 'method' => 'DELETE' , 'uri' => $ uri , ] , ] ; $ response = \ Httpful \ Request :: delete ( $ uri ) -> addHeader ( 'X-Auth-Email' , $ this -> email ) -> addHeader ( 'X-Auth-Key' , $ this -> apikey ) -> expects ( \ Httpful \ Mime :: JSON ) -> parseWith ( function ( $ body ) { return \ Metaclassing \ Utility :: decodeJson ( $ body ) ; } ) -> send ( ) -> body ; $ this -> log [ count ( $ this -> log ) - 1 ] [ 'response' ] = $ response ; if ( $ response [ 'success' ] != true ) { throw new \ Exception ( "delete to {$uri} unsuccessful" ) ; } return $ response [ 'result' ] ; }
Internal function to delete records in the API
33,974
protected function getStatus ( $ statusId ) { if ( ! isset ( $ this -> cachedStatuses [ $ statusId ] ) ) { $ this -> cachedStatuses [ $ statusId ] = $ this -> statusRepository -> findOneById ( $ statusId ) ; } return $ this -> cachedStatuses [ $ statusId ] ; }
Retrieve a status from the cache or DB
33,975
public function fromItem ( Item $ item ) { return Comment :: createFromArray ( array_filter ( [ 'id' => $ item -> getId ( ) , 'source' => $ item -> get ( 'source' ) , 'parent' => $ item -> get ( 'parent' ) , 'author_uuid' => $ item -> get ( 'author_uuid' ) , 'author_name' => $ item -> get ( 'author_name' ) , 'author_email' => $ item -> get ( 'author_email' ) , 'author_avatar' => $ item -> get ( 'author_avatar' ) , 'author_role' => $ item -> get ( 'author_role' ) , 'thumb' => $ item -> get ( 'thumb' ) , 'rating' => $ item -> get ( 'rating' ) , 'content' => $ item -> get ( 'content' ) , 'state' => $ item -> get ( 'state' ) , 'created_at' => $ item -> get ( 'created_at' ) , ] ) ) ; }
Create object by item .
33,976
public function toItem ( $ object ) : Item { return Item :: create ( $ this -> toItemUUID ( $ object ) , [ 'parent' => $ object -> getParent ( ) instanceof Comment ? $ object -> getParent ( ) -> getId ( ) : null , 'author_name' => $ object -> getAuthorName ( ) , 'author_email' => $ object -> getAuthorEmail ( ) , 'author_avatar' => $ object -> getAuthorAvatar ( ) , 'author_role' => $ object -> getAuthorRole ( ) , 'content' => $ object -> getContent ( ) , ] , [ 'author_uuid' => $ object -> getAuthorUUID ( ) , 'thumb' => $ object -> getThumb ( ) , 'source' => $ object -> getSource ( ) , 'state' => $ object -> getState ( ) , 'rating' => $ object -> getRating ( ) , 'created_at' => $ object -> getCreatedAt ( ) -> format ( DATE_ATOM ) , ] , [ $ object -> getContent ( ) ] ) ; }
Create item by object .
33,977
public function readFromUrl ( $ url , array $ options = [ ] ) : Certificate { $ urlHost = parse_url ( $ url , PHP_URL_HOST ) ; if ( $ urlHost === null ) { $ urlHost = $ url ; } $ urlPort = parse_url ( $ url , PHP_URL_PORT ) ; if ( $ urlPort === null ) { $ urlPort = self :: DEFAULT_PORT ; } $ options = $ this -> prepareReadFromUrlOptions ( $ options ) ; $ streamContext = stream_context_create ( array ( 'ssl' => array ( 'capture_peer_cert' => TRUE , 'verify_peer' => FALSE , 'verify_peer_name' => FALSE ) ) ) ; $ stream = @ stream_socket_client ( sprintf ( 'ssl://%s:%d' , $ urlHost , $ urlPort ) , $ errorNumber , $ errorString , $ options [ self :: OPT_CONNECTION_TIMEOUT ] , STREAM_CLIENT_CONNECT , $ streamContext ) ; if ( $ stream ) { $ streamParams = stream_context_get_params ( $ stream ) ; $ certResource = $ streamParams [ 'options' ] [ 'ssl' ] [ 'peer_certificate' ] ; return new Certificate ( $ this -> certResourceToString ( $ certResource ) ) ; } throw new Exception ( sprintf ( 'Unable to connect to %s:%d' , $ urlHost , $ urlPort ) , Exception :: CONNECTION_PROBLEM ) ; }
Connect to a URL and retrieve the SSL certificate .
33,978
public function setText ( $ message ) { if ( empty ( $ message ) ) { throw new \ InvalidArgumentException ( 'Message cannot be empty' ) ; } $ this -> message -> setText ( $ message ) ; return $ this ; }
Sets message content
33,979
protected function createMigration ( $ table ) { $ table = strtolower ( $ table ) ; $ filepath = base_path ( ) . '/database/migrations/' . date ( 'Y_m_d_His' ) . '_FilesCreate' . studly_case ( $ table ) . 'Table.php' ; $ output = view ( '_files::migrations.' . $ table ) -> render ( ) ; if ( ! file_exists ( $ filepath ) ) { $ fs = fopen ( $ filepath , 'x' ) ; if ( $ fs ) { fwrite ( $ fs , $ output ) ; fclose ( $ fs ) ; return true ; } else { return false ; } } else { return false ; } }
Creates migrations for tables
33,980
public function validate ( $ value , Constraint $ constraint ) { if ( $ value -> isInMenu ( ) || $ value -> isInFooter ( ) ) { if ( preg_match ( '/{.*}/' , $ value -> getRoutePattern ( ) ) ) { $ this -> context -> buildViolation ( $ constraint -> message ) -> atPath ( 'routePattern' ) -> addViolation ( ) ; } } }
Checks if a dynamic route pattern isn t in menu
33,981
public function getDeployInfo ( $ package ) { $ deployInfoFile = $ package -> getRootDirectory ( ) -> getFile ( 'deploy-info.json' ) ; $ deployInfo = new \ stdClass ; if ( $ deployInfoFile -> exists ( ) ) { $ deployInfo = JSONConverter :: create ( ) -> parseFile ( $ deployInfoFile ) ; } if ( ! isset ( $ deployInfo -> isStaging ) ) { $ deployInfo -> isStaging = NULL ; } if ( ! isset ( $ deployInfo -> isDevelopment ) ) { $ deployInfo -> isDevelopment = NULL ; } if ( ! isset ( $ deployInfo -> isBuilt ) ) { $ deployInfo -> isBuilt = NULL ; } return $ deployInfo ; }
Returns the deploy info written as a file in directory root
33,982
public function getConfiguration ( ) { if ( $ this -> getLocalPackage ( ) === NULL ) { $ reader = new ConfigurationReader ( ) ; return $ reader -> fromArray ( $ this -> getHostConfiguration ( ) -> get ( array ( 'defaults' ) , array ( ) ) ) ; } return $ this -> getLocalProject ( ) -> getConfiguration ( ) ; }
Returns a global Configuration
33,983
private function daemonize ( ) { umask ( 0 ) ; $ pid = pcntl_fork ( ) ; if ( $ pid == - 1 ) { throw new \ RuntimeException ( 'Failed to fork the daemon.' ) ; } elseif ( $ pid ) { return false ; } if ( posix_setsid ( ) == - 1 ) { throw new \ RuntimeException ( 'Failed to become a daemon.' ) ; } return true ; }
Split into a new process . Returns true when it s the child process and false for the parent process .
33,984
protected function handleForm ( FormInterface $ form , $ successMessage , $ itemToPersist = null ) { if ( $ form -> isValid ( ) ) { $ documentManager = $ this -> get ( 'object_manager' ) ; if ( $ itemToPersist ) { $ documentManager -> persist ( $ itemToPersist ) ; } $ documentManager -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , $ successMessage ) ; return true ; } return false ; }
Do some stuff if admin form is valid
33,985
protected function renderAdminForm ( FormInterface $ form , array $ params = array ( ) , $ response = null , $ template = self :: TEMPLATE ) { if ( is_null ( $ response ) ) { $ code = Response :: HTTP_OK ; if ( $ form -> isSubmitted ( ) && ! $ form -> isValid ( ) ) { $ code = Response :: HTTP_UNPROCESSABLE_ENTITY ; } $ response = new Response ( '' , $ code , array ( 'Content-type' => 'text/html; charset=utf-8' ) ) ; } $ params = array_merge ( $ params , array ( 'form' => $ form -> createView ( ) ) ) ; return $ this -> render ( $ template , $ params , $ response ) ; }
Render admin form and tag response with status 400 if form is badly completed
33,986
public function multiton ( $ alias , $ instance = '__default__' , array $ args = [ ] ) { if ( 1 === func_num_args ( ) ) { $ multitons = [ ] ; foreach ( $ this -> sharedDefinitions as $ name => $ value ) { if ( 0 === strpos ( $ name , $ alias . '::' ) ) { $ multitons [ substr ( $ name , strlen ( $ alias ) + 2 ) ] = $ value ; } } return $ multitons ; } $ name = $ alias . '::' . $ instance ; if ( $ this -> hasShared ( $ name ) ) { return $ this -> sharedDefinitions [ $ name ] ; } if ( $ this -> has ( $ alias ) and isset ( $ this -> sharedDefinitions [ $ alias ] ) ) { $ previousSingletonSetting = $ this -> sharedDefinitions [ $ alias ] ; unset ( $ this -> sharedDefinitions [ $ alias ] ) ; $ this -> definitions [ $ alias ] = $ previousSingletonSetting ; } $ concrete = $ this -> sharedDefinitions [ $ name ] = $ this -> get ( $ alias , $ args ) ; if ( isset ( $ previousSingletonSetting ) ) { unset ( $ this -> definitions [ $ alias ] ) ; $ this -> sharedDefinitions [ $ alias ] = $ previousSingletonSetting ; } return $ concrete ; }
Resolves a named instance from the container
33,987
protected function getEntityName ( $ entityClassName ) { preg_match_all ( '/\\\([a-zA-Z]+)/' , $ entityClassName , $ matches ) ; if ( ! empty ( $ matches [ 1 ] ) ) { return $ matches [ 1 ] [ count ( $ matches [ 1 ] ) - 1 ] ; } return $ entityClassName ; }
Get entity name by class name
33,988
protected function getTableName ( $ entityName ) { $ tableName = $ entityName ; preg_match_all ( '/[A-Z][a-z]+/' , $ entityName , $ matches ) ; if ( ! empty ( $ matches [ 0 ] ) ) { $ tableName = implode ( '_' , $ matches [ 0 ] ) ; } return strtolower ( $ tableName ) ; }
Get table name by entity name
33,989
protected function getOrderByExpressionAsString ( InternalOrderByInfo $ orderBy ) { $ result = '' ; foreach ( $ orderBy -> getOrderByInfo ( ) -> getOrderByPathSegments ( ) as $ order ) { foreach ( $ order -> getSubPathSegments ( ) as $ subOrder ) { $ result .= $ result ? ', ' : '' ; $ result .= $ subOrder -> getName ( ) ; $ result .= $ order -> isAscending ( ) ? ' ASC' : ' DESC' ; } } return $ result ; }
Get part of SQL query with ORDER BY condition
33,990
public function add ( ClassInterface $ import , $ alias = NULL ) { if ( empty ( $ alias ) ) { $ alias = $ import -> getName ( ) ; } if ( empty ( $ alias ) ) { throw new InvalidArgumentException ( 'GClass: ' . $ import . ' must have a valid FQN: ' . $ import -> getFQN ( ) ) ; } if ( array_key_exists ( $ lowerAlias = mb_strtolower ( $ alias ) , $ this -> aliases ) ) { $ usedBy = $ this -> classes [ $ this -> aliases [ $ lowerAlias ] ] ; if ( ! $ import -> equals ( $ usedBy ) ) { throw new LogicException ( 'Alias: ' . $ alias . ' is already used by Class ' . $ usedBy ) ; } } $ this -> classes [ $ alias ] = $ import ; $ this -> aliases [ $ lowerAlias ] = $ alias ; return $ this ; }
Adds an Import
33,991
public function remove ( $ aliasOrGClass ) { if ( $ aliasOrGClass instanceof ClassInterface ) { $ gClass = $ aliasOrGClass ; $ alias = $ aliasOrGClass -> getName ( ) ; } else { $ gClass = NULL ; $ alias = $ aliasOrGClass ; } if ( array_key_exists ( $ loweralias = mb_strtolower ( $ alias ) , $ this -> aliases ) ) { unset ( $ this -> classes [ $ this -> aliases [ $ loweralias ] ] ) ; unset ( $ this -> aliases [ $ loweralias ] ) ; } elseif ( isset ( $ gClass ) ) { foreach ( $ this -> classes as $ alias => $ otherGClass ) { if ( $ otherGClass -> equals ( $ gClass ) ) { unset ( $ this -> aliases [ mb_strtolower ( $ alias ) ] ) ; unset ( $ this -> classes [ $ alias ] ) ; break ; } } } return $ this ; }
Removes an Import
33,992
public function mergeFromClass ( GClass $ gClass ) { try { foreach ( $ gClass -> getImports ( ) -> toArray ( ) as $ alias => $ import ) { $ this -> add ( $ import , $ alias ) ; } } catch ( InvalidArgumentException $ e ) { \ Doctrine \ Common \ Util \ Debug :: dump ( $ gClass -> getImports ( ) -> toArray ( ) ) ; throw new InvalidArgumentException ( 'Cannot add all imports from ' . $ gClass -> getFQN ( ) . ' into imports.' , 0 , $ e ) ; } return $ this ; }
Merges all Imports from a GClass to this imports
33,993
public function refresh ( $ account ) { $ identity = $ this -> identity ( $ account ) ; return $ this -> findByIdentity ( [ $ identity => $ account -> $ identity ] ) ; }
todo interface for identity
33,994
public function confirmByCode ( $ code ) { $ identity = [ 'confirmation_code' => $ code ] ; $ account = $ this -> findByIdentity ( $ identity ) ; if ( $ account ) { return $ this -> confirm ( $ account ) ; } else { return false ; } }
Update the confirmation status of a user to true if a user is found with the given confirmation code .
33,995
public function register ( $ input ) { $ account = $ this -> model ( ) -> fill ( $ input ) ; $ account -> password_confirmation = array_get ( $ input , 'password_confirmation' ) ; $ account -> confirmation_code = md5 ( uniqid ( mt_rand ( ) , true ) ) ; return $ this -> save ( $ account ) ; }
Signup a new account with the given parameters
33,996
public function logAttempt ( array $ input , $ mustBeConfirmed = true ) { $ remember = $ this -> extractRememberFromArray ( $ input ) ; $ given_identity = $ input [ $ this -> identity ( ) ] ; if ( $ this -> loginThrottling ( $ given_identity ) ) { $ account = $ this -> findByIdentity ( [ $ this -> identity ( ) => $ given_identity ] ) ; if ( $ account instanceof Entity ) { if ( ! $ account -> confirmed && $ mustBeConfirmed ) { return false ; } if ( ! $ this -> checkPassword ( $ account , $ input ) ) { return false ; } $ this -> login ( $ account , $ remember ) ; return true ; } } return false ; }
Attempt to log a user into the application with password and email
33,997
public function checkPassword ( $ account , array $ input ) { $ password = isset ( $ input [ 'password' ] ) ? $ input [ 'password' ] : false ; return app ( 'hash' ) -> check ( $ password , $ account -> password ) ; }
todo interface password
33,998
protected function loginThrottling ( $ identity ) { $ count = app ( 'account.throttle' ) -> throttleIdentity ( $ identity ) ; if ( $ count >= config ( 'store.throttle_limit' ) ) return false ; if ( $ count > 2 ) usleep ( ( $ count - 1 ) * 400000 ) ; return true ; }
Calls throttleIdentity of the loginThrottler and returns false if the throttleCount is grater then the throttle_limit config . Also sleeps a little in order to avoid dicionary attacks .
33,999
public function existsButNotConfirmed ( $ input ) { $ given_identity = $ input [ $ this -> identity ( ) ] ; $ account = $ this -> findByIdentity ( [ $ this -> identity ( ) => $ given_identity ] ) ; if ( $ account ) { $ correctPassword = $ this -> checkPassword ( $ account , $ input ) ; return ( ! $ account -> confirmed && $ correctPassword ) ; } }
Checks if the given credentials correponds to a user that exists but is not confirmed