idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
24,200 | public function createHydratorFor ( $ objectClass ) { $ metadata = $ this -> getMetadata ( $ objectClass ) ; $ propertyAccessStrategy = $ metadata -> isPropertyAccessStrategyEnabled ( ) ; $ hydrator = new Hydrator \ Hydrator ( $ this , $ propertyAccessStrategy ) ; if ( $ this -> classResolver ) { $ hydrator -> setClassResolver ( $ this -> classResolver ) ; } $ fieldsWithHydrationStrategy = $ metadata -> computeFieldsWithHydrationStrategy ( ) ; $ mappedFieldNames = $ metadata -> getMappedFieldNames ( ) ; foreach ( $ mappedFieldNames as $ mappedFieldName ) { $ strategy = null ; if ( $ metadata -> isMappedFieldWithStrategy ( $ mappedFieldName ) ) { $ fieldStrategy = $ fieldsWithHydrationStrategy [ $ mappedFieldName ] ; $ strategy = new ClosureHydrationStrategy ( $ fieldStrategy [ $ metadata :: INDEX_EXTRACTION_STRATEGY ] , $ fieldStrategy [ $ metadata :: INDEX_HYDRATION_STRATEGY ] ) ; } if ( $ metadata -> isMappedDateField ( $ mappedFieldName ) ) { $ readDateConverter = $ metadata -> getReadDateFormatByMappedField ( $ mappedFieldName , null ) ; $ writeDateConverter = $ metadata -> getWriteDateFormatByMappedField ( $ mappedFieldName , null ) ; if ( ! is_null ( $ readDateConverter ) && ! is_null ( $ writeDateConverter ) ) { $ strategy = new DateHydrationStrategy ( $ readDateConverter , $ writeDateConverter , $ strategy ) ; } else { throw new ObjectMappingException ( sprintf ( 'The date field "%s" should provide "readDateConverter" and "writeDateConverter" metadata.' , $ mappedFieldName ) ) ; } } if ( ! is_null ( $ strategy ) ) { $ hydrator -> addStrategy ( $ mappedFieldName , $ strategy ) ; } } if ( $ metadata -> eventsExist ( ) ) { $ hydrator = new Hydrator \ EventHydrator ( $ hydrator , $ this ) ; } return $ hydrator ; } | Factory method to create an hydrator . |
24,201 | public function getMetadata ( $ objectClass ) { if ( ! $ objectClass instanceof ObjectKey ) { $ objectClass = new ObjectKey ( $ objectClass ) ; } $ key = $ objectClass -> getKey ( ) ; return $ this -> classMetadataFactory -> loadMetadata ( $ objectClass , LoadingCriteria :: createFromConfiguration ( $ this -> configuration , $ objectClass ) , $ this -> configuration ) ; } | Return the class metadata . |
24,202 | public function instance ( ) { $ settings = $ this -> getValidatedSettings ( ) ; $ objectManager = $ this -> createObjectManager ( $ settings ) ; $ logger = isset ( $ settings [ 'logger' ] ) ? isset ( $ settings [ 'logger' ] ) : null ; $ this -> initializeRegistry ( $ objectManager , $ logger ) ; return new DataMapper ( $ objectManager ) ; } | Instantiate a DataMapper from settings |
24,203 | private function getValidatedSettings ( ) { $ processor = new Processor ( ) ; $ settingsValidator = new SettingsValidator ( ) ; $ validatedSettings = $ processor -> processConfiguration ( $ settingsValidator , $ this -> pSettings ) ; return $ validatedSettings ; } | Validates settings and reduces them if multiple settings given . |
24,204 | private function getItemKey ( string $ sectionHandle , array $ requestedFields = null , string $ context = null , string $ id = null ) : string { return sha1 ( $ sectionHandle ) . $ this -> getFieldKey ( $ requestedFields ) . $ this -> getContextKey ( $ context ) . $ this -> getIdKey ( $ id ) ; } | Get the key for the item so the key will be unique for this specific cache item and can t be unexpectedly overridden . |
24,205 | private function getFieldKey ( array $ requestedFields = null ) : string { if ( is_null ( $ requestedFields ) ) { return 'no-field-key' ; } return $ fieldKey = '.' . sha1 ( implode ( ',' , $ requestedFields ) ) ; } | A lot of calls contain the fields one want s to have in return . Make sure this is also added to the item key . |
24,206 | private function getRelationships ( FullyQualifiedClassName $ fullyQualifiedClassName ) : array { $ fields = ( string ) $ fullyQualifiedClassName ; if ( ! is_subclass_of ( $ fields , CommonSectionInterface :: class ) ) { throw new NotASexyFieldEntityException ; } $ relationships = [ ] ; foreach ( $ fields :: fieldInfo ( ) as $ field ) { if ( ! is_null ( $ field [ 'relationship' ] ) ) { $ relationships [ ] = $ field [ 'relationship' ] [ 'class' ] ; } } return $ relationships ; } | Entries can have relationships make sure to tag them . |
24,207 | public function getIndices ( ) { $ indices = $ this -> indices ( ) ; if ( empty ( $ indices ) ) { $ className = ( new \ ReflectionClass ( $ this ) ) -> getShortName ( ) ; return [ $ className ] ; } return $ indices ; } | Returns an array of indices for this model . |
24,208 | public function exists ( UserInterface $ user , $ code = null ) { return $ this -> findIncomplete ( $ user , $ code ) !== null ; } | Check if a valid reminder exists . |
24,209 | public function complete ( UserInterface $ user , $ code , $ password ) { $ reminder = $ this -> findIncomplete ( $ user , $ code ) ; if ( $ reminder === null ) { return false ; } $ credentials = [ 'password' => $ password ] ; if ( ! $ this -> users -> validForUpdate ( $ user , $ credentials ) ) { return false ; } $ entityManager = $ this -> getEntityManager ( ) ; $ entityManager -> beginTransaction ( ) ; try { $ this -> users -> update ( $ user , $ credentials ) ; $ reminder -> complete ( ) ; $ this -> save ( $ reminder ) ; $ entityManager -> commit ( ) ; return true ; } catch ( \ Exception $ e ) { $ entityManager -> rollback ( ) ; return false ; } } | Complete reminder for the given user . |
24,210 | public function make ( AlgoliaConfig $ config ) { return new AlgoliaManager ( new Client ( $ config -> getApplicationId ( ) , $ config -> getApiKey ( ) , $ config -> getHostsArray ( ) , $ config -> getOptions ( ) ) , new ActiveRecordFactory ( ) , new ActiveQueryChunker ( ) ) ; } | Makes a new Algolia Client . |
24,211 | protected function sendRequestThroughRouter ( Request $ request ) { return ( new Pipeline ( $ this -> app ) ) -> send ( $ request ) -> then ( function ( $ request ) { $ response = $ this -> router -> dispatch ( $ request ) ; if ( property_exists ( $ response , 'exception' ) && $ response -> exception instanceof Exception ) { throw $ response -> exception ; } return $ response ; } ) ; } | Send the request through the Songshenzong router . |
24,212 | private function generateCacheKey ( $ method , $ uri , array $ options = [ ] ) { return sha1 ( sprintf ( '%s.%s.%s.%s' , get_class ( $ this ) , $ method , $ uri , json_encode ( $ options ) ) ) ; } | Generates the cache key based on the class name request method uri and options . |
24,213 | private function isCacheable ( $ method , $ uri , array $ options , $ response ) { $ statusCode = $ response -> getStatusCode ( ) ; if ( $ statusCode < 200 || $ statusCode >= 300 ) { return false ; } if ( 'GET' === $ method ) { return true ; } if ( 'POST' === $ method ) { return in_array ( $ uri , self :: CACHEABLE_POST_ENDPOINTS ) ; } return false ; } | Checks if the request may be cached . |
24,214 | public function query ( $ q = null ) { return User :: where ( function ( $ query ) use ( $ q ) { $ query -> where ( 'email' , 'like' , "%{$q}" ) -> orWhere ( 'name' , 'like' , "%{$q}" ) ; } ) -> orderBy ( 'email' ) -> paginate ( ) ; } | Queries the repository and returns a paginated result . |
24,215 | protected function shouldIgnore ( FieldInterface $ field ) : bool { $ fieldType = $ this -> container -> get ( ( string ) $ field -> getFieldType ( ) -> getFullyQualifiedClassName ( ) ) ; $ fieldTypeGeneratorConfig = $ fieldType -> getFieldTypeGeneratorConfig ( ) -> toArray ( ) ; if ( ! key_exists ( static :: GENERATE_FOR , $ fieldTypeGeneratorConfig ) ) { return true ; } try { $ fieldGeneratorConfig = $ field -> getConfig ( ) -> getGeneratorConfig ( ) -> toArray ( ) ; if ( ! empty ( $ fieldGeneratorConfig [ static :: GENERATE_FOR ] [ 'ignore' ] ) && $ fieldGeneratorConfig [ static :: GENERATE_FOR ] [ 'ignore' ] ) { return true ; } } catch ( \ Exception $ exception ) { } return false ; } | There are scenario s in which a field should be ignored by a generator |
24,216 | protected function getFieldTypeTemplateDirectory ( FieldInterface $ field , string $ supportingDirectory ) { $ fieldType = $ this -> container -> get ( ( string ) $ field -> getFieldType ( ) -> getFullyQualifiedClassName ( ) ) ; $ fieldTypeDirectory = explode ( '/' , $ fieldType -> directory ( ) ) ; foreach ( $ fieldTypeDirectory as $ key => $ segment ) { if ( $ segment === 'vendor' ) { $ selector = $ key + 2 ; $ fieldTypeDirectory [ $ selector ] = $ supportingDirectory ; break ; } } return implode ( '/' , $ fieldTypeDirectory ) ; } | The field type generator templates are to be defined in the packages that provide the specific support for what is to be generated |
24,217 | private function applyWatermarkImagick ( Imagick $ image ) { $ pictureWidth = $ image -> getImageWidth ( ) ; $ pictureHeight = $ image -> getImageHeight ( ) ; $ watermarkPicture = new Picture ( $ this -> watermark , NULL , Picture :: WORKER_IMAGICK ) ; $ opacity = new Opacity ( $ this -> opacity ) ; $ opacity -> apply ( $ watermarkPicture ) ; if ( $ this -> size ) { $ resize = new Resize ( $ pictureWidth / 100 * $ this -> size , $ pictureHeight / 100 * $ this -> size , Resize :: MODE_FIT ) ; $ resize -> apply ( $ watermarkPicture ) ; } $ watermark = $ watermarkPicture -> getResource ( Picture :: WORKER_IMAGICK ) ; $ watermarkWidth = $ watermark -> getImageWidth ( ) ; $ watermarkHeight = $ watermark -> getImageHeight ( ) ; switch ( $ this -> position ) { case 'repeat' : for ( $ w = 0 ; $ w < $ pictureWidth ; $ w += $ watermarkWidth + $ this -> space ) { for ( $ h = 0 ; $ h < $ pictureHeight ; $ h += $ watermarkHeight + $ this -> space ) { $ image -> compositeImage ( $ watermark , $ watermark -> getImageCompose ( ) , $ w , $ h ) ; } } return ; case 'center' : $ positionX = ( $ image -> getImageWidth ( ) - $ watermark -> getImageWidth ( ) ) / 2 - $ this -> offsetX ; $ positionY = ( $ image -> getImageHeight ( ) - $ watermark -> getImageHeight ( ) ) / 2 - $ this -> offsetY ; break ; case 'topRight' : $ positionX = $ image -> getImageWidth ( ) - $ watermark -> getImageWidth ( ) - $ this -> offsetX ; $ positionY = $ this -> offsetY ; break ; case 'bottomRight' : $ positionX = $ image -> getImageWidth ( ) - $ watermark -> getImageWidth ( ) - $ this -> offsetX ; $ positionY = $ image -> getImageHeight ( ) - $ watermark -> getImageHeight ( ) - $ this -> offsetY ; break ; case 'bottomLeft' : $ positionX = $ this -> offsetX ; $ positionY = $ image -> getImageHeight ( ) - $ watermark -> getImageHeight ( ) - $ this -> offsetY ; break ; default : $ positionX = $ this -> offsetX ; $ positionY = $ this -> offsetY ; break ; } $ image -> compositeImage ( $ watermark , $ watermark -> getImageCompose ( ) , $ positionX , $ positionY ) ; } | Watermark effect processed by Imagick |
24,218 | protected function applyWatermarkGD ( $ resource , Picture $ picture ) { $ pictureWidth = imagesx ( $ resource ) ; $ pictureHeight = imagesy ( $ resource ) ; $ watermarkPicture = new Picture ( $ this -> watermark , NULL , Picture :: WORKER_GD ) ; $ opacity = new Opacity ( $ this -> opacity ) ; $ opacity -> apply ( $ watermarkPicture ) ; if ( $ this -> size ) { $ resize = new Resize ( $ pictureWidth / 100 * $ this -> size , $ pictureHeight / 100 * $ this -> size , Resize :: MODE_FIT ) ; $ resize -> apply ( $ watermarkPicture ) ; } $ watermark = $ watermarkPicture -> getResource ( $ watermarkPicture :: WORKER_GD ) ; imagealphablending ( $ watermark , TRUE ) ; $ watermarkWidth = imagesx ( $ watermark ) ; $ watermarkHeight = imagesx ( $ watermark ) ; switch ( $ this -> position ) { case 'repeat' : for ( $ w = 0 ; $ w < $ pictureWidth ; $ w += $ watermarkWidth + $ this -> space ) { for ( $ h = 0 ; $ h < $ pictureHeight ; $ h += $ watermarkHeight + $ this -> space ) { imagecopy ( $ resource , $ watermark , $ w , $ h , 0 , 0 , $ watermarkWidth , $ watermarkHeight ) ; } } return $ resource ; case 'center' : $ positionX = ( $ pictureWidth - $ watermarkWidth ) / 2 - $ this -> offsetX ; $ positionY = ( $ pictureHeight - $ watermarkHeight ) / 2 - $ this -> offsetY ; break ; case 'topRight' : $ positionX = $ pictureWidth - $ watermarkWidth - $ this -> offsetX ; $ positionY = $ this -> offsetY ; break ; case 'bottomRight' : $ positionX = $ pictureWidth - $ watermarkWidth - $ this -> offsetX ; $ positionY = $ pictureHeight - $ watermarkHeight - $ this -> offsetY ; break ; case 'bottomLeft' : $ positionX = $ this -> offsetX ; $ positionY = $ pictureHeight - $ watermarkHeight - $ this -> offsetY ; break ; default : $ positionX = $ this -> offsetX ; $ positionY = $ this -> offsetY ; break ; } imagecopy ( $ resource , $ watermark , $ positionX , $ positionY , 0 , 0 , $ watermarkWidth , $ watermarkHeight ) ; return $ resource ; } | Watermark effect processed by gd |
24,219 | public function run ( Request $ request = null ) { \ ini_set ( 'display_errors' , $ this -> config [ 'debug' ] ? 1 : 0 ) ; \ ini_set ( 'display_startup_errors' , $ this -> config [ 'debug' ] ? 1 : 0 ) ; \ date_default_timezone_set ( $ this -> config [ 'timezone' ] ) ; foreach ( $ this -> routes as $ r => & $ x ) { if ( isset ( $ x [ 'controller' ] ) ) { $ this -> router -> map ( $ x [ 'method' ] , $ r , $ x [ 'action' ] , $ x [ 'controller' ] ) ; } else foreach ( $ x as & $ xx ) { $ this -> router -> map ( $ xx [ 'method' ] , $ r , $ xx [ 'action' ] , $ xx [ 'controller' ] ) ; } } try { try { $ this -> router -> dispatch ( $ request === null ? Request :: createFromGlobals ( ) : $ request , new class ( ( new MultiControllerFactory ( ... $ this -> controller_factories ) ) -> close ( ) , $ this -> endobox , $ this -> logger , $ this -> config [ 'app-namespace' ] ) extends ControllerFactoryDecorator { private $ endobox ; private $ logger ; private $ namespace ; public function __construct ( ControllerFactory $ factory , BoxFactory $ endobox , Logger $ logger , string $ namespace ) { parent :: __construct ( $ factory ) ; $ this -> endobox = $ endobox ; $ this -> logger = $ logger ; $ this -> namespace = $ namespace ; } public function create ( string $ type ) : ? Controller { return parent :: create ( '\\' . $ this -> namespace . '\\controllers\\' . $ type ) -> setBoxFactory ( $ this -> endobox ) -> setLogger ( $ this -> logger ) ; } } ) ; } catch ( \ Klein \ Exceptions \ UnhandledException $ e ) { throw new \ RuntimeException ( \ sprintf ( "%s: %s\n<pre>%s</pre>" , \ get_class ( $ e ) , $ e -> getMessage ( ) , $ e -> getTraceAsString ( ) ) , $ e -> getCode ( ) , $ e ) ; } } catch ( \ Exception $ e ) { if ( $ this -> config [ 'catch-exceptions' ] === false ) { throw $ e ; } if ( $ this -> config [ 'debug' ] === true ) { die ( self :: formatException ( $ e ) ) ; } die ( ) ; } return $ this ; } | Entry point for Neo . |
24,220 | public static function make ( string $ country = null ) { if ( empty ( $ country ) ) { $ country = config ( 'default' ) ; } return ( new static ( ) ) -> setCurrency ( $ country ) ; } | Create Static Instance . |
24,221 | public function setCurrency ( $ country = null ) { if ( is_null ( $ country ) ) { $ country = config ( 'currency.default' ) ; } $ config = config ( 'currency.' . $ country ) ; if ( empty ( $ config ) ) { throw new CurrencyNotAvaialbleException ( $ country . ' currency not avaialble.' ) ; } $ this -> currency = $ config ; return $ this ; } | Set Currency . |
24,222 | public function getCurrency ( ) { if ( ! empty ( $ this -> currency ) ) { return $ this -> currency ; } return $ this -> setCurrency ( config ( 'currency.default' ) ) -> getCurrency ( ) ; } | Ge Current Use Currency . |
24,223 | public function toCommon ( int $ amount , bool $ format = true ) : string { $ money = $ this -> castMoney ( $ amount , $ this -> getCurrencySwiftCode ( ) ) ; $ moneyFormatter = new DecimalMoneyFormatter ( new ISOCurrencies ( ) ) ; return ( $ format ) ? number_format ( $ moneyFormatter -> format ( $ money ) , 2 , '.' , ',' ) : $ moneyFormatter -> format ( $ money ) ; } | Convert integer money to common view for the system Instead of 700000 to 7000 . |
24,224 | public function toMachine ( string $ amount , string $ swift_code = '' ) : int { $ swift_code = empty ( $ swift_code ) ? config ( 'currency.default_swift_code' ) : $ swift_code ; return ( new DecimalMoneyParser ( new ISOCurrencies ( ) ) ) -> parse ( preg_replace ( '/[^0-9.-]/im' , '' , $ amount ) , ( new Currency ( $ swift_code ) ) ) -> getAmount ( ) ; } | Return to Database Format . This method intended to be use before save to the database and this need to be call manually . |
24,225 | public function convertFixedRate ( array $ fixedExchange , int $ amount , string $ swift_code ) : MoneyPHP { return ( new Converter ( new ISOCurrencies ( ) , ( new ReversedCurrenciesExchange ( new FixedExchange ( $ fixedExchange ) ) ) ) ) -> convert ( $ this -> castMoney ( $ amount ) , new Currency ( $ swift_code ) ) ; } | Convert Money with given fixed rate . |
24,226 | protected function handleCancel ( CancellationException $ e ) : ? string { throw $ this -> closed ? ( $ e -> getPrevious ( ) ?? $ e ) : $ e ; } | Handle a cancelled read operation . |
24,227 | public static function createUsingErrors ( array $ errors ) { $ message = "An error was encountered reading an XML document:\n" ; foreach ( $ errors as $ error ) { switch ( $ error -> level ) { case LIBXML_ERR_ERROR : $ message .= '[Error] ' ; break ; case LIBXML_ERR_FATAL : $ message .= '[Fatal] ' ; break ; case LIBXML_ERR_WARNING : $ message .= '[Warning] ' ; break ; } $ message .= sprintf ( "[line %d] [column %d] %s in \"%s\".\n" , $ error -> line , $ error -> column , trim ( $ error -> message ) , $ error -> file ) ; } return new self ( $ message ) ; } | Creates a new exception using an array of libXMLError instances . |
24,228 | public function boot ( Application $ app ) { $ self = & $ this ; $ app -> get ( $ app [ 'swaggerui.path' ] , function ( Request $ request ) use ( $ app ) { return str_replace ( array ( '{{swaggerui-root}}' , '{{swagger-docs}}' ) , array ( $ request -> getBasePath ( ) . $ app [ 'swaggerui.path' ] , $ request -> getBasePath ( ) . $ app [ 'swaggerui.apiDocPath' ] ) , file_get_contents ( __DIR__ . '/../../../../public/index.html' ) ) ; } ) ; $ app -> get ( $ app [ 'swaggerui.path' ] . '/{resource}' , function ( $ resource ) use ( $ app ) { $ file = __DIR__ . '/../../../../public/' . $ resource ; if ( is_file ( $ file ) ) { return file_get_contents ( $ file ) ; } return '' ; } ) ; $ app -> get ( $ app [ 'swaggerui.path' ] . '/lib/{resource}' , function ( $ resource ) use ( $ app , $ self ) { return $ self -> getFile ( __DIR__ . '/../../../../public/lib/' . $ resource , 'text/javascript' ) ; } ) ; $ app -> get ( $ app [ 'swaggerui.path' ] . '/css/{resource}' , function ( $ resource ) use ( $ app , $ self ) { return $ self -> getFile ( __DIR__ . '/../../../../public/css/' . $ resource , 'text/css' ) ; } ) ; $ app -> get ( $ app [ 'swaggerui.path' ] . '/images/{resource}' , function ( $ resource ) use ( $ app , $ self ) { return $ self -> getFile ( __DIR__ . '/../../../../public/images/' . $ resource , 'image/png' ) ; } ) ; } | Add routes to the swagger UI documentation browser |
24,229 | public function getFile ( $ path , $ contentType ) { if ( is_file ( $ path ) ) { $ response = new Response ( file_get_contents ( $ path ) ) ; $ response -> headers -> set ( 'Content-Type' , $ contentType ) ; $ response -> setCharset ( 'UTF-8' ) ; return $ response ; } return new Response ( '' , 404 ) ; } | Get a public file |
24,230 | private function addMultiItem ( ) { $ args = func_get_args ( ) ; $ optionKey = array_shift ( $ args ) ; $ this -> items [ ] = sprintf ( "%s:%s" , $ optionKey , implode ( ',' , $ args ) ) ; return $ this ; } | Adds repeating property item . |
24,231 | protected function _getView ( ) : View { if ( ! $ this -> getConfig ( 'view' ) ) { $ view = new View ( ) ; foreach ( $ this -> getConfig ( 'helpers' ) as $ helper ) { $ view -> loadHelper ( $ helper ) ; } $ this -> setConfig ( 'view' , $ view ) ; } return $ this -> getConfig ( 'view' ) ; } | Prepares a View instance with which the given view file will be rendered . |
24,232 | protected function _preparePdf ( $ viewFile , $ viewVars ) : Mpdf { $ mpdf = new Mpdf ( $ this -> _config [ 'mpdfSettings' ] ) ; if ( is_callable ( $ this -> _config [ 'mpdfConfigurationCallback' ] ) ) { $ this -> _config [ 'mpdfConfigurationCallback' ] ( $ mpdf ) ; } $ styles = '' ; if ( $ this -> _config [ 'cssFile' ] ) { $ styles = file_get_contents ( $ this -> _config [ 'cssFile' ] ) ; } if ( $ this -> _config [ 'cssStyles' ] ) { $ styles .= $ this -> _config [ 'cssStyles' ] ; } if ( ! empty ( $ styles ) ) { $ mpdf -> WriteHTML ( $ styles , 1 ) ; } if ( $ this -> _config [ 'pdfSourceFile' ] ) { $ mpdf -> SetImportUse ( ) ; $ pagecount = $ mpdf -> SetSourceFile ( $ this -> _config [ 'pdfSourceFile' ] ) ; if ( $ pagecount > 1 ) { for ( $ i = 0 ; $ i <= $ pagecount ; ++ $ i ) { $ pageNumber = $ i + 1 ; if ( $ pageNumber <= $ pagecount ) { $ importPage = $ mpdf -> ImportPage ( $ pageNumber ) ; $ mpdf -> UseTemplate ( $ importPage ) ; if ( is_array ( $ viewFile ) && isset ( $ viewFile [ $ i ] ) ) { $ mpdf -> WriteHTML ( $ this -> _getView ( ) -> element ( $ viewFile [ $ i ] , $ viewVars ) ) ; } } if ( $ pageNumber < $ pagecount ) { $ mpdf -> AddPage ( ) ; } } } else { $ tplId = $ mpdf -> ImportPage ( $ pagecount ) ; $ mpdf -> SetPageTemplate ( $ tplId ) ; } } return $ mpdf ; } | Instanciate and configure the MPDF instance |
24,233 | public function render ( $ viewFile , array $ options = [ ] ) { $ options = Hash :: merge ( [ 'target' => self :: TARGET_RETURN , 'filename' => 'pdf.pdf' , ] , $ options ) ; $ mpdf = $ this -> _preparePdf ( $ viewFile , $ options [ 'viewVars' ] ) ; $ options [ 'viewVars' ] [ 'mpdf' ] = $ mpdf ; if ( ! is_array ( $ viewFile ) ) { $ wholeString = $ this -> _getView ( ) -> element ( $ viewFile , $ options [ 'viewVars' ] ) ; $ splitLength = ini_get ( 'pcre.backtrack_limit' ) - ( ini_get ( 'pcre.backtrack_limit' ) / 10 ) ; $ splitString = str_split ( $ wholeString , $ splitLength ) ; foreach ( $ splitString as $ string ) { $ mpdf -> WriteHTML ( $ string ) ; } } switch ( $ options [ 'target' ] ) { case self :: TARGET_RETURN : return $ mpdf ; break ; case self :: TARGET_DOWNLOAD : $ mpdf -> Output ( $ options [ 'filename' ] , 'D' ) ; break ; case self :: TARGET_BROWSER : $ mpdf -> Output ( $ options [ 'filename' ] , 'I' ) ; break ; case self :: TARGET_FILE : $ mpdf -> Output ( $ options [ 'filename' ] , 'F' ) ; break ; case self :: TARGET_BINARY : return $ mpdf -> Output ( '' , 'S' ) ; break ; default : throw new \ InvalidArgumentException ( "{$options['target']} is not a valid target" ) ; break ; } } | Render a view file |
24,234 | public function hasAccess ( $ permissions ) { if ( $ this -> permissions -> isEmpty ( ) ) { $ this -> mergePermissions ( $ this -> userPermissions , $ this -> rolePermissions ) ; } if ( func_num_args ( ) > 1 ) { $ permissions = func_get_args ( ) ; } foreach ( ( array ) $ permissions as $ permissionName ) { if ( ! $ this -> allows ( $ permissionName ) ) { return false ; } } return true ; } | Returns if access is available for all given permissions . |
24,235 | protected function add ( Permission $ permission , $ override = true ) { if ( $ override || ! $ this -> permissions -> containsKey ( $ permission -> getName ( ) ) ) { $ this -> permissions -> set ( $ permission -> getName ( ) , $ permission ) ; } } | Adds a permission to the merged permissions Collection . Override logic is handled from outside to enable strict or standard permissions . |
24,236 | protected function allows ( $ permissionName ) { foreach ( $ this -> getMatchingPermissions ( $ permissionName ) as $ key ) { $ permission = $ this -> permissions -> get ( $ key ) ; if ( $ permission -> isAllowed ( ) ) { return true ; } } return false ; } | Check if the given permission is allowed . Only explicitly allowed permissions will return true . |
24,237 | public function setSize ( $ size ) { if ( is_string ( $ size ) && $ parsed = $ this -> parseSizeWord ( $ size ) ) { $ this -> size = $ parsed ; } else { $ this -> size = $ size ; } return $ this ; } | Process and sets size . |
24,238 | public function parse ( AbstractStream $ stream ) { $ value = $ this -> format ( $ this -> read ( $ stream ) ) ; $ this -> validate ( $ value ) ; return $ value ; } | Reads and process value from Stream . |
24,239 | private function format ( $ value ) { if ( is_callable ( $ this -> formatter ) ) { $ value = call_user_func ( $ this -> formatter , $ value , $ this -> dataSet ) ; } return $ value ; } | Applies value formatter to read value . |
24,240 | private function parseSizeWord ( $ word ) { $ sizeWord = strtoupper ( preg_replace ( '/([a-z])([A-Z])/' , '$1_$2' , $ word ) ) ; if ( array_key_exists ( $ sizeWord , $ this -> sizes ) ) { $ size = $ this -> sizes [ $ sizeWord ] ; } else { $ size = 0 ; } return $ size ; } | Process given string and return appropriate size value . |
24,241 | protected function send ( $ url , array $ headers = [ ] , $ body = [ ] ) : ResponseContract { $ endpoint = $ url instanceof EndpointContract ? $ url : static :: to ( $ url ) ; return $ this -> responseWith ( $ this -> client -> send ( 'POST' , $ endpoint , $ headers , $ body ) ) ; } | Send Webhook request . |
24,242 | private function statusComparator ( $ s1 , $ s2 ) { if ( array_search ( $ s1 -> getCode ( ) , $ this -> statusOrder ) === array_search ( $ s2 -> getCode ( ) , $ this -> statusOrder ) ) { return 0 ; } return ( array_search ( $ s1 -> getCode ( ) , $ this -> statusOrder ) < array_search ( $ s2 -> getCode ( ) , $ this -> statusOrder ) ) ? - 1 : 1 ; } | Callable used to order Status . |
24,243 | public function create ( UserInterface $ user ) { $ entity = static :: ENTITY_CLASSNAME ; $ reminder = new $ entity ( $ user ) ; $ this -> save ( $ reminder ) ; return $ reminder ; } | Create a new reminder record and code . |
24,244 | private function makeSerializable ( $ value ) { if ( null === $ value ) { return $ value ; } if ( $ value instanceof Traversable || is_array ( $ value ) ) { $ value = ArrayUtils :: iteratorToArray ( $ value ) ; foreach ( $ value as $ key => $ val ) { $ value [ $ key ] = $ this -> makeSerializable ( $ val ) ; } return $ value ; } if ( is_scalar ( $ value ) ) { return $ value ; } if ( is_resource ( $ value ) ) { return 'resource' ; } return new ObjectStub ( $ value ) ; } | Retrieves a serializable version of a given value |
24,245 | private function makeReal ( $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ key => $ val ) { $ value [ $ key ] = $ this -> makeReal ( $ val ) ; } } if ( $ value instanceof ObjectStub ) { return $ value -> getObject ( ) ; } return $ value ; } | Retrieves a semi - real version of the value |
24,246 | public function getView ( string $ uri , Engine $ engine , $ type = null ) : View { if ( null === $ type ) { $ view = $ this -> getViewFinder ( ) -> find ( [ $ uri ] , $ engine ) ; return $ view -> setBuilder ( $ this ) ; } return $ this -> resolveType ( $ type , $ uri , $ engine ) ; } | Get a view for a given URI engine and type . |
24,247 | public function addLocation ( Location $ location ) { $ this -> locations -> add ( $ location ) ; unset ( $ this -> viewPathCache ) ; $ this -> viewPathCache = [ ] ; return $ this ; } | Add a location to scan with the BaseViewFinder . |
24,248 | public function scanLocations ( array $ criteria ) { $ uris = $ this -> locations -> map ( function ( $ location ) use ( $ criteria ) { return $ location -> getURI ( $ criteria ) ; } ) -> filter ( function ( $ uri ) { return false !== $ uri ; } ) ; if ( $ uris -> isEmpty ( ) ) { foreach ( $ criteria as $ criterion ) { if ( file_exists ( $ criterion ) ) { return $ criterion ; } } } return $ uris -> isEmpty ( ) ? false : $ uris -> first ( ) ; } | Scan Locations for an URI that matches the specified criteria . |
24,249 | protected function getFinder ( $ key ) { $ finderClass = $ this -> config -> getKey ( $ key , 'ClassName' ) ; return new $ finderClass ( $ this -> config -> getSubConfig ( $ key ) ) ; } | Get a finder instance . |
24,250 | protected function resolveType ( $ type , string $ uri , Engine $ engine = null ) : View { $ configKey = [ static :: VIEW_FINDER_KEY , 'Views' , $ type ] ; if ( is_string ( $ type ) && $ this -> config -> hasKey ( $ configKey ) ) { $ className = $ this -> config -> getKey ( $ configKey ) ; $ type = new $ className ( $ uri , $ engine , $ this ) ; } if ( is_string ( $ type ) ) { $ type = new $ type ( $ uri , $ engine , $ this ) ; } if ( is_callable ( $ type ) ) { $ type = $ type ( $ uri , $ engine , $ this ) ; } if ( ! $ type instanceof View ) { throw new FailedToInstantiateView ( sprintf ( _ ( 'Could not instantiate view "%s".' ) , serialize ( $ type ) ) ) ; } return $ type ; } | Resolve the view type . |
24,251 | protected function getConfig ( $ config = [ ] ) : ConfigInterface { $ defaults = ConfigFactory :: create ( dirname ( __DIR__ , 2 ) . '/config/defaults.php' , $ config ) ; $ config = $ config ? ConfigFactory :: createFromArray ( array_merge_recursive ( $ defaults -> getArrayCopy ( ) , $ config -> getArrayCopy ( ) ) ) : $ defaults ; return $ config -> getSubConfig ( 'BrightNucleus\View' ) ; } | Get the configuration to use in the ViewBuilder . |
24,252 | public function attachToModel ( Model $ model , $ type = '' , $ locale = null ) : Model { if ( $ model -> assets ( ) -> get ( ) -> contains ( $ this ) ) { throw AssetUploadException :: create ( ) ; } $ model -> assets -> where ( 'pivot.type' , $ type ) -> where ( 'pivot.locale' , $ locale ) ; $ locale = $ locale ?? config ( 'app.locale' ) ; $ model -> assets ( ) -> attach ( $ this , [ 'type' => $ type , 'locale' => $ locale , 'order' => $ this -> order ] ) ; return $ model -> load ( 'assets' ) ; } | Attaches this asset instance to the given model and sets the type and locale to the given values and returns the model with the asset relationship . |
24,253 | public function getImageUrl ( $ type = '' ) : string { if ( $ this -> getMedia ( ) -> isEmpty ( ) ) { return asset ( 'assets/back/img/other.png' ) ; } $ extension = $ this -> getExtensionType ( ) ; if ( $ extension === 'image' ) { return $ this -> getFileUrl ( $ type ) ; } elseif ( $ extension ) { return asset ( 'assets/back/img/' . $ extension . '.png' ) ; } return asset ( 'assets/back/img/other.png' ) ; } | Returns the image url or a fallback specific per filetype . |
24,254 | public static function removeByIds ( $ imageIds ) { if ( is_array ( $ imageIds ) ) { foreach ( $ imageIds as $ id ) { if ( ! $ id ) { continue ; } self :: remove ( $ id ) ; } } else { if ( ! $ imageIds ) { return ; } self :: remove ( $ imageIds ) ; } } | Removes one or more assets by their ids . |
24,255 | public static function remove ( $ id ) { $ asset = self :: find ( $ id ) -> first ( ) ; $ media = $ asset -> media ; foreach ( $ media as $ file ) { if ( ! is_file ( public_path ( $ file -> getUrl ( ) ) ) || ! is_writable ( public_path ( $ file -> getUrl ( ) ) ) ) { return ; } } $ asset -> delete ( ) ; } | Removes one assets by id . It also checks if you have the permissions to remove the file . |
24,256 | public function registerMediaConversions ( Media $ media = null ) { $ conversions = config ( 'assetlibrary.conversions' ) ; foreach ( $ conversions as $ key => $ value ) { $ conversionName = $ key ; $ this -> addMediaConversion ( $ conversionName ) -> width ( $ value [ 'width' ] ) -> height ( $ value [ 'height' ] ) -> keepOriginalImageFormat ( ) -> optimize ( ) ; } if ( config ( 'assetlibrary.allowCropping' ) ) { $ this -> addMediaConversion ( 'cropped' ) -> keepOriginalImageFormat ( ) -> optimize ( ) ; } } | Register the conversions that should be performed . |
24,257 | protected function checkArguments ( array $ args , $ min , $ max , $ methodName ) { $ argc = count ( $ args ) ; if ( $ argc < $ min || $ argc > $ max ) { throw new \ BadMethodCallException ( "Method $methodName is not exist" ) ; } } | Check if args are valid or not . |
24,258 | public function doRegister ( $ data , WaitingListRegistrationForm $ form ) { $ form -> saveInto ( $ registration = WaitingListRegistration :: create ( ) ) ; $ registration -> EventID = $ this -> getController ( ) -> ID ; $ this -> getController ( ) -> WaitingList ( ) -> add ( $ registration ) ; $ this -> getController ( ) -> redirect ( $ this -> getController ( ) -> Link ( '?waitinglist=1' ) ) ; } | Sets the person on the waiting list |
24,259 | public function getInfo ( string $ key = null ) { if ( $ this -> info == null ) { $ resource = $ this -> linker -> getLink ( ) -> getAgent ( ) -> getResource ( ) ; $ resourceType = $ resource -> getType ( ) ; $ serverVersion = $ clientVersion = null ; if ( $ resourceType == Resource :: TYPE_MYSQL_LINK ) { $ object = $ resource -> getObject ( ) ; foreach ( get_class_vars ( get_class ( $ object ) ) as $ var => $ _ ) { $ this -> info [ $ var ] = $ object -> { $ var } ; } $ serverVersion = preg_replace ( '~\s*([^ ]+).*~' , '\1' , $ object -> server_info ) ; $ clientVersion = preg_replace ( '~(?:[a-z]+\s+)?([^ ]+).*~i' , '\1' , $ object -> client_info ) ; } elseif ( $ resourceType == Resource :: TYPE_PGSQL_LINK ) { $ this -> info = pg_version ( $ resource -> getObject ( ) ) ; $ serverVersion = preg_replace ( '~\s*([^ ]+).*~' , '\1' , $ this -> info [ 'server' ] ) ; $ clientVersion = preg_replace ( '~\s*([^ ]+).*~' , '\1' , $ this -> info [ 'client' ] ) ; } $ this -> info [ 'serverVersion' ] = $ serverVersion ; $ this -> info [ 'clientVersion' ] = $ clientVersion ; } return ( $ key == null ) ? $ this -> info : $ this -> info [ $ key ] ?? null ; } | Get info . |
24,260 | protected function updateSize ( ) { $ sizeY = abs ( $ this -> startY ) ; $ sizeX = 0 ; foreach ( $ this -> elements as $ idx => $ element ) { $ sizeY += $ element -> getHeight ( ) + $ this -> margin ; if ( abs ( $ element -> getX ( ) ) + $ element -> getWidth ( ) > $ sizeX ) { $ sizeX = abs ( $ element -> getX ( ) ) + $ element -> getWidth ( ) ; } } $ this -> setSize ( $ sizeX , $ sizeY ) ; } | Update the size of the layout according to all the elements in it . |
24,261 | public function setPosition ( $ x , $ y ) { $ this -> posX = $ x ; $ this -> posy = $ y ; return $ this ; } | Set position . |
24,262 | public function getAccounts ( ) { $ accounts = array ( ) ; $ this -> Account -> byOrganization ( $ this -> AuthenticationManager -> getCurrentUserOrganizationId ( ) ) -> each ( function ( $ Account ) use ( & $ accounts ) { array_push ( $ accounts , array ( 'label' => $ Account -> key . ' ' . $ Account -> name , 'value' => $ Account -> id ) ) ; } ) ; return $ accounts ; } | Get organization accounts |
24,263 | public function getGroupsAccounts ( ) { $ accounts = array ( ) ; $ this -> Account -> byOrganization ( $ this -> AuthenticationManager -> getCurrentUserOrganizationId ( ) ) -> each ( function ( $ Account ) use ( & $ accounts ) { if ( $ Account -> is_group ) { array_push ( $ accounts , array ( 'label' => $ Account -> key . ' ' . $ Account -> name , 'value' => $ Account -> id ) ) ; } } ) ; return $ accounts ; } | Get group organization accounts |
24,264 | public function getAccountsTypes ( ) { $ accountTypes = array ( ) ; $ this -> AccountType -> byOrganization ( $ this -> AuthenticationManager -> getCurrentUserOrganizationId ( ) ) -> each ( function ( $ AccountType ) use ( & $ accountTypes ) { array_push ( $ accountTypes , array ( 'label' => $ AccountType -> name , 'value' => $ AccountType -> id ) ) ; } ) ; return $ accountTypes ; } | Get organization accounts types |
24,265 | public function accept ( VisitorInterface $ visitor ) : void { $ visitor -> visitBefore ( $ this ) ; foreach ( $ this -> getChildren ( ) as $ node ) { $ node -> accept ( $ visitor ) ; } $ visitor -> visitAfter ( $ this ) ; } | Accept a visitor |
24,266 | public function getChild ( string $ name ) : Node { foreach ( $ this -> children as $ node ) { if ( strcasecmp ( $ node -> getName ( ) , $ name ) == 0 ) { return $ node ; } } return new NullNode ; } | Get child node |
24,267 | public function hasChild ( string $ name ) : bool { foreach ( $ this -> children as $ node ) { if ( strcasecmp ( $ node -> getName ( ) , $ name ) == 0 ) { return true ; } } return false ; } | Check if child exists |
24,268 | public function getChildren ( string $ name = '' ) : array { $ nodes = [ ] ; foreach ( $ this -> children as $ node ) { if ( ! $ name || strcasecmp ( $ node -> getName ( ) , $ name ) == 0 ) { $ nodes [ ] = $ node ; } } return $ nodes ; } | Get registered child nodes |
24,269 | public function getCountryAccountsChartsTypes ( ) { $ accountsChartsTypes = array ( ) ; $ this -> AccountChartType -> accountsChartsTypesByCountry ( $ this -> AuthenticationManager -> getCurrentUserOrganizationCountry ( ) ) -> each ( function ( $ AccountChartType ) use ( & $ accountsChartsTypes ) { $ name = $ this -> Lang -> has ( $ AccountChartType -> lang_key ) ? $ this -> Lang -> get ( $ AccountChartType -> lang_key ) : $ AccountChartType -> name ; array_push ( $ accountsChartsTypes , array ( 'id' => $ AccountChartType -> id , 'name' => $ name , 'url' => $ AccountChartType -> url ) ) ; } ) ; return $ accountsChartsTypes ; } | Get country accounts chart types . |
24,270 | public function getSystemCurrencies ( ) { $ currencies = array ( ) ; $ this -> Currency -> all ( ) -> each ( function ( $ Currency ) use ( & $ currencies ) { array_push ( $ currencies , array ( 'label' => $ Currency -> name . ' (' . $ Currency -> symbol . ')' , 'value' => $ Currency -> id ) ) ; } ) ; return $ currencies ; } | Get system currencies |
24,271 | public function getSettingJournals ( ) { return $ this -> JournalManager -> getJournalsByApp ( array ( 'appId' => 'acct-initial-acounting-setup' , 'page' => 1 , 'journalizedId' => $ this -> Setting -> byOrganization ( $ this -> AuthenticationManager -> getCurrentUserOrganization ( 'id' ) ) -> first ( ) -> id , 'filter' => null , 'userId' => null , 'onlyActions' => false ) , true ) ; } | Get Setting Journals |
24,272 | private static function initModelProperties ( ) { $ currentModel = static :: class ; if ( isset ( self :: $ modelProperties [ $ currentModel ] ) ) { return ; } $ properties = [ 'connection' => ConnectionFactory :: build ( static :: $ connection ) , 'dateFields' => static :: $ dates ? : [ ] , 'fields' => static :: $ fields ? : [ ] , 'primaryKeys' => ( array ) static :: $ primaryKey , 'table' => static :: $ table , 'timestamps' => ( bool ) static :: $ timestamps , ] ; if ( $ properties [ 'timestamps' ] ) { $ properties [ 'fields' ] [ ] = 'created_at' ; $ properties [ 'fields' ] [ ] = 'updated_at' ; $ properties [ 'dateFields' ] [ ] = 'created_at' ; $ properties [ 'dateFields' ] [ ] = 'updated_at' ; } self :: $ modelProperties [ $ currentModel ] = $ properties ; } | Initialize static properties . |
24,273 | public function exists ( ) : bool { $ query = static :: createQuery ( ) ; $ pks = static :: getPrimaryKeys ( ) ; $ pkValues = $ this -> getPrimaryKeyValues ( ) ; if ( count ( $ pks ) != count ( $ pkValues ) ) { return false ; } $ filterFunction = function ( WhereClause $ whereClause ) use ( & $ pkValues , $ query ) { foreach ( $ pkValues as $ field => $ value ) { $ whereClause -> and ( $ field , '=' , '?' ) ; $ query -> bind ( $ value ) ; } } ; $ query -> where ( $ filterFunction ) -> count ( '*' ) ; $ row = $ query -> execute ( ) -> fetch ( ) ; return $ row [ 'all_count' ] > 0 ; } | Checks if the current Model exists in the storage . |
24,274 | public function insert ( ) : Result { $ result = self :: getConnection ( ) -> insert ( $ this ) ; if ( $ result -> count ( ) ) { $ pks = static :: getPrimaryKeys ( ) ; if ( count ( $ pks ) == 1 ) { $ this -> data [ $ pks [ 0 ] ] = static :: getConnection ( ) -> lastId ( ) ; } } return $ result ; } | Insert data in the database . |
24,275 | public static function sanitize ( $ input , $ skip = [ ] , $ textOnly = false , $ removeFunctions = true ) { if ( ! is_array ( $ input ) ) { if ( true === $ removeFunctions ) { $ input = preg_replace ( '/[a-zA-Z][a-zA-Z0-9_]+(\()+([a-zA-Z0-9_\-$,\s\"]?)+(\))(\;?)/' , '' , $ input ) ; } $ invalidValues = [ 'exec' , '\\' , '&' , '&#' , '0x' , '<script>' , '</script>' , '">' , "'>" ] ; $ allowableTags = '<p><br><img><label><input><textarea><div><span><a><strong><i><u>' ; $ input = str_replace ( $ invalidValues , '' , $ input ) ; $ input = preg_replace ( '/%[a-zA-Z0-9]{2}/' , '' , $ input ) ; $ input = strip_tags ( trim ( $ input ) , $ allowableTags ) ; if ( $ textOnly ) { $ input = str_replace ( [ '<' , '>' , "'" , '"' ] , '' , $ input ) ; } return $ input ; } else { $ array = [ ] ; foreach ( $ input as $ key => $ item ) { if ( in_array ( $ key , $ skip ) ) { $ array [ $ key ] = $ item ; } else { if ( ! is_array ( $ item ) ) { $ array [ $ key ] = self :: sanitize ( $ item , $ skip , $ textOnly , $ removeFunctions ) ; } else { $ array = array_merge ( $ array , [ $ key => self :: sanitize ( $ item , $ skip , $ textOnly , $ removeFunctions ) ] ) ; } } } return $ array ; } } | Sanitizes or recursively sanitizes a value |
24,276 | public function setDataSource ( $ listLeft , $ listRight = null ) { $ this -> _listLeftDataSource = $ listLeft ; $ this -> _listRightDataSource = $ listRight ; } | Config DataSource to Dual List |
24,277 | public function createDefaultButtons ( ) { $ this -> setButtonOneLeft ( new DualListButton ( "<--" , DualListButtonType :: Button ) ) ; $ this -> setButtonAllLeft ( new DualListButton ( "<<<" , DualListButtonType :: Button ) ) ; $ this -> setButtonOneRight ( new DualListButton ( "-->" , DualListButtonType :: Button ) ) ; $ this -> setButtonAllRight ( new DualListButton ( ">>>" , DualListButtonType :: Button ) ) ; } | Create all default buttons . |
24,278 | public static function Parse ( $ context , $ duallistaname ) { $ val = $ context -> get ( $ duallistaname ) ; if ( $ val != "" ) { return explode ( "," , $ val ) ; } else { return array ( ) ; } } | Parse RESULTSS from DualList object |
24,279 | private function buildListItens ( $ list , $ arr ) { foreach ( $ arr as $ key => $ value ) { $ item = XmlUtil :: CreateChild ( $ list , "item" , "" ) ; XmlUtil :: AddAttribute ( $ item , "id" , $ key ) ; XmlUtil :: AddAttribute ( $ item , "text" , $ value ) ; } } | Build Dual lista data |
24,280 | private function makeButton ( $ button , $ name , $ duallist , $ from , $ to , $ all ) { $ newbutton = XmlUtil :: CreateChild ( $ duallist , "button" , "" ) ; XmlUtil :: AddAttribute ( $ newbutton , "name" , $ name ) ; if ( $ button -> type == DualListButtonType :: Image ) { XmlUtil :: AddAttribute ( $ newbutton , "type" , "image" ) ; XmlUtil :: AddAttribute ( $ newbutton , "src" , $ button -> href ) ; XmlUtil :: AddAttribute ( $ newbutton , "value" , $ button -> text ) ; } else { XmlUtil :: AddAttribute ( $ newbutton , "type" , "button" ) ; XmlUtil :: AddAttribute ( $ newbutton , "value" , $ button -> text ) ; } XmlUtil :: AddAttribute ( $ newbutton , "from" , $ from ) ; XmlUtil :: AddAttribute ( $ newbutton , "to" , $ to ) ; XmlUtil :: AddAttribute ( $ newbutton , "all" , $ all ) ; } | Make a buttom |
24,281 | function delete ( $ key ) { $ this -> data [ $ key ] = null ; unset ( $ this -> data [ $ key ] ) ; return $ this ; } | Removes an item from the collection by its key . |
24,282 | function chunk ( int $ numitems , bool $ preserve_keys = false ) { return ( new self ( \ array_chunk ( $ this -> data , $ numitems , $ preserve_keys ) ) ) ; } | Breaks the collection into multiple smaller chunks of a given size . Returns a new Collection . |
24,283 | function diff ( $ arr ) { if ( $ arr instanceof self ) { $ arr = $ arr -> all ( ) ; } return ( new self ( \ array_diff ( $ this -> data , $ arr ) ) ) ; } | Compares the collection against another collection or a plain PHP array based on its value . Returns a new Collection . |
24,284 | function diffKeys ( $ arr ) { if ( $ arr instanceof self ) { $ arr = $ arr -> all ( ) ; } return ( new self ( \ array_diff_key ( $ this -> data , $ arr ) ) ) ; } | Compares the collection against another collection or a plain PHP array based on its key . Returns a new Collection . |
24,285 | function each ( callable $ closure ) { foreach ( $ this -> data as $ key => $ val ) { $ feed = $ closure ( $ val , $ key ) ; if ( $ feed === false ) { break ; } } return $ this ; } | Iterates over the items in the collection and passes each item to a given callback . Returning false in the callback will stop the processing . |
24,286 | function filter ( callable $ closure ) { $ new = array ( ) ; foreach ( $ this -> data as $ key => $ val ) { $ feed = ( bool ) $ closure ( $ val , $ key ) ; if ( $ feed ) { $ new [ $ key ] = $ val ; } } return ( new self ( $ new ) ) ; } | Filters the collection by a given callback keeping only those items that pass a given truth test . Returns a new Collection . |
24,287 | function first ( callable $ closure = null ) { if ( $ closure === null ) { if ( empty ( $ this -> data ) ) { return null ; } $ keys = \ array_keys ( $ this -> data ) ; return ( $ this -> data [ $ keys [ 0 ] ] ?? null ) ; } foreach ( $ this -> data as $ key => $ val ) { $ feed = ( bool ) $ closure ( $ val , $ key ) ; if ( $ feed ) { return $ val ; } } return null ; } | Returns the first element in the collection that passes a given truth test . |
24,288 | function flatten ( int $ depth = 0 ) { $ data = $ this -> flattenDo ( $ this -> data , $ depth ) ; return ( new self ( $ data ) ) ; } | Flattens a multi - dimensional collection into a single dimension . Returns a new Collection . |
24,289 | function groupBy ( $ column ) { if ( $ column === null || $ column === '' ) { return $ this ; } $ new = array ( ) ; foreach ( $ this -> data as $ key => $ val ) { if ( \ is_callable ( $ column ) ) { $ key = $ column ( $ val , $ key ) ; } elseif ( \ is_array ( $ val ) ) { $ key = $ val [ $ column ] ; } elseif ( \ is_object ( $ val ) ) { $ key = $ val -> $ column ; } $ new [ $ key ] [ ] = $ val ; } return ( new self ( $ new ) ) ; } | Groups the collection s items by a given key . Returns a new Collection . |
24,290 | function implode ( $ col , string $ glue = ', ' ) { $ data = '' ; foreach ( $ this -> data as $ key => $ val ) { if ( \ is_array ( $ val ) ) { if ( ! isset ( $ val [ $ col ] ) ) { throw new \ BadMethodCallException ( 'Specified key "' . $ col . '" does not exist on array' ) ; } $ data .= $ glue . $ val [ $ col ] ; } elseif ( \ is_object ( $ val ) ) { if ( ! isset ( $ val -> $ col ) ) { throw new \ BadMethodCallException ( 'Specified key "' . $ col . '" does not exist on object' ) ; } $ data .= $ glue . $ val -> $ col ; } else { $ data .= $ glue . $ val ; } } return \ substr ( $ data , \ strlen ( $ glue ) ) ; } | Joins the items in a collection . Its arguments depend on the type of items in the collection . If the collection contains arrays or objects you should pass the key of the attributes you wish to join and the glue string you wish to place between the values . |
24,291 | function indexOf ( $ value ) { $ i = 0 ; foreach ( $ this -> data as $ val ) { if ( $ val === $ value ) { return $ i ; } $ i ++ ; } return null ; } | Returns the position of the given value in the collection . Returns null if the given value couldn t be found . |
24,292 | function intersect ( $ arr ) { if ( $ arr instanceof self ) { $ arr = $ arr -> all ( ) ; } return ( new self ( \ array_intersect ( $ this -> data , $ arr ) ) ) ; } | Removes any values that are not present in the given array or collection . Returns a new Collection . |
24,293 | function last ( callable $ closure = null ) { if ( $ closure === null ) { if ( empty ( $ this -> data ) ) { return null ; } $ keys = \ array_keys ( $ this -> data ) ; return $ this -> data [ $ keys [ ( \ count ( $ keys ) - 1 ) ] ] ; } $ data = null ; foreach ( $ this -> data as $ key => $ val ) { $ feed = $ closure ( $ val , $ key ) ; if ( $ feed ) { $ data = $ val ; } } return $ data ; } | Returns the last element in the collection that passes a given truth test . |
24,294 | function map ( callable $ closure ) { $ keys = \ array_keys ( $ this -> data ) ; $ items = \ array_map ( $ closure , $ this -> data , $ keys ) ; return ( new self ( \ array_combine ( $ keys , $ items ) ) ) ; } | Iterates through the collection and passes each value to the given callback . The callback is free to modify the item and return it thus forming a new collection of modified items . |
24,295 | function max ( $ key = null ) { if ( $ key !== null ) { $ data = \ array_column ( $ this -> data , $ key ) ; } else { $ data = $ this -> data ; } return \ max ( $ data ) ; } | Return the maximum value of a given key . |
24,296 | function min ( $ key = null ) { if ( $ key !== null ) { $ data = \ array_column ( $ this -> data , $ key ) ; } else { $ data = $ this -> data ; } return \ min ( $ data ) ; } | Return the minimum value of a given key . |
24,297 | function merge ( \ CharlotteDunois \ Collect \ Collection $ collection ) { return ( new self ( \ array_merge ( $ this -> data , $ collection -> all ( ) ) ) ) ; } | Merges the given collection into this collection resulting in a new collection . Any string key in the given collection matching a string key in this collection will overwrite the value in this collection . |
24,298 | function nth ( int $ nth , int $ offset = 0 ) { if ( $ nth <= 0 ) { throw new \ InvalidArgumentException ( 'nth must be a non-zero positive integer' ) ; } $ new = array ( ) ; $ size = \ count ( $ this -> data ) ; for ( $ i = $ offset ; $ i < $ size ; $ i += $ nth ) { $ new [ ] = $ this -> data [ $ i ] ; } return ( new self ( $ new ) ) ; } | Creates a new collection consisting of every n - th element . |
24,299 | function only ( array $ keys ) { $ new = array ( ) ; foreach ( $ this -> data as $ key => $ val ) { if ( \ in_array ( $ key , $ keys , true ) ) { $ new [ $ key ] = $ val ; } } return ( new self ( $ new ) ) ; } | Returns the items in the collection with the specified keys . Returns a new Collection . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.