idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
3,800
|
public function orderConfirmationAction ( Request $ request , $ id ) { $ locale = $ this -> getLocale ( $ request ) ; $ this -> get ( 'translator' ) -> setLocale ( $ locale ) ; try { $ orderApiEntity = $ this -> getOrderManager ( ) -> findByIdAndLocale ( $ id , $ locale ) ; $ order = $ orderApiEntity -> getEntity ( ) ; } catch ( OrderNotFoundException $ exc ) { throw new OrderNotFoundException ( $ id ) ; } $ pdf = $ this -> getPdfManager ( ) -> createOrderConfirmation ( $ orderApiEntity ) ; $ pdfName = $ this -> getPdfManager ( ) -> getPdfName ( $ order ) ; return new Response ( $ pdf , 200 , array ( 'Content-Type' => 'application/pdf' , 'Content-Disposition' => 'attachment; filename="' . $ pdfName . '"' ) ) ; }
|
Finds a order object by a given id from the url and returns a rendered pdf in a download window
|
3,801
|
public function open ( ) : bool { $ path = $ this -> getOptionOrDefault ( 'path' ) ; if ( is_resource ( $ path ) ) { $ this -> resource = $ path ; return true ; } $ context = $ this -> getOptionOrDefault ( 'context' ) ; if ( is_resource ( $ context ) ) { $ this -> resource = @ fopen ( $ path , 'ab' , false , $ context ) ; } else { $ this -> resource = @ fopen ( $ path , 'ab' ) ; } return is_resource ( $ this -> resource ) ; }
|
Open a log destination .
|
3,802
|
public static function factory ( array $ middlewares = array ( ) ) { $ runner = null ; foreach ( $ middlewares as $ middleware ) { $ runner = $ runner ? $ runner -> add ( $ middleware ) : new static ( $ middleware ) ; } return $ runner ; }
|
Creates a runner based on an array of middleware
|
3,803
|
public static function collapseSerialized ( EloquentCollection $ collection ) { return $ collection -> map ( function ( SerializedModel $ menu_item ) { return $ menu_item -> serialized ( ) ; } ) -> collapse ( ) ; }
|
Collapse a keyed Eloquent Collection .
|
3,804
|
public function addUser ( $ user ) { if ( ! $ this -> hasUser ( $ user ) ) { return RoleUser :: create ( [ 'role_id' => $ this -> id , 'user_id' => $ user -> id ] ) ; } return false ; }
|
Adds a user into the role .
|
3,805
|
public function addPermission ( $ permission ) { if ( ! $ this -> hasPermission ( $ permission ) ) { return PermissionRole :: create ( [ 'role_id' => $ this -> id , 'permission_id' => $ permission -> id ] ) ; } return false ; }
|
Adds a permission into the role .
|
3,806
|
public function deleteUser ( $ user ) { if ( $ this -> hasUser ( $ user ) ) { return RoleUser :: where ( [ 'role_id' => $ this -> id , 'user_id' => $ user -> id ] ) -> first ( ) -> delete ( ) ; } return false ; }
|
Deletes the specified role user .
|
3,807
|
public function deletePermission ( $ permission ) { if ( $ this -> hasPermission ( $ permission ) ) { return PermissionRole :: where ( [ 'role_id' => $ this -> id , 'permission_id' => $ permission -> id ] ) -> first ( ) -> delete ( ) ; } return false ; }
|
Deletes the specified role permission .
|
3,808
|
public function process ( StorableInterface $ object ) { if ( is_array ( $ this -> backends ) && count ( $ this -> backends ) > 0 ) { $ results = [ ] ; $ identifiers = $ object -> getStorableBackendIdentifiers ( ) ; foreach ( $ this -> backends as $ identifier => $ backend ) { if ( in_array ( $ identifier , $ identifiers ) ) { $ results [ $ identifier ] = $ backend -> write ( $ object ) ; } } return $ results ; } else { throw new StorageProcessingException ( sprintf ( "Tried to process an storable object '%s' with no backends" , $ object -> getStorableIdentifier ( ) ) ) ; } }
|
Runs through each storage backend and processes the Storable object
|
3,809
|
protected function toUtf8 ( $ string ) { if ( $ this -> getEncoding ( ) === 'utf-8' ) { $ result = $ string ; } else { $ result = $ this -> convertEncoding ( $ string , 'UTF-8' , $ this -> getEncoding ( ) ) ; } return $ result ; }
|
Convert string to UTF - 8
|
3,810
|
private function addParameterFallback ( $ name , $ fallbackData = null ) { if ( ! isset ( $ this -> parameters [ $ name ] ) && ! empty ( $ fallbackData ) ) { $ this -> parameters [ $ name ] = $ fallbackData ; } }
|
This will add fallback data to the parameters if the key is not set .
|
3,811
|
public function inject ( ContainerBuilder $ container ) { foreach ( $ this -> schema as $ parameter ) { $ value = $ parameter [ 'default' ] ; if ( $ this -> parametersStorage -> has ( $ parameter [ 'key' ] ) ) { $ value = $ this -> parametersStorage -> get ( $ parameter [ 'key' ] ) ; } $ container -> setParameter ( $ this -> getParametersName ( $ parameter [ 'key' ] ) , $ this -> protectParameterValue ( $ value ) ) ; } }
|
Inject dynamic parameters in the container builder
|
3,812
|
public function rebuild ( Kernel $ kernel ) { $ kernelReflectionClass = new \ ReflectionClass ( $ kernel ) ; $ buildContainerReflectionMethod = $ kernelReflectionClass -> getMethod ( 'buildContainer' ) ; $ buildContainerReflectionMethod -> setAccessible ( true ) ; $ dumpContainerReflectionMethod = $ kernelReflectionClass -> getMethod ( 'dumpContainer' ) ; $ dumpContainerReflectionMethod -> setAccessible ( true ) ; $ getContainerClassReflectionMethod = $ kernelReflectionClass -> getMethod ( 'getContainerClass' ) ; $ getContainerClassReflectionMethod -> setAccessible ( true ) ; $ getContainerBaseClassReflectionMethod = $ kernelReflectionClass -> getMethod ( 'getContainerBaseClass' ) ; $ getContainerBaseClassReflectionMethod -> setAccessible ( true ) ; $ newContainer = $ buildContainerReflectionMethod -> invoke ( $ kernel ) ; $ this -> inject ( $ newContainer ) ; $ newContainer -> compile ( ) ; $ class = $ getContainerClassReflectionMethod -> invoke ( $ kernel ) ; $ cache = new ConfigCache ( $ kernel -> getCacheDir ( ) . '/' . $ class . '.php' , $ kernel -> isDebug ( ) ) ; $ dumpContainerReflectionMethod -> invoke ( $ kernel , $ cache , $ newContainer , $ class , $ getContainerBaseClassReflectionMethod -> invoke ( $ kernel ) ) ; }
|
Rebuild the container and dump it to the cache to apply change on redis stored parameters
|
3,813
|
public function filterByCreateDate ( $ createDate = null , $ comparison = null ) { if ( is_array ( $ createDate ) ) { $ useMinMax = false ; if ( isset ( $ createDate [ 'min' ] ) ) { $ this -> addUsingAlias ( RoleTableMap :: COL_CREATE_DATE , $ createDate [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ createDate [ 'max' ] ) ) { $ this -> addUsingAlias ( RoleTableMap :: COL_CREATE_DATE , $ createDate [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( RoleTableMap :: COL_CREATE_DATE , $ createDate , $ comparison ) ; }
|
Filter the query on the create_date column
|
3,814
|
public function filterByUpdateDate ( $ updateDate = null , $ comparison = null ) { if ( is_array ( $ updateDate ) ) { $ useMinMax = false ; if ( isset ( $ updateDate [ 'min' ] ) ) { $ this -> addUsingAlias ( RoleTableMap :: COL_UPDATE_DATE , $ updateDate [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ updateDate [ 'max' ] ) ) { $ this -> addUsingAlias ( RoleTableMap :: COL_UPDATE_DATE , $ updateDate [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( RoleTableMap :: COL_UPDATE_DATE , $ updateDate , $ comparison ) ; }
|
Filter the query on the update_date column
|
3,815
|
public function filterByUserRole ( $ userRole , $ comparison = null ) { if ( $ userRole instanceof \ Alchemy \ Component \ Cerberus \ Model \ UserRole ) { return $ this -> addUsingAlias ( RoleTableMap :: COL_ID , $ userRole -> getRoleId ( ) , $ comparison ) ; } elseif ( $ userRole instanceof ObjectCollection ) { return $ this -> useUserRoleQuery ( ) -> filterByPrimaryKeys ( $ userRole -> getPrimaryKeys ( ) ) -> endUse ( ) ; } else { throw new PropelException ( 'filterByUserRole() only accepts arguments of type \Alchemy\Component\Cerberus\Model\UserRole or Collection' ) ; } }
|
Filter the query by a related \ Alchemy \ Component \ Cerberus \ Model \ UserRole object
|
3,816
|
public function useUserRoleQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinUserRole ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'UserRole' , '\Alchemy\Component\Cerberus\Model\UserRoleQuery' ) ; }
|
Use the UserRole relation UserRole object
|
3,817
|
public function useRolePermissionQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinRolePermission ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'RolePermission' , '\Alchemy\Component\Cerberus\Model\RolePermissionQuery' ) ; }
|
Use the RolePermission relation RolePermission object
|
3,818
|
public function filterByUser ( $ user , $ comparison = Criteria :: EQUAL ) { return $ this -> useUserRoleQuery ( ) -> filterByUser ( $ user , $ comparison ) -> endUse ( ) ; }
|
Filter the query by a related User object using the user_role table as cross reference
|
3,819
|
public function filterByPermission ( $ permission , $ comparison = Criteria :: EQUAL ) { return $ this -> useRolePermissionQuery ( ) -> filterByPermission ( $ permission , $ comparison ) -> endUse ( ) ; }
|
Filter the query by a related Permission object using the role_permission table as cross reference
|
3,820
|
public function doDeleteAll ( ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( RoleTableMap :: DATABASE_NAME ) ; } return $ con -> transaction ( function ( ) use ( $ con ) { $ affectedRows = 0 ; $ affectedRows += parent :: doDeleteAll ( $ con ) ; RoleTableMap :: clearInstancePool ( ) ; RoleTableMap :: clearRelatedInstancePool ( ) ; return $ affectedRows ; } ) ; }
|
Deletes all rows from the role table .
|
3,821
|
public function delete ( ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( RoleTableMap :: DATABASE_NAME ) ; } $ criteria = $ this ; $ criteria -> setDbName ( RoleTableMap :: DATABASE_NAME ) ; return $ con -> transaction ( function ( ) use ( $ con , $ criteria ) { $ affectedRows = 0 ; RoleTableMap :: removeInstanceFromPool ( $ criteria ) ; $ affectedRows += ModelCriteria :: delete ( $ con ) ; RoleTableMap :: clearRelatedInstancePool ( ) ; return $ affectedRows ; } ) ; }
|
Performs a DELETE on the database based on the current ModelCriteria
|
3,822
|
public function start ( ) { $ data = $ this -> handler -> read ( $ this -> get_id ( ) ) ; if ( false !== $ data && ! is_null ( $ data ) && is_array ( $ data ) ) { $ this -> attributes = $ data ; } $ this -> started = true ; }
|
Start the session reading the data from a handler .
|
3,823
|
public function keep ( $ keys = null ) { $ keys = is_array ( $ keys ) ? $ keys : func_get_args ( ) ; $ this -> merge_new_flashes ( $ keys ) ; $ this -> remove_old_flash_data ( $ keys ) ; }
|
Reflash a subset of the current flash data .
|
3,824
|
public function regenerate ( $ destroy = false ) { if ( $ destroy ) { $ this -> handler -> destroy ( $ this -> get_id ( ) ) ; } $ this -> set_id ( $ this -> generate_session_id ( ) ) ; return true ; }
|
Generate a new session identifier .
|
3,825
|
public function set_id ( $ id ) { $ this -> id = $ this -> is_valid_id ( $ id ) ? $ id : $ this -> generate_session_id ( ) ; }
|
Set the session ID .
|
3,826
|
protected function generate_session_id ( ) { $ length = 40 ; require_once ABSPATH . 'wp-includes/class-phpass.php' ; $ bytes = ( new \ PasswordHash ( 8 , false ) ) -> get_random_bytes ( $ length * 2 ) ; return substr ( str_replace ( [ '/' , '+' , '=' ] , '' , base64_encode ( $ bytes ) ) , 0 , $ length ) ; }
|
Get a new random session ID .
|
3,827
|
public function getCurrentRouteMatch ( ) { if ( empty ( $ this -> currentRouteMatch ) ) { $ this -> currentRouteMatch = \ Drupal :: service ( 'current_route_match' ) ; } return $ this -> currentRouteMatch ; }
|
Gets the current route match .
|
3,828
|
protected function setCssContent ( $ cssContent ) { if ( is_string ( $ cssContent ) ) { $ this -> content = $ cssContent ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ cssContent ) . "' for argument 'cssContent' given." ) ; } return $ this ; }
|
Sets the CSS source content .
|
3,829
|
protected function migrate ( ) { if ( ! $ this -> container [ 'migrator' ] -> repositoryExists ( ) ) { throw new Exception ( 'Migration table not found.' ) ; } $ this -> container [ 'migrator' ] -> run ( $ this -> getAttribute ( 'path' ) . '/database/migrations' ) ; }
|
Execute module migrations .
|
3,830
|
protected function rollback ( ) { if ( ! $ this -> container [ 'migrator' ] -> repositoryExists ( ) ) { throw new Exception ( 'Migration table not found.' ) ; } $ this -> container [ 'migrator' ] -> rollback ( $ this -> getAttribute ( 'path' ) . '/database/migrations' ) ; }
|
Rollback module migrations .
|
3,831
|
protected function seed ( ) { $ seederFilePath = $ this -> getAttribute ( 'path' ) . '/database/seeds/DatabaseSeeder.php' ; if ( $ this -> container [ 'files' ] -> exists ( $ seederFilePath ) ) { require_once $ seederFilePath ; $ namespace = $ this -> getAttribute ( 'namespace' ) . 'Database\\Seeds\\DatabaseSeeder' ; $ class = '\\' . ltrim ( $ namespace , '\\' ) ; $ seeder = new $ class ( ) ; $ seeder -> run ( ) ; } }
|
Seed the database with module seeders .
|
3,832
|
public function getOriginalHeader ( $ name ) { return array_key_exists ( $ name , $ this -> _request ) ? $ this -> _request [ $ name ] : null ; }
|
Get the original HTTP header value from the request
|
3,833
|
protected function primeCommandArray ( ) { if ( empty ( $ this -> layoutName ) ) { throw new LayoutNameIsMissingException ( 'You must specify a layout name.' ) ; } $ this -> commandArray [ '-db' ] = $ this -> adapter -> getHostConnection ( ) -> getDbName ( ) ; $ this -> commandArray [ '-lay' ] = $ this -> layoutName ; }
|
Adds the default url parameters needed for any request .
|
3,834
|
protected function addToCommandArray ( $ values ) { foreach ( $ values as $ key => $ value ) { $ this -> commandArray [ $ key ] = $ value ; } }
|
Adds additional Url parameters to the request .
|
3,835
|
public function executeCommand ( ) { $ this -> adapter -> setCommandArray ( $ this -> commandArray ) ; $ result = $ this -> adapter -> execute ( ) ; $ commandArrayUsed = $ this -> adapter -> getCommandArray ( ) ; $ this -> clearCommandArray ( ) ; $ this -> checkResultForError ( $ result , $ commandArrayUsed ) ; return $ result ; }
|
Performs the steps necessary to execute a SimpleFM query .
|
3,836
|
protected function checkResultForError ( $ result , $ commandArrayUsed ) { if ( empty ( $ result ) ) { throw new NoResultReturnedException ( 'The SimpleFM request did not return a result.' ) ; } if ( $ result -> getErrorCode ( ) == 401 ) { throw new RecordsNotFoundException ( $ result -> getErrorMessage ( ) , $ result -> getErrorCode ( ) , $ result ) ; } if ( $ result -> getErrorCode ( ) !== 0 ) { $ message = $ result -> getErrorMessage ( ) . ". Command used: " . json_encode ( $ commandArrayUsed ) ; throw new GeneralException ( $ message , $ result -> getErrorCode ( ) , $ result ) ; } }
|
Parses the SimpleFM result and determines if a FileMaker error was thrown .
|
3,837
|
public function persist ( ProfileInterface $ profile ) { foreach ( $ this -> persistenceHandlers as $ persistenceHandler ) { $ persistenceHandler -> persist ( $ profile ) ; } return $ this ; }
|
Persists data to the persistence handlers
|
3,838
|
public function removeEval ( $ key ) { if ( array_key_exists ( $ key , $ this -> eval ) ) { unset ( $ this -> eval [ $ key ] ) ; return true ; } return false ; }
|
Remove an entry vom the eval array Returns true if entry was removed and false if key was not found
|
3,839
|
public function modifyEval ( $ key , $ value ) { if ( array_key_exists ( $ key , $ this -> eval ) ) { $ this -> eval [ $ key ] = $ value ; } }
|
Set a new value to an existing eval entry
|
3,840
|
public function getEval ( $ key ) { if ( array_key_exists ( $ key , $ this -> eval ) ) { return $ this -> eval [ $ key ] ; } return false ; }
|
Get an entry from the eval array Returns the entry or false if key not found
|
3,841
|
public static function replaceStringsAndComments ( $ text ) { if ( is_string ( $ text ) ) { if ( strpos ( $ text , "'" ) !== false || strpos ( $ text , '"' ) !== false ) { $ replaceStringCallback = function ( $ matches ) { return self :: addStringReplacement ( $ matches [ 1 ] . $ matches [ 2 ] . $ matches [ 1 ] ) ; } ; $ text = preg_replace ( '/\r/' , '' , $ text ) ; $ text = preg_replace ( '/\\\\\n/' , '_STRING_CSSLINEBREAK_' , $ text ) ; $ text = preg_replace ( '/\\\\"/' , '_STRING_ESCAPEDDOUBLEQUOTE_' , $ text ) ; $ text = preg_replace ( '/\\\\\'/' , '_STRING_ESCAPEDSINGLEQUOTE_' , $ text ) ; $ text = preg_replace_callback ( '/("|\')(.*?)\g{1}/' , $ replaceStringCallback , $ text ) ; } if ( strpos ( $ text , "data:" ) !== false ) { $ replaceDataUriCallback = function ( $ matches ) { return self :: addStringReplacement ( $ matches [ 1 ] ) ; } ; $ text = preg_replace_callback ( '/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' . '(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/' , $ replaceDataUriCallback , $ text ) ; } if ( strpos ( $ text , "*" ) !== false ) { $ replaceCommentCallback = function ( $ matches ) { return self :: addCommentReplacement ( $ matches [ 1 ] ) ; } ; $ text = preg_replace_callback ( '/(\/\*.*?\*\/)/' , $ replaceCommentCallback , $ text ) ; } return $ text ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ text ) . "' for argument 'text' given." ) ; } }
|
Replaces all CSS strings and comments in the given text .
|
3,842
|
public static function replaceStringPlaceholders ( $ text , $ deletePlaceholders = false ) { if ( is_string ( $ text ) ) { if ( strpos ( $ text , "_" ) !== false ) { $ replaceStringPlaceholders = function ( $ matches ) use ( $ deletePlaceholders ) { $ result = "" ; if ( isset ( self :: $ replacements [ $ matches [ 1 ] ] ) ) { $ result = self :: $ replacements [ $ matches [ 1 ] ] ; $ result = str_replace ( [ '_STRING_CSSLINEBREAK_' , '_STRING_ESCAPEDDOUBLEQUOTE_' , '_STRING_ESCAPEDSINGLEQUOTE_' ] , [ "\\\n" , '\\"' , "\\'" ] , $ result ) ; if ( $ deletePlaceholders === true ) { unset ( self :: $ replacements [ $ matches [ 1 ] ] ) ; } } return $ result ; } ; $ text = preg_replace_callback ( '/(?:_STRING_([a-f0-9]{32})_)/' , $ replaceStringPlaceholders , $ text ) ; } return $ text ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ text ) . "' for argument 'text' given." ) ; } }
|
Replaces the string place holders wih the saved strings in a given text .
|
3,843
|
public static function removeCommentPlaceholders ( $ text , $ deletePlaceholders = false ) { if ( is_string ( $ text ) ) { if ( strpos ( $ text , "_" ) !== false ) { $ removeStringPlaceholders = function ( $ matches ) use ( $ deletePlaceholders ) { if ( $ deletePlaceholders === true ) { if ( isset ( self :: $ replacements [ $ matches [ 1 ] ] ) ) { unset ( self :: $ replacements [ $ matches [ 1 ] ] ) ; } } return "" ; } ; $ text = preg_replace_callback ( '/(?:_COMMENT_([a-f0-9]{32})_)/' , $ removeStringPlaceholders , $ text ) ; } return $ text ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ text ) . "' for argument 'text' given." ) ; } }
|
Removes the comment place holders from a given text .
|
3,844
|
protected static function addReplacement ( $ string , $ prefix ) { if ( is_string ( $ string ) ) { if ( is_string ( $ prefix ) ) { $ hash = md5 ( self :: $ counter ) ; $ placeholder = "_" . $ prefix . "_" . $ hash . "_" ; self :: $ replacements [ $ hash ] = $ string ; self :: $ counter ++ ; return $ placeholder ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ prefix ) . "' for argument 'prefix' given." ) ; } } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ string ) . "' for argument 'string' given." ) ; } }
|
Adds a replacement to the internal list .
|
3,845
|
final private function getRefClass ( ) { if ( $ this -> refClass === null ) { $ this -> refClass = new \ ReflectionClass ( $ this ) ; } return $ this -> refClass ; }
|
Gets the ReflectionClass object for the current object .
|
3,846
|
final public function hasProperty ( $ property ) { if ( ! Str :: is ( $ property ) || ! Str :: match ( $ property , "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/" ) || $ property == 'this' ) { throw new \ InvalidArgumentException ( "The \$property parameter must be a string and follow the PHP rules of variable naming." ) ; } return property_exists ( $ this , $ property ) ; }
|
Checks if the object has the given property .
|
3,847
|
final public function hasMethod ( $ method ) { if ( ! Str :: is ( $ method ) || ! Str :: match ( $ method , "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/" ) ) { throw new \ InvalidArgumentException ( "The \$method parameter must be a string and follow the PHP rules of method naming." ) ; } return method_exists ( $ this , $ method ) ; }
|
Checks if the object has the given method .
|
3,848
|
public static function download ( $ location , $ filename = null , $ mime = 'application/octet-stream' , $ speed = 1024 , $ disposition = 'attachment' ) { if ( connection_status ( ) != 0 ) return ( false ) ; if ( ! is_file ( $ location ) ) { http_response_code ( 404 ) ; exit ( ) ; } if ( empty ( $ mime ) ) { $ mime = static :: getFileMime ( $ location ) ; } set_time_limit ( 0 ) ; while ( ob_get_level ( ) > 0 ) { ob_end_clean ( ) ; } if ( ! $ filename ) { $ filename = pathinfo ( $ location , PATHINFO_BASENAME ) ; } $ time = date ( 'r' , filemtime ( $ location ) ) ; $ size = filesize ( $ location ) ; $ speed = ( $ speed === null ) ? 1024 : intval ( $ speed ) * 1024 ; $ begin = 0 ; $ end = $ size ; $ status = 200 ; if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { if ( preg_match ( '/bytes=\h*(\d+)-(\d*)[\D.*]?/i' , $ _SERVER [ 'HTTP_RANGE' ] , $ matches ) ) { $ begin = intval ( $ matches [ 0 ] ) ; if ( ! empty ( $ matches [ 1 ] ) ) { $ end = intval ( $ matches [ 1 ] ) ; } $ status = 206 ; } } http_response_code ( $ status ) ; header ( 'Expires: 0' ) ; header ( "Content-Type: $mime" ) ; header ( 'Pragma: public' ) ; header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ) ; header ( 'Accept-Ranges: bytes' ) ; header ( 'Content-Length: ' . ( $ end - $ begin ) ) ; header ( "Content-Range: bytes $begin-" . ( $ end - 1 ) . "/$size" ) ; header ( "Content-Disposition: " . $ disposition . "; filename=$filename" ) ; header ( "Content-Transfer-Encoding: binary" ) ; header ( "Last-Modified: $time" ) ; header ( 'Connection: close' ) ; for ( $ offset = $ begin ; $ offset <= $ end ; $ offset += $ speed ) { if ( connection_status ( ) || connection_aborted ( ) ) { exit ( 1 ) ; } echo file_get_contents ( $ location , false , null , $ offset , $ speed ) ; while ( ob_get_level ( ) > 0 ) { ob_end_flush ( ) ; } flush ( ) ; usleep ( intval ( floatval ( $ time ) * 1000000 ) ) ; } return ( ( connection_status ( ) == 0 ) and ! connection_aborted ( ) ) ; }
|
Sends the file to the browser for download
|
3,849
|
public static function getFileMime ( $ filename , $ default = 'application/octet-stream' ) { if ( function_exists ( 'mime_content_type' ) ) { return mime_content_type ( $ filename ) ; } $ mime_types = array ( 'txt' => 'text/plain' , 'htm' => 'text/html' , 'html' => 'text/html' , 'php' => 'text/html' , 'css' => 'text/css' , 'js' => 'application/javascript' , 'json' => 'application/json' , 'xml' => 'application/xml' , 'swf' => 'application/x-shockwave-flash' , 'flv' => 'video/x-flv' , 'png' => 'image/png' , 'jpe' => 'image/jpeg' , 'jpeg' => 'image/jpeg' , 'jpg' => 'image/jpeg' , 'gif' => 'image/gif' , 'bmp' => 'image/bmp' , 'ico' => 'image/vnd.microsoft.icon' , 'tiff' => 'image/tiff' , 'tif' => 'image/tiff' , 'svg' => 'image/svg+xml' , 'svgz' => 'image/svg+xml' , 'zip' => 'application/zip' , 'rar' => 'application/x-rar-compressed' , 'exe' => 'application/x-msdownload' , 'msi' => 'application/x-msdownload' , 'cab' => 'application/vnd.ms-cab-compressed' , 'mp3' => 'audio/mpeg' , 'qt' => 'video/quicktime' , 'mov' => 'video/quicktime' , 'pdf' => 'application/pdf' , 'psd' => 'image/vnd.adobe.photoshop' , 'ai' => 'application/postscript' , 'eps' => 'application/postscript' , 'ps' => 'application/postscript' , 'doc' => 'application/msword' , 'rtf' => 'application/rtf' , 'xls' => 'application/vnd.ms-excel' , 'ppt' => 'application/vnd.ms-powerpoint' , 'odt' => 'application/vnd.oasis.opendocument.text' , 'ods' => 'application/vnd.oasis.opendocument.spreadsheet' , ) ; $ ext = substr ( strrchr ( $ filename , "." ) , 1 ) ; if ( array_key_exists ( $ ext , $ mime_types ) ) { return $ mime_types [ $ ext ] ; } elseif ( function_exists ( 'finfo_open' ) ) { $ finfo = finfo_open ( FILEINFO_MIME ) ; $ mimetype = finfo_file ( $ finfo , $ filename ) ; finfo_close ( $ finfo ) ; return $ mimetype ; } return $ default ; }
|
Get file s mime type
|
3,850
|
public static function notice ( $ slug , $ type = null ) { ob_start ( ) ; self :: template ( $ slug , 'notice' ) ; $ result = null ; if ( $ type == null ) { $ result = ob_get_flush ( ) ; } else { $ result = array ( 'message' => ob_get_flush ( ) , 'type' => $ type , ) ; } return $ result ; }
|
Loads notice templates .
|
3,851
|
public function buildErrorResponse ( \ Exception $ e ) { $ response = [ 'type' => get_class ( $ e ) , 'code' => $ e -> getCode ( ) , 'message' => $ e -> getMessage ( ) , 'data' => [ 'status' => 500 ] ] ; if ( $ e instanceof ModelNotFoundException ) { $ response [ 'data' ] [ 'status' ] = 404 ; } if ( $ e instanceof HttpException ) { $ response [ 'data' ] [ 'status' ] = $ e -> getStatusCode ( ) ; } if ( $ e instanceof ValidationException ) { $ response [ 'data' ] [ 'errors' ] = $ e -> messages ( ) ; } if ( $ this -> isDebugMode ( ) ) { $ response [ 'line' ] = $ e -> getLine ( ) ; $ response [ 'file' ] = $ e -> getFile ( ) ; $ response [ 'trace' ] = $ e -> getTraceAsString ( ) ; } return $ response ; }
|
Given an Exception build a data package suitable for reporting the error to the client .
|
3,852
|
public function retrieveCoreStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22CoreStats%22]" ) ; $ coreStats = json_decode ( $ data ) ; return $ coreStats ; }
|
Retrieve Core Stats
|
3,853
|
public function retrieveBadPlayerStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22BadPlayerStats%22]" ) ; $ badPlayerStats = json_decode ( $ data ) ; return $ badPlayerStats ; }
|
Retrieve Bad Player Stats
|
3,854
|
public function retrieveVehicleStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22VehicleStats%22]" ) ; $ vehicleStats = json_decode ( $ data ) ; return $ vehicleStats ; }
|
Retrieve Vehicle Stats
|
3,855
|
public function retrieveMapStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22MapStats%22]" ) ; $ mapStats = json_decode ( $ data ) ; return $ mapStats ; }
|
Retrieve Map Stats
|
3,856
|
public function retrieveGameModeMapStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22GameModeMapStats%22]" ) ; $ gameModeMapStats = json_decode ( $ data ) ; return $ gameModeMapStats ; }
|
Retrieve Game Mode Map Stats
|
3,857
|
public function retrieveWeaponStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22WeaponStats%22]" ) ; $ weapons = json_decode ( $ data ) ; return $ weapons ; }
|
Retrieve Weapon Stats
|
3,858
|
public function retrieveGameModeStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22GameModeStats%22]" ) ; $ gameModeStats = json_decode ( $ data ) ; return $ gameModeStats ; }
|
Retrieve Game Mode Stats
|
3,859
|
public function retrieveRushMapStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22RushMapStats%22]&_?=1351945928776" ) ; $ rushMapStats = json_decode ( $ data ) ; return $ rushMapStats ; }
|
Retrieve Rush Map Stats
|
3,860
|
public function retrieveGameEventStats ( ) { $ data = file_get_contents ( "http://battlefield.play4free.com/en/profile/stats/" . $ this -> _profileID . "/" . $ this -> _soldierID . "?g=[%22GameEventStats%22]" ) ; $ gameEventStats = json_decode ( $ data ) ; return $ gameEventStats ; }
|
Retrieve Game Event Stats
|
3,861
|
public function totalSeconds ( ) : int { return $ this -> days * 86400 + $ this -> h * 3600 + $ this -> i * 60 + $ this -> s ; }
|
Get the total number of seconds from the DateInterval .
|
3,862
|
private function isAuthorized ( Request $ request , Response $ response ) : bool { $ this -> authorized = false ; $ user = $ this -> authenticate ( $ request , $ response ) ; if ( null !== $ user && $ this -> authConstraint -> requiresRoles ( ) ) { $ roles = $ this -> roles ( $ response , $ user ) ; if ( null !== $ roles && $ this -> authConstraint -> satisfiedByRoles ( $ roles ) ) { $ request -> associate ( new Identity ( $ user , $ roles ) ) ; $ this -> authorized = true ; } elseif ( null !== $ roles ) { $ this -> error = $ response -> forbidden ( ) ; } } elseif ( null !== $ user ) { $ request -> associate ( new Identity ( $ user , Roles :: none ( ) ) ) ; $ this -> authorized = true ; } return $ this -> authorized ; }
|
checks if request is authorized
|
3,863
|
private function authenticate ( Request $ request , Response $ response ) { $ authenticationProvider = $ this -> injector -> getInstance ( AuthenticationProvider :: class ) ; try { $ user = $ authenticationProvider -> authenticate ( $ request ) ; if ( null == $ user && $ this -> authConstraint -> loginAllowed ( ) ) { $ response -> redirect ( $ authenticationProvider -> loginUri ( $ request ) ) ; } elseif ( null == $ user ) { $ this -> error = $ response -> forbidden ( ) ; return null ; } return $ user ; } catch ( AuthProviderException $ ahe ) { $ this -> handleAuthProviderException ( $ ahe , $ response ) ; return null ; } }
|
checks whether request is authenticated
|
3,864
|
private function roles ( Response $ response , User $ user ) { try { return $ this -> injector -> getInstance ( AuthorizationProvider :: class ) -> roles ( $ user ) ; } catch ( AuthProviderException $ ahe ) { $ this -> handleAuthProviderException ( $ ahe , $ response ) ; return null ; } }
|
checks whether expected role is given
|
3,865
|
private function handleAuthProviderException ( AuthProviderException $ ahe , Response $ response ) { if ( $ ahe -> isInternal ( ) ) { $ this -> error = $ response -> internalServerError ( $ ahe ) ; } else { $ response -> setStatusCode ( $ ahe -> getCode ( ) ) ; $ this -> error = new Error ( $ ahe -> getMessage ( ) ) ; } }
|
sets proper response status code depending on exception
|
3,866
|
public function isValid ( ) { $ this -> errorMessages = [ ] ; $ this -> validatorCollection -> rewind ( ) ; while ( $ this -> validatorCollection -> valid ( ) ) { $ this -> checkForErrors ( $ this -> validatorCollection -> current ( ) ) ; $ this -> validatorCollection -> next ( ) ; } $ count = count ( $ this -> errorMessages ) ; return $ count == 0 ; }
|
Runs the checkForErrors method for each field which adds to errorMessages if invalid
|
3,867
|
public function remove ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> items ) ) { throw new CollectionUnknownKeyException ( sprintf ( 'Item name=%s does not exist in collection' , $ name ) ) ; } unset ( $ this -> items [ $ name ] ) ; return true ; }
|
Remove an item from the collection
|
3,868
|
public function get ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> items ) ) { throw new CollectionUnknownKeyException ( sprintf ( 'Item name=%s does not exist in collection' , $ name ) ) ; } return $ this -> items [ $ name ] ; }
|
Get an item from the collection
|
3,869
|
public function processFile ( $ filePath , $ functions ) { $ result = array ( 'problems' => array ( ) , 'fixes' => array ( ) , ) ; $ phpTokens = new PhpFileParser ( $ filePath ) ; $ changes = 0 ; foreach ( $ phpTokens as $ key => $ row ) { if ( is_array ( $ row ) ) { list ( $ token , $ functionName , $ lineNumber ) = $ row ; $ originalFunctionName = $ functionName ; $ functionName = strtolower ( $ functionName ) ; if ( $ token == T_STRING && ! $ phpTokens -> isEqualToToken ( T_OBJECT_OPERATOR , $ key - 1 ) && ! $ phpTokens -> isEqualToToken ( T_DOUBLE_COLON , $ key - 1 ) && ! $ phpTokens -> isEqualToToken ( T_FUNCTION , $ key - 2 ) ) { if ( function_exists ( $ functionName ) && ! in_array ( $ functionName , $ this -> calledFunctions ) ) { $ this -> calledFunctions [ ] = $ functionName ; } if ( isset ( $ functions [ $ functionName ] ) ) { $ definingFunctionName = $ phpTokens -> getDefiningFunctionName ( $ key ) ; if ( ! $ definingFunctionName || ! isset ( $ functions [ strtolower ( $ definingFunctionName ) ] ) ) { $ result [ 'problems' ] [ ] = array ( $ functions [ $ functionName ] , $ originalFunctionName , $ lineNumber ) ; } if ( $ this -> fixProblems && isset ( $ this -> instantReplacements [ $ functionName ] ) ) { $ phpTokens [ $ key ] = array ( T_STRING , $ this -> instantReplacements [ $ functionName ] ) ; $ result [ 'fixes' ] [ ] = array ( $ originalFunctionName , $ this -> instantReplacements [ $ functionName ] , $ lineNumber ) ; $ changes ++ ; } } } } } if ( $ changes ) { try { $ phpTokens -> exportPhp ( $ filePath ) ; } catch ( \ CodeReview \ IOException $ e ) { echo '*** Error: ' . $ e -> getMessage ( ) . " ***\n" ; } } unset ( $ phpTokens ) ; return $ result ; }
|
Find function calls and extract
|
3,870
|
public function hidden ( Form \ Element \ Hidden $ element ) { $ html = html ( 'input' , $ element -> getAttributes ( ) ) ; return $ html ; }
|
render hidden input
|
3,871
|
public function label_date ( Form \ Element \ LabelDate $ element ) { $ html = '<label class="col-md-3 control-label">' . $ element -> getLabel ( ) . '</label>' ; $ html .= '<div class="col-md-9"><p class="form-control-static">' . $ element -> getDisplayValue ( ) . '</p></div>' ; $ class = Style :: FORM_GROUP_CLASS . ' row' ; return html ( 'div' , compact ( 'class' ) , $ html ) ; }
|
Render Label Date
|
3,872
|
public function image ( Form \ Element \ Image $ element ) { $ element -> addStyle ( 'object-fit' , 'cover !important;' ) ; $ element -> addAttribute ( 'src' , $ element -> getValue ( ) ) ; $ html = '<label class="col-md-3 control-label">' . $ element -> getLabel ( ) . '</label>' ; $ html .= '<div class="col-md-9"><p class="form-control-static">' . html ( 'img' , $ element -> getAttributes ( ) ) . '</p></div>' ; $ class = Style :: FORM_GROUP_CLASS . ' row' ; return html ( 'div' , compact ( 'class' ) , $ html ) ; }
|
Render Image input
|
3,873
|
public function button ( Form \ Element \ Button $ element ) { $ element -> addClass ( 'btn btn-default' ) ; $ element -> addAttribute ( 'id' , $ element -> getName ( ) ) ; $ html = '<div class="form-group">' ; $ html .= '<label class="col-md-3 control-label"> </label>' ; $ html .= '<div class="col-md-9">' . html ( 'button' , $ element -> getAttributes ( ) , $ element -> getLabel ( ) ) . '</div>' ; $ html .= '</div>' ; return $ html ; }
|
rende a button element
|
3,874
|
public function date_range ( Form \ Element \ DateRange $ element ) { $ class = Style :: FORM_GROUP_CLASS ; if ( $ hasError = ! $ element -> getValidator ( ) -> isValid ( ) ) { if ( empty ( $ element -> getAttribute ( 'data-placement' ) ) ) { $ element -> addAttribute ( 'data-placement' , 'bottom' ) ; } $ message = '' ; foreach ( $ element -> getValidator ( ) -> getErrors ( ) as $ error ) { $ message .= $ error . ' ' ; } $ element -> addAttribute ( 'data-original-title' , $ message ) ; $ element -> addAttribute ( 'data-toggle' , 'tooltip' ) ; $ class .= ' ' . Style :: FORM_GROUP_ERROR ; } $ label = '' ; if ( $ element -> getForm ( ) -> hasLabel ( ) ) { $ label = '<label for="' . $ element -> getName ( ) . '" class="col-md-3 control-label">' . $ element -> getLabel ( ) . ( $ element -> hasRule ( 'required' ) ? ' *' : '' ) . '</label>' ; } $ html = html ( 'input' , [ 'type' => 'text' , 'class' => Style :: FORM_ELEMENT_CONTROL , 'name' => $ element -> getFrom ( ) ] ) ; $ html .= '<span class="input-group-addon"> => </span>' ; $ html .= html ( 'input' , [ 'type' => 'text' , 'class' => Style :: FORM_ELEMENT_CONTROL , 'name' => $ element -> getTo ( ) ] ) ; $ html = html ( 'div' , [ 'class' => 'input-group input-large date-picker daterange input-daterange' , 'data-date-format' => configurator ( ) -> get ( 'form.element.date.formatjs' ) ] , $ html ) ; if ( $ element -> hasDescription ( ) ) { $ html .= html ( 'span' , [ 'class' => 'help-block' ] , $ element -> getDescription ( ) ) ; } $ html = html ( 'div' , [ 'class' => 'col-md-9' ] , $ html ) ; return html ( 'div' , compact ( 'class' ) , $ label . $ html ) ; }
|
Render a date range element
|
3,875
|
protected function parseRuleString ( $ ruleString ) { $ ruleString = preg_replace ( '/^[ \r\n\t\f]*@page[ \r\n\t\f]*/i' , '' , $ ruleString ) ; $ ruleString = trim ( $ ruleString , " \r\n\t\f" ) ; $ pageSelector = new PageSelector ( $ ruleString , $ this -> getStyleSheet ( ) ) ; $ this -> setSelector ( $ pageSelector ) ; }
|
Parses the page rule .
|
3,876
|
public function createDocumentManager ( $ mongouri , $ dbName , $ debug = false , $ managerId = "" , $ newConnection = false , $ options = [ ] ) { if ( ! isset ( $ this -> connexions [ $ mongouri ] ) ) { $ client = new Client ( $ mongouri ) ; } if ( ! isset ( $ this -> managers [ $ managerId ] ) ) { $ database = new Database ( $ client -> getManager ( ) , $ dbName ) ; $ class = $ this -> repositoryFactoryClass ; $ repositoryFactory = new $ class ( null , $ this -> classMetadataFactory ) ; $ this -> managers [ $ managerId ] = new DocumentManager ( $ client , $ database , $ repositoryFactory , $ debug , $ options , [ ] ) ; } return $ this -> managers [ $ managerId ] ; }
|
Create new DocumentManager from mongouri and DB name
|
3,877
|
protected function getFillableReplace ( ) { $ attributes = array_merge ( $ this -> data [ 'normal_fillable' ] , $ this -> data [ 'translated_fillable' ] ) ; if ( ! count ( $ attributes ) ) return '' ; return $ this -> getAttributePropertySection ( 'fillable' , $ attributes ) ; }
|
Returns the replacement for the fillable placeholder
|
3,878
|
protected function getCastsReplace ( ) { $ attributes = $ this -> data [ 'casts' ] ? : [ ] ; if ( ! count ( $ attributes ) ) return '' ; $ longestLength = 0 ; foreach ( $ attributes as $ attribute => $ type ) { if ( strlen ( $ attribute ) > $ longestLength ) { $ longestLength = strlen ( $ attribute ) ; } } $ replace = $ this -> tab ( ) . "protected \$casts = [\n" ; foreach ( $ attributes as $ attribute => $ type ) { $ replace .= $ this -> tab ( 2 ) . "'" . str_pad ( $ attribute . "'" , $ longestLength + 1 ) . " => '" . $ type . "',\n" ; } $ replace .= $ this -> tab ( ) . "];\n\n" ; return $ replace ; }
|
Returns the replacement for the casts placeholder
|
3,879
|
protected function getDefaultsReplace ( ) { if ( ! config ( 'pxlcms.generator.models.include_defaults' ) ) return '' ; $ attributes = $ this -> data [ 'defaults' ] ? : [ ] ; if ( ! count ( $ attributes ) ) return '' ; $ longestLength = 0 ; foreach ( $ attributes as $ attribute => $ default ) { if ( strlen ( $ attribute ) > $ longestLength ) { $ longestLength = strlen ( $ attribute ) ; } } $ replace = $ this -> tab ( ) . "protected \$attributes = [\n" ; foreach ( $ attributes as $ attribute => $ default ) { $ replace .= $ this -> tab ( 2 ) . "'" . str_pad ( $ attribute . "'" , $ longestLength + 1 ) . " => " . $ default . ",\n" ; } $ replace .= $ this -> tab ( ) . "];\n\n" ; return $ replace ; }
|
Returns the replacement for the default attributes placeholder
|
3,880
|
public function updateDataFixutreHistory ( array $ updateFields , $ where , array $ parameters = [ ] ) { $ qb = $ this -> _em -> createQueryBuilder ( ) -> update ( 'OkvpnFixtureBundle:DataFixture' , 'm' ) -> where ( $ where ) ; foreach ( $ updateFields as $ fieldName => $ fieldValue ) { $ qb -> set ( $ fieldName , $ fieldValue ) ; } $ qb -> getQuery ( ) -> execute ( $ parameters ) ; }
|
Update data fixture history
|
3,881
|
public static function is ( array $ arr ) { $ isdot = true ; foreach ( $ arr as $ key => $ value ) { if ( ! ( $ isdot = ( $ isdot && ! Str :: contains ( $ key , '.' ) ) ) ) { break ; } if ( is_array ( $ value ) ) { $ isdot = ( $ isdot && static :: is ( $ value ) ) ; } } return $ isdot ; }
|
Tests if the given value is a dot - notated accessible array .
|
3,882
|
protected static function getMultiple ( array $ arr , array $ keys , $ default = null ) { $ return = [ ] ; foreach ( $ keys as $ key ) { $ return [ $ key ] = static :: get ( $ arr , $ key , $ default ) ; } return $ return ; }
|
Gets multiple values from a dot - notated array .
|
3,883
|
protected static function setMultiple ( array & $ arr , array $ keyvals ) { foreach ( $ keyvals as $ key => $ value ) { static :: set ( $ arr , $ key , $ value ) ; } }
|
Sets multiple values to a dot - notated array .
|
3,884
|
protected static function deleteMultiple ( array & $ arr , array $ keys ) { $ return = [ ] ; foreach ( $ keys as $ key ) { $ return [ $ key ] = static :: delete ( $ arr , $ key ) ; } return $ return ; }
|
Deletes multiple items from a dot - notated array .
|
3,885
|
protected static function keyExistsMultiple ( array $ arr , array $ keys ) { $ return = [ ] ; foreach ( $ keys as $ key ) { $ return [ $ key ] = static :: keyExists ( $ arr , $ key ) ; } return $ return ; }
|
Verifies if multiple keys exists in a dot - notated array or not .
|
3,886
|
protected static function keyMatchesMultiple ( array $ arr , array $ keys ) { $ return = [ ] ; foreach ( $ keys as $ key ) { $ return [ $ key ] = static :: keyMatches ( $ arr , $ key ) ; } return $ return ; }
|
Gets full and partial matches to multiple keys .
|
3,887
|
public static function convert ( array $ arr ) { $ converted = [ ] ; foreach ( $ arr as $ key => $ value ) { $ keys = explode ( '.' , $ key ) ; $ tmp = & $ converted ; foreach ( $ keys as $ k ) { if ( ! array_key_exists ( $ k , $ tmp ) || ! is_array ( $ tmp [ $ k ] ) ) { $ tmp [ $ k ] = [ ] ; } $ tmp = & $ tmp [ $ k ] ; } $ tmp = is_array ( $ value ) ? static :: convert ( $ value ) : $ value ; } return $ converted ; }
|
Converts an array to a dot - notated array .
|
3,888
|
public function registerEventHandler ( $ event , callable $ handler ) { if ( empty ( $ event ) ) { throw new InvalidArgumentException ( 'Event name is required' ) ; } if ( is_callable ( $ handler ) ) { if ( empty ( $ this -> event_handlers [ $ event ] ) ) { $ this -> event_handlers [ $ event ] = [ ] ; } $ this -> event_handlers [ $ event ] [ ] = $ handler ; } else { throw new InvalidArgumentException ( 'Handler not callable' ) ; } }
|
Register an internal event handler .
|
3,889
|
private static function domain ( string $ url ) : ? string { $ domain = parse_url ( $ url , PHP_URL_HOST ) ; if ( null !== $ domain ) { return implode ( '.' , array_slice ( explode ( '.' , $ domain ) , - 2 ) ) ; } return null ; }
|
Returns the domain name from URL .
|
3,890
|
static public function getLabel ( $ code ) { static :: isValid ( $ code ) ; switch ( $ code ) { case static :: EBP : return 'Euro Business Parcel' ; case static :: GBP : return 'Global Business Parcel' ; case static :: EP : return 'Express Parcel Guaranteed' ; case static :: SHD : return 'Shop Delivery Service' ; case static :: FDF : return 'Flex Delivery Service' ; case static :: BP : default : return 'Business Parcel' ; } }
|
Returns the label for the given product code .
|
3,891
|
static function getUniShip ( $ code ) { static :: isValid ( $ code ) ; switch ( $ code ) { case static :: EBP : return 'CC' ; case static :: GBP : return 'FF' ; case static :: EP : case static :: SHD : case static :: FDF : return null ; case static :: BP : default : return 'AA' ; } }
|
Returns the UNI Ship equivalent product code .
|
3,892
|
public function transformEntity ( $ entity , $ transformer = null , SerializerAbstract $ serializer = null ) : array { $ transformer = $ transformer ? : $ this -> getTransformerFromClassProperty ( ) ; $ results = $ this -> transform ( ) -> resourceWith ( $ entity , $ transformer ) -> usingPaginatorIfPaged ( ) ; if ( $ serializer ) { return $ results -> serialize ( $ serializer ) ; } return $ results -> serialize ( ) ; }
|
Shortcut method for serializing and transforming an entity .
|
3,893
|
protected function getTransformerFromClassProperty ( ) { if ( ! isset ( $ this -> transformer ) || ! $ this -> isTransformer ( $ this -> transformer ) ) { throw new \ InvalidArgumentException ( 'You cannot transform the entity without providing a valid Transformer. Verify your transformer extends ' . TransformerAbstract :: class ) ; } return ( is_a ( $ this -> transformer , TransformerAbstract :: class , true ) && ! is_object ( $ this -> transformer ) ) ? new $ this -> transformer : $ this -> transformer ; }
|
Gets the transformer from the class and validates it s a correct serializer .
|
3,894
|
protected function mapApiRoutes ( ) { Route :: group ( [ 'middleware' => 'api' , 'namespace' => $ this -> namespace . '\Api' , 'domain' => config ( 'hstcms.apiDomain' ) ? config ( 'hstcms.apiDomain' ) : env ( 'APP_URL' ) , 'prefix' => config ( 'hstcms.apiDomain' ) ? '' : config ( 'hstcms.apiPrefix' ) ? config ( 'hstcms.apiPrefix' ) : 'api' , ] , function ( $ router ) { require __DIR__ . '/../Routes/api.php' ; } ) ; }
|
Define the api routes for the module .
|
3,895
|
private function setUrl ( Url $ url ) { $ urlValidationRegex = '_https:\/\/hooks.slack.com\/services\/[\w\/]+$_iuS' ; if ( ! preg_match ( $ urlValidationRegex , ( string ) $ url ) ) { throw new InvalidUrlException ( sprintf ( 'The url: "%s" is not a valid url. Slack webhook urls should always start with "https://hooks.slack.com/services/"' , $ url ) , 400 ) ; } $ this -> url = $ url ; return $ this ; }
|
This wil set the url if it is valid .
|
3,896
|
public function dec ( ) : array { $ colors = str_split ( $ this -> hex ( 'no-hash' ) , 2 ) ; return array_map ( function ( $ color ) { return hexdec ( $ color ) ; } , $ colors ) ; }
|
Get the CSS decimal color .
|
3,897
|
public static function validateHexColorString ( string $ hex ) : bool { $ length = strlen ( ltrim ( $ hex , '#' ) ) ; switch ( $ length ) { case 3 : break ; case 6 : break ; default : return false ; } return preg_match ( '/^#?[0-9a-fA-F]{3,6}$/' , $ hex ) === 1 ; }
|
Validates CSS hexadecimal color .
|
3,898
|
public function upload ( ThumbnailRequest $ request ) { $ crudeName = $ request -> input ( 'crudeName' ) ; $ crude = CrudeInstance :: get ( $ crudeName ) ; $ column = $ request -> input ( 'columnName' ) ; $ file = $ request -> file ( ) [ 'file' ] ; $ id = $ request -> input ( 'modelId' ) ; $ model = $ crude -> uploadThumbnailByIdAndColumn ( $ id , $ column , $ file ) ; return [ 'success' => true , 'model' => $ model ] ; }
|
Handle thumbnail upload
|
3,899
|
public function delete ( ThumbnailRequest $ request ) { $ crudeName = $ request -> input ( 'crudeName' ) ; $ crude = CrudeInstance :: get ( $ crudeName ) ; $ id = $ request -> input ( 'model_id' ) ; $ column = $ request -> input ( 'model_column' ) ; $ model = $ crude -> deleteThumbnailByIdAndColumn ( $ id , $ column ) ; return [ 'model' => $ model ] ; }
|
delete thumbnail file
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.