idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
500
protected function broadcastEvent ( $ event ) { $ connection = ( $ event instanceof ShouldBroadcastNowInterface ) ? 'sync' : null ; $ queue = method_exists ( $ event , 'onQueue' ) ? $ event -> onQueue ( ) : null ; $ this -> resolveQueue ( ) -> connection ( $ connection ) -> pushOn ( $ queue , 'Nova\Broadcasting\BroadcastEvent' , array ( 'event' => serialize ( clone $ event ) , ) ) ; }
Broadcast the given event class .
501
protected function addToActionList ( $ action , $ route ) { $ controller = $ action [ 'controller' ] ; if ( ! isset ( $ this -> actionList [ $ controller ] ) ) { $ this -> actionList [ $ controller ] = $ route ; } }
Add a route to the controller action dictionary .
502
protected function fastCheck ( array $ routes , $ request ) { $ domain = $ request -> getHost ( ) ; $ path = ( $ request -> path ( ) == '/' ) ? '/' : '/' . $ request -> path ( ) ; foreach ( array ( $ domain . $ path , $ path ) as $ key ) { $ route = Arr :: get ( $ routes , $ key ) ; if ( ! is_null ( $ route ) && $ route -> matches ( $ request , true ) ) { return $ route ; } } }
Determine if a route in the array fully matches the request - the fast way .
503
public function broadcastWith ( ) { return array_merge ( $ this -> data , array ( 'id' => $ this -> notification -> id , 'type' => get_class ( $ this -> notification ) , ) ) ; }
Get the data that should be sent with the broadcasted event .
504
protected function evaluatePath ( $ __path , $ __data ) { $ obLevel = ob_get_level ( ) ; ob_start ( ) ; foreach ( $ __data as $ __variable => $ __value ) { if ( in_array ( $ __variable , array ( '__path' , '__data' ) ) ) { continue ; } $ { $ __variable } = $ __value ; } unset ( $ __data , $ __variable , $ __value ) ; try { include $ __path ; } catch ( \ Exception $ e ) { $ this -> handleViewException ( $ e , $ obLevel ) ; } catch ( \ Throwable $ e ) { $ this -> handleViewException ( $ e , $ obLevel ) ; } return ltrim ( ob_get_clean ( ) ) ; }
Get the evaluated contents of the View at the given path .
505
protected function writeLog ( $ level , $ message , $ context ) { $ this -> fireLogEvent ( $ level , $ message = $ this -> formatMessage ( $ message ) , $ context ) ; $ this -> monolog -> { $ level } ( $ message , $ context ) ; }
Write a message to Monolog .
506
public function render ( Closure $ callback = null ) { try { $ contents = $ this -> renderContents ( ) ; $ response = isset ( $ callback ) ? $ callback ( $ this , $ contents ) : null ; $ this -> factory -> flushSectionsIfDoneRendering ( ) ; return $ response ? : $ contents ; } catch ( Exception $ e ) { $ this -> factory -> flushSections ( ) ; throw $ e ; } }
Get the string contents of the View .
507
public function withErrors ( $ provider ) { if ( $ provider instanceof MessageProvider ) { $ this -> with ( 'errors' , $ provider -> getMessageBag ( ) ) ; } else { $ this -> with ( 'errors' , new MessageBag ( ( array ) $ provider ) ) ; } return $ this ; }
Add validation errors to the view .
508
protected function getColumns ( Blueprint $ blueprint ) { $ columns = array ( ) ; foreach ( $ blueprint -> getColumns ( ) as $ column ) { $ sql = $ this -> wrap ( $ column ) . ' ' . $ this -> getType ( $ column ) ; $ columns [ ] = $ this -> addModifiers ( $ sql , $ blueprint , $ column ) ; } return $ columns ; }
Compile the blueprint s column definitions .
509
protected function logMessage ( $ message ) { $ emails = implode ( ', ' , array_keys ( ( array ) $ message -> getTo ( ) ) ) ; $ this -> logger -> info ( "Pretending to mail message to: {$emails}" ) ; }
Log that a message was sent .
510
protected function generateRedirectToDefaultSelection ( $ categorySlug , $ questionSlug ) { $ doRedirect = false ; $ config = $ this -> container -> getParameter ( 'genj_faq' ) ; if ( ! $ categorySlug && $ config [ 'select_first_category_by_default' ] ) { $ firstCategory = $ this -> getCategoryRepository ( ) -> retrieveFirst ( ) ; if ( $ firstCategory instanceof \ Genj \ FaqBundle \ Entity \ Category ) { $ categorySlug = $ firstCategory -> getSlug ( ) ; $ doRedirect = true ; } else { throw $ this -> createNotFoundException ( 'Tried to open the first faq category by default, but there was none.' ) ; } } if ( ! $ questionSlug && $ config [ 'select_first_question_by_default' ] ) { $ firstQuestion = $ this -> getQuestionRepository ( ) -> retrieveFirstByCategorySlug ( $ categorySlug ) ; if ( $ firstQuestion instanceof \ Genj \ FaqBundle \ Entity \ Question ) { $ questionSlug = $ firstQuestion -> getSlug ( ) ; $ doRedirect = true ; } else { throw $ this -> createNotFoundException ( 'Tried to open the first faq question by default, but there was none.' ) ; } } if ( $ doRedirect ) { return $ this -> redirect ( $ this -> generateUrl ( 'genj_faq_faq_index' , array ( 'categorySlug' => $ categorySlug , 'questionSlug' => $ questionSlug ) , true ) ) ; } return false ; }
Open first category or question if none was selected so far .
511
public function load ( $ environment = null ) { if ( $ environment == 'production' ) $ environment = null ; if ( ! $ this -> files -> exists ( $ path = $ this -> getFile ( $ environment ) ) ) { return array ( ) ; } else { return $ this -> files -> getRequire ( $ path ) ; } }
Load the environment variables for the given environment .
512
public function boot ( ) { $ db = $ this -> app [ 'db' ] ; $ events = $ this -> app [ 'events' ] ; Model :: setConnectionResolver ( $ db ) ; Model :: setEventDispatcher ( $ events ) ; }
Bootstrap the Application events .
513
protected function raw ( $ ability , array $ arguments ) { if ( is_null ( $ user = $ this -> resolveUser ( ) ) ) { return false ; } $ result = $ this -> callBeforeCallbacks ( $ user , $ ability , $ arguments ) ; if ( is_null ( $ result ) ) { $ result = $ this -> callAuthCallback ( $ user , $ ability , $ arguments ) ; } $ this -> callAfterCallbacks ( $ user , $ ability , $ arguments , $ result ) ; return $ result ; }
Get the raw result for the given ability for the current user .
514
private function getHeader ( $ key ) { if ( isset ( $ this -> requestHeader [ $ key ] ) ) { $ header = $ this -> requestHeader [ $ key ] [ 'value' ] ; unset ( $ this -> requestHeader [ $ key ] ) ; } else { if ( $ key === 'host' ) { $ header = $ this -> getHost ( ) ; } elseif ( $ key === 'accept' ) { $ header = '*/*' ; } elseif ( $ key === 'user-agent' ) { $ header = self :: $ userAgent ; } } return $ header ; }
Verifica se existe um header e retorna o seu valor .
515
public static function with ( $ relations ) { if ( is_string ( $ relations ) ) $ relations = func_get_args ( ) ; $ instance = new static ; return $ instance -> newQuery ( ) -> with ( $ relations ) ; }
Being querying a model with eager loading .
516
public function addObservableEvents ( $ observables ) { $ observables = is_array ( $ observables ) ? $ observables : func_get_args ( ) ; $ this -> observables = array_unique ( array_merge ( $ this -> observables , $ observables ) ) ; }
Add an observable event name .
517
public function removeObservableEvents ( $ observables ) { $ observables = is_array ( $ observables ) ? $ observables : func_get_args ( ) ; $ this -> observables = array_diff ( $ this -> observables , $ observables ) ; }
Remove an observable event name .
518
public function setCreatedAt ( $ value ) { if ( ! is_null ( $ column = $ this -> getCreatedAtColumn ( ) ) ) { $ this -> setAttribute ( $ column , $ value ) ; } }
Set the value of the created at attribute .
519
public function setUpdatedAt ( $ value ) { if ( ! is_null ( $ column = $ this -> getUpdatedAtColumn ( ) ) ) { $ this -> setAttribute ( $ column , $ value ) ; } }
Set the value of the updated at attribute .
520
public function applyGlobalScopes ( $ builder ) { foreach ( $ this -> getGlobalScopes ( ) as $ scope ) { $ scope -> apply ( $ builder , $ this ) ; } return $ builder ; }
Apply all of the global scopes to an ORM builder .
521
public function removeGlobalScopes ( $ builder ) { foreach ( $ this -> getGlobalScopes ( ) as $ scope ) { $ scope -> remove ( $ builder , $ this ) ; } return $ builder ; }
Remove all of the global scopes from an ORM builder .
522
public function onRequest ( Request $ request , Response $ response ) { $ psr7Request = \ Swoft \ Http \ Message \ Server \ Request :: loadFromSwooleRequest ( $ request ) ; $ psr7Response = new \ Swoft \ Http \ Message \ Server \ Response ( $ response ) ; $ dispatcher = App :: getBean ( 'serverDispatcher' ) ; $ dispatcher -> dispatch ( $ psr7Request , $ psr7Response ) ; }
onRequest event callback Each request will create an coroutine
523
public function getByLabel ( $ label ) { return isset ( $ this -> items [ $ label ] ) ? $ this -> items [ $ label ] : null ; }
Returns user data item by its label .
524
private function createDataItems ( array $ data ) { $ items = [ ] ; foreach ( $ data as $ item ) { $ items [ $ item [ 'label' ] ] = new UserDataItem ( $ item [ 'label' ] , $ item [ 'value' ] , $ item [ 'isValid' ] , $ item [ 'isOwner' ] ) ; } return $ items ; }
Creates data item object from array .
525
public function display ( Exception $ exception , $ code ) { $ content = $ this -> whoops ( ) -> handleException ( $ exception ) ; if ( $ this -> request -> wantsJson ( ) ) { return Response :: create ( $ content , $ code ) -> header ( 'Content-Type' , 'application/json' ) ; } else { return Response :: create ( $ content , $ code ) ; } }
Get the Whoops HTML content associated with the given exception .
526
protected function alreadyInParameters ( $ class , array $ parameters ) { $ result = Arr :: first ( $ parameters , function ( $ key , $ value ) use ( $ class ) { return ( $ value instanceof $ class ) ; } ) ; return ! is_null ( $ result ) ; }
Determine if an object of the given class is in a list of parameters .
527
protected function checkSpecificObject ( array $ acceptedTypes , $ value ) { if ( is_object ( $ value ) ) { foreach ( $ acceptedTypes as $ type ) { $ c = get_class ( $ value ) ; if ( $ c == ltrim ( $ type , '\\' ) || is_subclass_of ( $ c , $ type ) ) { return $ value ; } } } return null ; }
Will check to see if the value is an object and its class is listed in the accepted types .
528
public function execute ( AbstractMethod $ method ) : \ Generator { switch ( $ method -> getHttpMethod ( ) ) { case $ method :: HTTP_GET : $ response = yield from $ this -> get ( '/' . $ method -> getMethodName ( ) , $ method -> getParams ( ) ) ; break ; case $ method :: HTTP_POST : if ( $ method instanceof \ JsonSerializable ) { $ body = json_encode ( $ method ) ; $ bodyStream = new MemoryStream ( 0 , $ body ) ; yield from $ bodyStream -> end ( ) ; $ contentLength = mb_strlen ( $ body ) ; } else { $ bodyStream = null ; $ contentLength = 0 ; } $ headers = [ 'Content-Type' => 'application/json' , 'Content-Length' => $ contentLength ] ; $ response = yield from $ this -> post ( '/' . $ method -> getMethodName ( ) , $ method -> getParams ( ) , $ headers , $ bodyStream ) ; break ; } $ body = yield from $ this -> getResponseBody ( $ response ) ; $ body = json_decode ( $ body , true ) ; if ( $ body [ 'ok' ] === false ) { $ exception = new TelegramBotApiException ( $ body [ 'description' ] , $ body [ 'error_code' ] ) ; if ( isset ( $ body [ 'parameters' ] ) ) { $ parameters = new Type \ ResponseParameters ( $ body [ 'parameters' ] ) ; $ exception -> setParameters ( $ parameters ) ; } throw $ exception ; } return $ method -> buildResult ( $ body [ 'result' ] ) ; }
Execute an API method .
529
protected function buildUrl ( string $ pathName , array $ params = [ ] ) : string { $ uri = new BasicUri ( $ this -> baseUrl . $ this -> token . $ pathName ) ; foreach ( $ params as $ name => $ value ) { if ( is_bool ( $ value ) ) { $ value = ( int ) $ value ; } $ uri = $ uri -> withQueryValue ( $ name , $ value ) ; } return ( string ) $ uri ; }
Build full URL to a telegram API with given pathName
530
public function startExceptionHandling ( ) { $ this [ 'exception' ] -> register ( $ this -> environment ( ) ) ; $ debug = $ this [ 'config' ] [ 'app.debug' ] ; $ this [ 'exception' ] -> setDebug ( $ debug ) ; }
Start the exception handling for the request .
531
protected function bootApplication ( ) { $ this -> fireAppCallbacks ( $ this -> bootingCallbacks ) ; $ this -> booted = true ; $ this -> fireAppCallbacks ( $ this -> bootedCallbacks ) ; }
Boot the application and fire app callbacks .
532
protected function parseMiddleware ( $ middleware ) { list ( $ name , $ parameters ) = array_pad ( explode ( ':' , $ middleware , 2 ) , 2 , array ( ) ) ; if ( is_string ( $ parameters ) ) { $ parameters = explode ( ',' , $ parameters ) ; } return array ( $ name , $ parameters ) ; }
Parse a middleware string to get the name and parameters .
533
public function pushMiddleware ( $ middleware ) { if ( array_search ( $ middleware , $ this -> middleware ) === false ) { array_push ( $ this -> middleware , $ middleware ) ; } return $ this ; }
Add a new middleware to end of the stack if it does not already exist .
534
public function setRequestForConsoleEnvironment ( ) { $ url = $ this [ 'config' ] -> get ( 'app.url' , 'http://localhost' ) ; $ parameters = array ( $ url , 'GET' , array ( ) , array ( ) , array ( ) , $ _SERVER ) ; $ this -> refreshRequest ( static :: onRequest ( 'create' , $ parameters ) ) ; }
Set the application request for the console environment .
535
public function abuseReport ( $ start = 0 , $ limit = 2000 , $ string = null ) { $ payload = array ( 'id' => $ this -> listId , 'start' => $ start , 'limit' => $ limit , 'string' => $ string ) ; $ apiCall = 'lists/abuse-reports' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Get all email addresses that complained about a campaign sent to a list
536
public function batchSubscribe ( $ batch , $ double_optin = true , $ update_existing = true , $ replace_interests = true ) { $ payload = array ( 'id' => $ this -> listId , 'batch' => $ batch , 'double_optin' => $ double_optin , 'update_existing' => $ update_existing , 'replace_interests' => $ replace_interests , ) ; $ apiCall = 'lists/batch-subscribe' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Subscribe a batch of email addresses to a list at once These calls are also long so be sure you increase your timeout values
537
public function batchUnsubscribe ( $ batch , $ delete_member = false , $ send_goodbye = false , $ send_notify = false ) { $ payload = array ( 'id' => $ this -> listId , 'batch' => $ batch , 'delete_member' => $ delete_member , 'send_goodbye' => $ send_goodbye , 'send_notify' => $ send_notify ) ; $ apiCall = 'lists/batch-unsubscribe' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Unsubscribe a batch of email addresses to a list at once These calls are also long so be sure you increase your timeout values
538
public function subscribe ( $ email_id , $ email_type = 'html' , $ double_optin = true , $ update_existing = true , $ replace_interests = true , $ send_welcome = false , $ email_identifier = 'email' ) { if ( ! in_array ( $ email_identifier , array ( "email" , "euid" , "leid" ) ) ) throw new InvalidArgumentException ( 'email identifier should be one of ("email","euid","leid")' ) ; $ payload = array ( 'id' => $ this -> listId , 'email' => array ( $ email_identifier => $ email_id ) , 'merge_vars' => $ this -> merge_vars , 'email_type' => $ email_type , 'double_optin' => $ double_optin , 'update_existing' => $ update_existing , 'replace_interests' => $ replace_interests , 'send_welcome' => $ send_welcome ) ; $ apiCall = 'lists/subscribe' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Subscribe an email addresses to a list These calls are also long so be sure you increase your timeout values
539
public function unsubscribe ( $ email_id , $ delete_member = false , $ send_goodbye = true , $ send_notify = true , $ email_identifier = 'email' ) { if ( ! in_array ( $ email_identifier , array ( "email" , "euid" , "leid" ) ) ) throw new InvalidArgumentException ( 'email identifier should be one of ("email","euid","leid")' ) ; $ payload = array ( 'id' => $ this -> listId , 'email' => array ( $ email_identifier => $ email_id ) , 'delete_member' => $ delete_member , 'send_goodbye' => $ send_goodbye , 'send_notify' => $ send_notify ) ; $ apiCall = 'lists/unsubscribe' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return true ; }
Unsubscribe the given email address from the list
540
public function memberInfo ( $ email_id , $ email_identifier = 'email' ) { if ( ! in_array ( $ email_identifier , array ( "email" , "euid" , "leid" ) ) ) throw new InvalidArgumentException ( 'email identifier should be one of ("email","euid","leid")' ) ; $ email_ids = array ( ) ; if ( is_array ( $ email_id ) ) { foreach ( $ email_id as $ email ) { $ email_ids [ ] = array ( $ email_identifier => $ email ) ; } } else { $ email_ids [ ] = array ( $ email_identifier => $ email_id ) ; } $ payload = array ( 'id' => $ this -> listId , 'emails' => $ email_ids ) ; $ apiCall = 'lists/member-info' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Get all the information for particular members of a list
541
public function members ( $ status = 'subscribed' , $ opts = null ) { $ payload = array ( 'id' => $ this -> listId , 'status' => $ status ) ; if ( ! is_null ( $ opts ) ) { $ payload [ 'opts' ] = $ opts ; } $ apiCall = 'lists/members' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Get a list of members for a list
542
public function lists ( $ filters = array ( ) , $ start = 0 , $ end = 100 , $ sort_field = "created" , $ sort_dir = "DESC" ) { $ payload = array ( 'id' => $ this -> listId , 'filters' => $ filters , 'start' => $ start , 'end' => $ end , 'sort_field' => $ sort_field , 'sort_dir' => $ sort_dir ) ; $ apiCall = 'lists/list' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Retrieve all of the lists defined for your user account
543
public function interestGroupings ( $ count = null ) { $ payload = array ( 'id' => $ this -> listId , 'count' => $ count ) ; $ apiCall = 'lists/interest-groupings' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Get the list of interest groupings for a given list including the label form information and included groups for each
544
public function addInterestGroupings ( $ name , $ type , array $ groups ) { $ payload = array ( 'id' => $ this -> listId , 'name' => $ name , 'type' => $ type , 'groups' => $ groups ) ; $ apiCall = 'lists/interest-grouping-add' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return isset ( $ data ) ? $ data : false ; }
Add a new Interest Grouping - if interest groups for the List are not yet enabled adding the first grouping will automatically turn them on .
545
public function delInterestGrouping ( $ group_id = false ) { $ payload = array ( 'grouping_id' => ( FALSE === $ group_id ) ? $ this -> grouping_id : $ group_id ) ; $ apiCall = 'lists/interest-grouping-del' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return true ; }
Delete an existing Interest Grouping - this will permanently delete all contained interest groups and will remove those selections from all list members
546
public function updateInterestGrouping ( $ name , $ value , $ group_id = false ) { $ payload = array ( 'grouping_id' => ( FALSE === $ group_id ) ? $ this -> grouping_id : $ group_id , 'name' => $ name , 'value' => $ value ) ; $ apiCall = 'lists/interest-grouping-update' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return true ; }
Update an existing Interest Grouping
547
public function addInterestGroup ( $ name , $ group_id = NULL ) { $ payload = array ( 'id' => $ this -> listId , 'group_name' => $ name , 'grouping_id' => ( NULL === $ group_id ) ? $ this -> grouping_id : $ group_id , ) ; $ apiCall = 'lists/interest-group-add' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return true ; }
Add a single Interest Group - if interest groups for the List are not yet enabled adding the first group will automatically turn them on .
548
public function updateInterestGroup ( $ old_name , $ new_name , $ grouping_id = NULL ) { $ payload = array ( 'id' => $ this -> listId , 'old_name' => $ old_name , 'new_name' => $ new_name , 'grouping_id' => ( NULL === $ grouping_id ) ? $ this -> grouping_id : $ grouping_id ) ; $ apiCall = 'lists/interest-group-update' ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return true ; }
Change the name of an Interest Group
549
private function getResourcePaths ( ContainerBuilder $ container ) { $ paths = [ ] ; $ rootDir = dirname ( $ container -> getParameter ( 'kernel.root_dir' ) ) ; foreach ( $ container -> getParameter ( 'kernel.bundles' ) as $ name => $ class ) { if ( null !== ( $ path = $ this -> getResourcePathFromBundle ( $ rootDir , $ name , $ class ) ) ) { $ paths [ ] = $ path ; } } if ( is_readable ( $ rootDir . '/app/Resources/contao/config/services.php' ) ) { $ paths [ ] = $ rootDir . '/app/Resources/contao/config/services.php' ; } if ( is_readable ( $ rootDir . '/system/config/services.php' ) ) { $ paths [ ] = $ rootDir . '/system/config/services.php' ; } return $ paths ; }
Returns the Contao resources paths as array .
550
private function getResourcePathFromClassName ( $ class ) { $ reflection = new \ ReflectionClass ( $ class ) ; if ( is_dir ( $ dir = dirname ( $ reflection -> getFileName ( ) ) . '/Resources/contao' ) ) { return $ dir ; } return null ; }
Returns the resources path from the class name .
551
protected function getSessionId ( Request $ request , SessionInterface $ session ) { $ name = $ session -> getName ( ) ; return $ request -> cookies -> get ( $ name ) ; }
Get the session ID from the request .
552
protected function configHitsLottery ( array $ config ) { list ( $ trigger , $ max ) = $ config [ 'lottery' ] ; $ value = mt_rand ( 1 , $ max ) ; return ( $ value <= $ trigger ) ; }
Determine if the configuration odds hit the lottery .
553
protected function createCookie ( array $ config , SessionInterface $ session ) { $ expireOnClose = Arr :: get ( $ config , 'expireOnClose' , false ) ; if ( $ expireOnClose !== false ) { $ lifetime = Arr :: get ( $ config , 'lifetime' , 180 ) ; $ expire = Carbon :: now ( ) -> addMinutes ( $ lifetime ) ; } else { $ expire = 0 ; } $ secure = Arr :: get ( $ config , 'secure' , false ) ; return new Cookie ( $ session -> getName ( ) , $ session -> getId ( ) , $ expire , $ config [ 'path' ] , $ config [ 'domain' ] , $ secure ) ; }
Create a Cookie instance for the specified Session and configuration .
554
protected function usingCookieSessions ( ) { if ( ! $ this -> sessionConfigured ( ) ) { return false ; } $ session = $ this -> manager -> driver ( ) ; $ handler = $ session -> getHandler ( ) ; return ( $ handler instanceof CookieSessionHandler ) ; }
Determine if the session is using cookie sessions .
555
public function dispatch ( SymfonyRequest $ request ) { if ( ! is_null ( $ route = $ this -> findRoute ( $ request ) ) ) { list ( $ callback , $ parameters ) = $ route ; array_unshift ( $ parameters , $ request ) ; return call_user_func_array ( $ callback , $ parameters ) ; } }
Dispatch a Assets File Response .
556
protected function findRoute ( Request $ request ) { if ( ! in_array ( $ request -> method ( ) , array ( 'GET' , 'HEAD' , 'OPTIONS' ) ) ) { return ; } $ uri = $ request -> path ( ) ; foreach ( $ this -> routes as $ pattern => $ callback ) { if ( preg_match ( '#^' . $ pattern . '$#s' , $ uri , $ matches ) ) { return array ( $ callback , array_slice ( $ matches , 1 ) ) ; } } }
Dispatch an URI and return the associated file path .
557
public function serve ( $ path , SymfonyRequest $ request , $ disposition = 'inline' , $ fileName = null , $ prepared = true ) { if ( ! file_exists ( $ path ) ) { return new Response ( 'File Not Found' , 404 ) ; } else if ( ! is_readable ( $ path ) ) { return new Response ( 'Unauthorized Access' , 403 ) ; } $ headers = array ( 'Access-Control-Allow-Origin' => '*' , ) ; $ mimeType = $ this -> guessMimeType ( $ path ) ; if ( $ request -> getMethod ( ) == 'OPTIONS' ) { $ headers = array_merge ( $ headers , array ( 'Access-Control-Allow-Methods' => 'GET, HEAD, OPTIONS' , 'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin' , ) ) ; return new Response ( 'OK' , 200 , $ headers ) ; } else { $ headers [ 'Content-Type' ] = $ mimeType ; } if ( $ mimeType !== 'application/json' ) { $ response = new BinaryFileResponse ( $ path , 200 , $ headers , true , $ disposition , true , false ) ; $ response -> setContentDisposition ( $ disposition , $ fileName ? : basename ( $ path ) ) ; $ this -> setupCacheControl ( $ response ) ; $ response -> isNotModified ( $ request ) ; } else { $ response = new JsonResponse ( json_decode ( file_get_contents ( $ path ) , true ) , 200 , $ headers ) ; } if ( $ prepared ) { return $ response -> prepare ( $ request ) ; } return $ response ; }
Serve a File .
558
protected function getPackagePath ( $ env , $ package , $ group ) { $ file = str_replace ( '/' , DS , "Packages/{$package}/{$env}/{$group}.php" ) ; return $ this -> defaultPath . DS . $ file ; }
Get the Package path for an environment and group .
559
public function validateArguments ( $ methods , $ handler ) : array { if ( ! $ methods || ! $ handler ) { throw new \ InvalidArgumentException ( 'The method and route handler is not allow empty.' ) ; } $ allow = self :: ALLOWED_METHODS_STR . ',' ; $ hasAny = false ; $ methods = \ array_map ( function ( $ m ) use ( $ allow , & $ hasAny ) { $ m = \ strtoupper ( trim ( $ m ) ) ; if ( ! $ m || false === \ strpos ( $ allow , $ m . ',' ) ) { throw new \ InvalidArgumentException ( "The method [$m] is not supported, Allow: " . trim ( $ allow , ',' ) ) ; } if ( ! $ hasAny && $ m === self :: ANY ) { $ hasAny = true ; } return $ m ; } , ( array ) $ methods ) ; return $ hasAny ? self :: ALLOWED_METHODS : $ methods ; }
validate and format arguments
560
public function parseParamRoute ( string $ route , array $ params , array $ conf ) : array { $ bak = $ route ; $ noOptional = null ; if ( false !== ( $ pos = \ strpos ( $ route , '[' ) ) ) { $ noOptional = \ substr ( $ route , 0 , $ pos ) ; $ withoutClosingOptionals = rtrim ( $ route , ']' ) ; $ optionalNum = \ strlen ( $ route ) - \ strlen ( $ withoutClosingOptionals ) ; if ( $ optionalNum !== \ substr_count ( $ withoutClosingOptionals , '[' ) ) { throw new \ LogicException ( 'Optional segments can only occur at the end of a route' ) ; } $ route = \ str_replace ( [ '[' , ']' ] , [ '(?:' , ')?' ] , $ route ) ; } if ( false !== \ strpos ( $ route , '.' ) ) { $ route = \ str_replace ( '.' , '\.' , $ route ) ; } if ( \ preg_match_all ( '#\{([a-zA-Z_][a-zA-Z0-9_-]*)\}#' , $ route , $ m ) ) { $ replacePairs = [ ] ; foreach ( $ m [ 1 ] as $ name ) { $ key = '{' . $ name . '}' ; $ regex = $ params [ $ name ] ?? self :: DEFAULT_REGEX ; $ replacePairs [ $ key ] = '(?P<' . $ name . '>' . $ regex . ')' ; } $ route = \ strtr ( $ route , $ replacePairs ) ; } $ first = null ; $ conf [ 'regex' ] = '#^' . $ route . '$#' ; if ( \ preg_match ( '#^/([\w-]+)/[\w-]*/?#' , $ bak , $ m ) ) { $ first = $ m [ 1 ] ; $ conf [ 'start' ] = $ m [ 0 ] ; return [ $ first , $ conf ] ; } $ include = null ; if ( $ noOptional ) { if ( \ strpos ( $ noOptional , '{' ) === false ) { $ include = $ noOptional ; } else { $ bak = $ noOptional ; } } if ( ! $ include && \ preg_match ( '#/([\w-]+)/?[\w-]*#' , $ bak , $ m ) ) { $ include = $ m [ 0 ] ; } $ conf [ 'include' ] = $ include ; return [ $ first , $ conf ] ; }
parse param route
561
public static function convertNodeStr ( $ str ) : string { $ str = \ trim ( $ str , '-' ) ; if ( \ strpos ( $ str , '-' ) ) { $ str = ( string ) \ preg_replace_callback ( '/-+([a-z])/' , function ( $ c ) { return \ strtoupper ( $ c [ 1 ] ) ; } , \ trim ( $ str , '- ' ) ) ; } return $ str ; }
convert first - second to firstSecond
562
protected function getContainer ( ) { if ( ! isset ( $ GLOBALS [ 'container' ] ) ) { $ GLOBALS [ 'container' ] = new PimpleGate ( [ ] , $ this -> getSymfonyContainer ( ) ) ; } $ container = $ GLOBALS [ 'container' ] ; if ( ! $ container instanceof PimpleGate ) { throw new \ RuntimeException ( 'Dependency container is incompatible class. Expected PimpleGate but found ' . get_class ( $ container ) , 1 ) ; } return $ container ; }
Get the currently defined global container or create it if no container is present so far .
563
private function getSymfonyContainer ( ) { if ( method_exists ( 'Contao\System' , 'getContainer' ) && ( $ container = System :: getContainer ( ) ) instanceof ContainerInterface ) { return $ container ; } if ( isset ( $ GLOBALS [ 'kernel' ] ) && $ GLOBALS [ 'kernel' ] instanceof KernelInterface && ( $ container = $ GLOBALS [ 'kernel' ] -> getContainer ( ) ) instanceof ContainerInterface ) { return $ container ; } throw new \ RuntimeException ( 'Could not obtain symfony container.' ) ; }
Determine the symfony container .
564
protected function callHooks ( PimpleGate $ container ) { if ( isset ( $ GLOBALS [ 'TL_HOOKS' ] [ 'initializeDependencyContainer' ] ) && is_array ( $ GLOBALS [ 'TL_HOOKS' ] [ 'initializeDependencyContainer' ] ) ) { foreach ( $ GLOBALS [ 'TL_HOOKS' ] [ 'initializeDependencyContainer' ] as $ callback ) { if ( is_array ( $ callback ) ) { $ class = new \ ReflectionClass ( $ callback [ 0 ] ) ; if ( ! $ class -> hasMethod ( $ callback [ 1 ] ) ) { if ( $ class -> hasMethod ( '__call' ) ) { $ method = $ class -> getMethod ( '__call' ) ; $ args = [ $ callback [ 1 ] , $ container ] ; } else { throw new \ InvalidArgumentException ( sprintf ( 'No such Method %s::%s' , $ callback [ 0 ] , $ callback [ 1 ] ) ) ; } } else { $ method = $ class -> getMethod ( $ callback [ 1 ] ) ; $ args = [ $ container ] ; } $ object = null ; if ( ! $ method -> isStatic ( ) ) { $ object = $ this -> getInstanceOf ( $ callback [ 0 ] ) ; } $ method -> invokeArgs ( $ object , $ args ) ; } else { call_user_func ( $ callback , $ container ) ; } } } }
Call the initialization hooks .
565
private function loadServiceConfigurations ( PimpleGate $ container ) { $ paths = $ container -> getSymfonyParameter ( 'cca.legacy_dic' ) ; foreach ( $ paths as $ file ) { require_once $ file ; } }
Load all services files .
566
public function init ( ) { $ container = $ this -> getContainer ( ) ; $ this -> loadServiceConfigurations ( $ container ) ; $ this -> callHooks ( $ container ) ; }
Init the global dependency container .
567
public function render ( $ size , array $ parts ) { ArgumentChecker :: check ( $ size , 'integer' ) ; $ this -> calculateTotal ( $ parts ) ; $ this -> size = $ size ; $ this -> parts = $ parts ; $ r = '' ; foreach ( $ parts as $ color => $ x ) { $ bars = $ this -> valueToBars ( $ x ) ; $ r .= $ this -> colorSpaces ( $ bars , $ color ) ; } $ r = $ this -> fillToSize ( $ r ) ; return $ r ; }
Render the progress bar .
568
public function createUserService ( ) { $ config = $ this -> container -> get ( 'cca.legacy_dic.contao_config' ) ; if ( ! $ config -> get ( 'dbDatabase' ) ) { throw new \ RuntimeException ( 'Contao Database is not properly configured.' ) ; } $ matcher = $ this -> container -> get ( 'contao.routing.scope_matcher' ) ; $ request = $ this -> container -> get ( 'request_stack' ) -> getCurrentRequest ( ) ; if ( ( null === $ request ) || $ matcher -> isBackendRequest ( $ request ) ) { return $ this -> container -> get ( 'contao.framework' ) -> createInstance ( BackendUser :: class ) ; } if ( $ matcher -> isFrontendRequest ( $ request ) ) { return $ this -> container -> get ( 'contao.framework' ) -> createInstance ( FrontendUser :: class ) ; } throw new \ RuntimeException ( 'Unknown TL_MODE encountered' , 1 ) ; }
Create the user service for contao user .
569
public function createPageProviderService ( ) { $ pageProvider = new PageProvider ( ) ; if ( isset ( $ GLOBALS [ 'TL_HOOKS' ] [ 'getPageLayout' ] ) && is_array ( $ GLOBALS [ 'TL_HOOKS' ] [ 'getPageLayout' ] ) ) { array_unshift ( $ GLOBALS [ 'TL_HOOKS' ] [ 'getPageLayout' ] , [ PageProvider :: class , 'setPage' ] ) ; } else { $ GLOBALS [ 'TL_HOOKS' ] [ 'getPageLayout' ] = [ [ PageProvider :: class , 'setPage' ] ] ; } return $ pageProvider ; }
Create the page provider service for provide the current active page model .
570
public function doHandler ( ServerRequestInterface $ request , array $ routeInfo ) { list ( $ status , $ path , $ info ) = $ routeInfo ; if ( $ status === HandlerMapping :: NOT_FOUND ) { throw new RouteNotFoundException ( 'Route not found for ' . $ path ) ; } if ( $ status === HandlerMapping :: METHOD_NOT_ALLOWED ) { throw new MethodNotAllowedException ( sprintf ( "Method '%s' not allowed for access %s, Allow: %s" , $ request -> getMethod ( ) , $ path , \ implode ( ',' , $ routeInfo [ 2 ] ) ) ) ; } list ( $ handler , $ matches ) = $ this -> createHandler ( $ path , $ info ) ; if ( \ is_array ( $ handler ) ) { $ handler = $ this -> defaultHandler ( $ handler ) ; } $ params = $ this -> bindParams ( $ request , $ handler , $ matches ) ; $ response = PhpHelper :: call ( $ handler , $ params ) ; if ( ! $ response instanceof Response ) { $ newResponse = RequestContext :: getResponse ( ) ; if ( $ response instanceof Payload ) { $ response = $ newResponse -> withStatus ( $ response -> getStatus ( ) ) -> withAttribute ( AttributeEnum :: RESPONSE_ATTRIBUTE , $ response -> data ) ; } else { $ response = $ newResponse -> withAttribute ( AttributeEnum :: RESPONSE_ATTRIBUTE , $ response ) ; } } return $ response ; }
Execute handler with controller and action
571
private function bindParams ( ServerRequestInterface $ request , $ handler , array $ matches ) : array { if ( \ is_array ( $ handler ) ) { list ( $ controller , $ method ) = $ handler ; $ reflectMethod = new \ ReflectionMethod ( $ controller , $ method ) ; $ reflectParams = $ reflectMethod -> getParameters ( ) ; } else { $ reflectMethod = new \ ReflectionFunction ( $ handler ) ; $ reflectParams = $ reflectMethod -> getParameters ( ) ; } $ bindParams = [ ] ; foreach ( $ reflectParams as $ key => $ reflectParam ) { $ reflectType = $ reflectParam -> getType ( ) ; $ name = $ reflectParam -> getName ( ) ; if ( $ reflectType === null ) { if ( isset ( $ matches [ $ name ] ) ) { $ bindParams [ $ key ] = $ matches [ $ name ] ; } else { $ bindParams [ $ key ] = null ; } continue ; } $ type = $ reflectType -> __toString ( ) ; if ( $ type === Request :: class ) { $ bindParams [ $ key ] = $ request ; } elseif ( $ type === Response :: class ) { $ bindParams [ $ key ] = RequestContext :: getResponse ( ) ; } elseif ( isset ( $ matches [ $ name ] ) ) { $ bindParams [ $ key ] = $ this -> parserParamType ( $ type , $ matches [ $ name ] ) ; } elseif ( App :: hasBean ( $ type ) ) { $ bindParams [ $ key ] = App :: getBean ( $ type ) ; } elseif ( \ class_exists ( $ type ) ) { $ bindParams [ $ key ] = $ this -> bindRequestParamsToClass ( $ request , new \ ReflectionClass ( $ type ) ) ; } else { $ bindParams [ $ key ] = $ this -> getDefaultValue ( $ type ) ; } } return $ bindParams ; }
Binding params of action method
572
private function bindRequestParamsToClass ( ServerRequestInterface $ request , \ ReflectionClass $ reflectClass ) { try { $ object = $ reflectClass -> newInstance ( ) ; $ queryParams = $ request -> getQueryParams ( ) ; if ( StringHelper :: startsWith ( $ request -> getHeaderLine ( 'Content-Type' ) , 'application/json' ) ) { $ requestBody = JsonHelper :: decode ( $ request -> getBody ( ) -> getContents ( ) , true ) ; } else { $ requestBody = $ request -> getParsedBody ( ) ; } $ requestParams = array_merge ( $ queryParams , $ requestBody ) ; $ properties = $ reflectClass -> getProperties ( ) ; foreach ( $ properties as $ property ) { $ name = $ property -> getName ( ) ; if ( ! isset ( $ requestParams [ $ name ] ) ) { continue ; } if ( ! $ property -> isPublic ( ) ) { $ property -> setAccessible ( true ) ; } $ property -> setValue ( $ object , $ requestParams [ $ name ] ) ; } } catch ( \ Exception $ e ) { $ object = null ; } return $ object ; }
Bind request parameters to instance of ReflectClass
573
private function parserParamType ( string $ type , $ value ) { switch ( $ type ) { case 'int' : $ value = ( int ) $ value ; break ; case 'string' : $ value = ( string ) $ value ; break ; case 'bool' : $ value = ( bool ) $ value ; break ; case 'float' : $ value = ( float ) $ value ; break ; case 'double' : $ value = ( double ) $ value ; break ; } return $ value ; }
parser the type of binding param
574
private function getDefaultValue ( string $ type ) { $ value = null ; switch ( $ type ) { case 'int' : $ value = 0 ; break ; case 'string' : $ value = '' ; break ; case 'bool' : $ value = false ; break ; case 'float' : $ value = 0 ; break ; case 'double' : $ value = 0 ; break ; } return $ value ; }
the default value of param
575
public function setContainerClass ( string $ containerClass ) { if ( ! \ class_exists ( $ containerClass ) || ( $ containerClass !== DIContainer :: class && ! \ is_subclass_of ( $ containerClass , DIContainer :: class ) ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'class "%s" must extend %s' , $ containerClass , DIContainer :: class ) ) ; } $ this -> containerClass = $ containerClass ; return $ this ; }
Set container class .
576
public function setProxiesPath ( string $ proxiesPath ) { if ( ! \ file_exists ( $ proxiesPath ) || ! \ is_dir ( $ proxiesPath ) || ! \ is_writable ( $ proxiesPath ) ) { throw new \ RuntimeException ( \ sprintf ( '%s directory does not exist or is write protected' , $ proxiesPath ) ) ; } $ this -> proxiesPath = $ proxiesPath ; return $ this ; }
Set proxies path .
577
public function setCompilationPath ( string $ compilationPath ) { if ( ! \ file_exists ( $ compilationPath ) || ! \ is_dir ( $ compilationPath ) || ! \ is_writable ( $ compilationPath ) ) { throw new \ RuntimeException ( \ sprintf ( '%s directory does not exist or is write protected' , $ compilationPath ) ) ; } $ this -> compilationPath = $ compilationPath ; return $ this ; }
Set compilation path .
578
public function setCompiledContainerClass ( string $ compiledContainerClass ) { if ( ! \ class_exists ( $ compiledContainerClass ) || ( $ compiledContainerClass !== DICompiledContainer :: class && ! \ is_subclass_of ( $ compiledContainerClass , DICompiledContainer :: class ) ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'class "%s" must extend %s' , $ compiledContainerClass , DICompiledContainer :: class ) ) ; } $ this -> compiledContainerClass = $ compiledContainerClass ; return $ this ; }
Set compiled container class .
579
public function setDefinitions ( $ definitions ) { if ( \ is_string ( $ definitions ) ) { $ definitions = [ $ definitions ] ; } if ( $ definitions instanceof \ Traversable ) { $ definitions = \ iterator_to_array ( $ definitions ) ; } if ( ! \ is_array ( $ definitions ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Definitions must be a string or traversable. %s given' , \ gettype ( $ definitions ) ) ) ; } \ array_walk ( $ definitions , function ( $ definition ) { if ( ! \ is_array ( $ definition ) && ! \ is_string ( $ definition ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'A definition must be an array or a file or directory path. %s given' , \ gettype ( $ definition ) ) ) ; } } ) ; $ this -> definitions = $ definitions ; return $ this ; }
Set definitions .
580
protected function whereNested ( Builder $ query , $ where ) { $ nested = $ where [ 'query' ] ; return '(' . substr ( $ this -> compileWheres ( $ nested ) , 6 ) . ')' ; }
Compile a nested where clause .
581
protected function whereInSub ( Builder $ query , $ where ) { $ select = $ this -> compileSelect ( $ where [ 'query' ] ) ; return $ this -> wrap ( $ where [ 'column' ] ) . ' in (' . $ select . ')' ; }
Compile a where in sub - select clause .
582
protected function restrict ( ) { $ length = strlen ( $ this -> data ) ; if ( $ length > 0 ) { $ this -> data [ $ length - 1 ] = chr ( ord ( $ this -> data [ $ length - 1 ] ) & self :: $ restrict [ $ this -> size % 8 ] ) ; } return $ this ; }
Remove useless bits for simplifying count operation .
583
public function offsetGet ( $ offset ) { if ( $ this -> offsetExists ( $ offset ) ) { return ( bool ) ( ord ( $ this -> data [ ( int ) ( $ offset / 8 ) ] ) & ( 1 << $ offset % 8 ) ) ; } else { throw new \ OutOfRangeException ( 'Argument offset must be a positive integer lesser than the size' ) ; } }
Get the truth value for an index
584
public function offsetSet ( $ offset , $ value ) { if ( $ this -> offsetExists ( $ offset ) ) { $ index = ( int ) ( $ offset / 8 ) ; if ( $ value ) { $ this -> data [ $ index ] = chr ( ord ( $ this -> data [ $ index ] ) | ( 1 << $ offset % 8 ) ) ; } else { $ this -> data [ $ index ] = chr ( ord ( $ this -> data [ $ index ] ) & ~ ( 1 << $ offset % 8 ) ) ; } } else { throw new \ OutOfRangeException ( 'Argument index must be a positive integer lesser than the size' ) ; } }
Set the truth value for an index
585
public function count ( ) { $ count = 0 ; for ( $ index = 0 , $ length = strlen ( $ this -> data ) ; $ index < $ length ; $ index ++ ) { $ count += self :: $ count [ ord ( $ this -> data [ $ index ] ) ] ; } return $ count ; }
Return the number of true bits
586
public function toArray ( ) { $ array = array ( ) ; for ( $ index = 0 ; $ index < $ this -> size ; $ index ++ ) { $ array [ ] = ( bool ) ( ord ( $ this -> data [ ( int ) ( $ index / 8 ) ] ) & ( 1 << $ index % 8 ) ) ; } return $ array ; }
Transform the object to an array
587
public function directCopy ( BitArray $ bits , $ index = 0 , $ offset = 0 , $ size = 0 ) { if ( $ offset > $ index ) { for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { $ this [ $ i + $ index ] = $ bits [ $ i + $ offset ] ; } } else { for ( $ i = $ size - 1 ; $ i >= 0 ; $ i -- ) { $ this [ $ i + $ index ] = $ bits [ $ i + $ offset ] ; } } return $ this ; }
Copy bits directly from a BitArray
588
public function copy ( BitArray $ bits , $ index = 0 , $ offset = 0 , $ size = null ) { $ index = $ this -> getRealOffset ( $ index ) ; $ offset = $ bits -> getRealOffset ( $ offset ) ; $ size = $ bits -> getRealSize ( $ offset , $ size ) ; if ( $ size > $ this -> size - $ index ) { $ size = $ this -> size - $ index ; } return $ this -> directCopy ( $ bits , $ index , $ offset , $ size ) ; }
Copy bits from a BitArray
589
public static function fromDecimal ( $ size , $ values = 0 ) { $ size = min ( ( int ) $ size , PHP_INT_SIZE ) ; $ values <<= PHP_INT_SIZE - $ size ; $ bits = new BitArray ( $ size ) ; for ( $ i = 0 ; $ i < PHP_INT_SIZE ; $ i ++ ) { $ bits -> data [ $ i ] = chr ( ( $ values & ( 0xff << ( PHP_INT_SIZE - 8 ) ) ) >> ( PHP_INT_SIZE - 8 ) ) ; $ values <<= 8 ; } return $ bits ; }
Create a new BitArray from a sequence of bits .
590
public static function fromTraversable ( $ traversable ) { $ bits = new BitArray ( count ( $ traversable ) ) ; $ offset = 0 ; $ ord = 0 ; foreach ( $ traversable as $ value ) { if ( $ value ) { $ ord |= 1 << $ offset % 8 ; } if ( $ offset % 8 === 7 ) { $ bits -> data [ ( int ) ( $ offset / 8 ) ] = chr ( $ ord ) ; $ ord = 0 ; } $ offset ++ ; } if ( $ offset % 8 !== 0 ) { $ bits -> data [ ( int ) ( $ offset / 8 ) ] = chr ( $ ord ) ; } return $ bits ; }
Create a new BitArray from a traversable
591
public static function fromString ( $ string ) { $ bits = new BitArray ( strlen ( $ string ) ) ; $ ord = 0 ; for ( $ offset = 0 ; $ offset < $ bits -> size ; $ offset ++ ) { if ( $ string [ $ offset ] !== '0' ) { $ ord |= 1 << $ offset % 8 ; } if ( $ offset % 8 === 7 ) { $ bits -> data [ ( int ) ( $ offset / 8 ) ] = chr ( $ ord ) ; $ ord = 0 ; } } if ( $ offset % 8 !== 0 ) { $ bits -> data [ ( int ) ( $ offset / 8 ) ] = chr ( $ ord ) ; } return $ bits ; }
Create a new BitArray from a bit string
592
public static function fromSlice ( BitArray $ bits , $ offset = 0 , $ size = null ) { $ offset = $ bits -> getRealOffset ( $ offset ) ; $ size = $ bits -> getRealSize ( $ offset , $ size ) ; $ slice = new BitArray ( $ size ) ; return $ slice -> directCopy ( $ bits , 0 , $ offset , $ size ) ; }
Create a new BitArray using a slice
593
public static function fromConcat ( BitArray $ bits1 , BitArray $ bits2 ) { $ size = $ bits1 -> size + $ bits2 -> size ; $ concat = new BitArray ( $ size ) ; $ concat -> directCopy ( $ bits1 , 0 , 0 , $ bits1 -> size ) ; $ concat -> directCopy ( $ bits2 , $ bits1 -> size , 0 , $ bits2 -> size ) ; return $ concat ; }
Create a new BitArray using the concat operation
594
public function applyComplement ( ) { $ length = strlen ( $ this -> data ) ; for ( $ index = 0 ; $ index < $ length ; $ index ++ ) { $ this -> data [ $ index ] = chr ( ~ ord ( $ this -> data [ $ index ] ) ) ; } return $ this -> restrict ( ) ; }
Complement the bit array
595
public function applyXor ( BitArray $ bits ) { if ( $ this -> size == $ bits -> size ) { $ length = strlen ( $ this -> data ) ; for ( $ index = 0 ; $ index < $ length ; $ index ++ ) { $ this -> data [ $ index ] = chr ( ord ( $ this -> data [ $ index ] ) ^ ord ( $ bits -> data [ $ index ] ) ) ; } return $ this ; } else { throw new \ InvalidArgumentException ( 'Argument must be of equal size' ) ; } }
Xor with an another bit array
596
public function shift ( $ size = 1 , $ value = false ) { $ size = ( int ) $ size ; if ( $ size > 0 ) { $ min = min ( $ this -> size , $ size ) ; for ( $ i = $ this -> size - 1 ; $ i >= $ min ; $ i -- ) { $ this [ $ i ] = $ this [ $ i - $ min ] ; } for ( $ i = 0 ; $ i < $ min ; $ i ++ ) { $ this [ $ i ] = $ value ; } } else { $ min = min ( $ this -> size , - $ size ) ; for ( $ i = 0 ; $ i < $ this -> size - $ min ; $ i ++ ) { $ this [ $ i ] = $ this [ $ i + $ min ] ; } for ( $ i = $ this -> size - $ min ; $ i < $ this -> size ; $ i ++ ) { $ this [ $ i ] = $ value ; } } return $ this ; }
Shift a bit array .
597
public function registerTemplateEngine ( $ resolver ) { $ app = $ this -> app ; $ app -> bindShared ( 'template.compiler' , function ( $ app ) { $ cachePath = $ app [ 'config' ] [ 'view.compiled' ] ; return new TemplateCompiler ( $ app [ 'files' ] , $ cachePath ) ; } ) ; $ resolver -> register ( 'template' , function ( ) use ( $ app ) { return new CompilerEngine ( $ app [ 'template.compiler' ] , $ app [ 'files' ] ) ; } ) ; }
Register the Template engine implementation .
598
public function registerMarkdownEngine ( $ resolver ) { $ app = $ this -> app ; $ app -> bindShared ( 'markdown.compiler' , function ( $ app ) { $ cachePath = $ app [ 'config' ] [ 'view.compiled' ] ; return new MarkdownCompiler ( $ app [ 'files' ] , $ cachePath ) ; } ) ; $ resolver -> register ( 'markdown' , function ( ) use ( $ app ) { return new CompilerEngine ( $ app [ 'markdown.compiler' ] , $ app [ 'files' ] ) ; } ) ; }
Register the Markdown engine implementation .
599
public function registerFactory ( ) { $ this -> app -> bindShared ( 'view' , function ( $ app ) { $ resolver = $ app [ 'view.engine.resolver' ] ; $ finder = $ app [ 'view.finder' ] ; $ factory = new Factory ( $ resolver , $ finder , $ app [ 'events' ] ) ; $ factory -> setContainer ( $ app ) ; $ factory -> share ( 'app' , $ app ) ; return $ factory ; } ) ; }
Register the View Factory .