idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
21,400 | public static function formatSize ( $ size , $ unit = null , $ decimals = 2 ) { $ units = static :: getUnits ( ) ; $ index = array_search ( $ unit , $ units ) ; if ( null !== $ unit && false === $ index ) { throw new IllegalArgumentException ( "The unit \"" . $ unit . "\" does not exists" ) ; } $ output = $ size ; $ iteration = 0 ; while ( self :: FILE_SIZE_DIVIDER <= $ output || $ iteration < $ index ) { $ output /= self :: FILE_SIZE_DIVIDER ; ++ $ iteration ; } return implode ( " " , [ sprintf ( "%." . $ decimals . "f" , $ output ) , $ units [ $ iteration ] ] ) ; } | Format a size . |
21,401 | public static function getFilenames ( $ pathname , $ extension = null ) { if ( false === file_exists ( $ pathname ) ) { throw new FileNotFoundException ( $ pathname ) ; } $ filenames = [ ] ; if ( false !== ( $ directory = opendir ( $ pathname ) ) ) { $ offset = strlen ( $ extension ) ; while ( ( $ file = readdir ( $ directory ) ) !== false ) { if ( false === in_array ( $ file , [ "." , ".." ] ) && ( ( null === $ extension ) || 0 === substr_compare ( $ file , $ extension , - $ offset ) ) ) { $ filenames [ ] = $ file ; } } closedir ( $ directory ) ; } return $ filenames ; } | Get the filenames . |
21,402 | public static function getSize ( $ filename ) { if ( false === file_exists ( $ filename ) ) { throw new FileNotFoundException ( $ filename ) ; } clearstatcache ( ) ; return filesize ( $ filename ) ; } | Get a file size . |
21,403 | public static function getUnits ( ) { return [ self :: FILE_SIZE_UNIT_B , self :: FILE_SIZE_UNIT_KB , self :: FILE_SIZE_UNIT_MB , self :: FILE_SIZE_UNIT_GB , self :: FILE_SIZE_UNIT_TB , self :: FILE_SIZE_UNIT_PB , self :: FILE_SIZE_UNIT_EB , self :: FILE_SIZE_UNIT_ZB , self :: FILE_SIZE_UNIT_YB , ] ; } | Get the units . |
21,404 | public static function zip ( $ source , $ destination ) { if ( false === file_exists ( $ source ) ) { throw new FileNotFoundException ( $ source ) ; } $ zip = new ZipArchive ( ) ; $ zip -> open ( $ destination , ZipArchive :: CREATE ) ; $ src = str_replace ( "\\\\" , "/" , realpath ( $ source ) ) ; if ( true === is_file ( $ src ) ) { $ zip -> addFromString ( basename ( $ src ) , static :: getContents ( $ src ) ) ; return $ zip -> close ( ) ; } $ files = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ src ) , RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ files as $ current ) { $ cur = str_replace ( "\\\\" , "/" , realpath ( $ current ) ) ; $ zipPath = preg_replace ( "/^" . str_replace ( "/" , "\/" , $ src . "/" ) . "/" , "" , $ cur ) ; if ( true === is_file ( $ cur ) ) { $ zip -> addFromString ( $ zipPath , static :: getContents ( $ cur ) ) ; } if ( true === is_dir ( $ cur ) ) { $ zip -> addEmptyDir ( $ zipPath ) ; } } } | Zip a file . |
21,405 | public function exists ( $ customerId , array $ addressToCheck ) { unset ( $ addressToCheck [ 'email' ] ) ; if ( empty ( $ addressToCheck [ 'company' ] ) ) { unset ( $ addressToCheck [ 'company' ] ) ; } $ addressCollection = $ this -> addressFactory -> create ( ) -> getCollection ( ) -> addFieldToFilter ( 'parent_id' , $ customerId ) ; foreach ( $ addressToCheck as $ addressField => $ fieldValue ) { $ addressCollection -> addFieldToFilter ( $ addressField , $ fieldValue ) ; } return $ addressCollection -> count ( ) > 0 ; } | Checks if provided address is also saved as an address for the given customer by filtering its customer address |
21,406 | private function quickSort ( $ min , $ max ) { $ i = $ min ; $ j = $ max ; $ pivot = $ this -> values [ $ min + ( $ max - $ min ) / 2 ] ; while ( $ i <= $ j ) { while ( true === $ this -> functor -> compare ( $ this -> values [ $ i ] , $ pivot ) ) { ++ $ i ; } while ( true === $ this -> functor -> compare ( $ pivot , $ this -> values [ $ j ] ) ) { -- $ j ; } if ( $ i <= $ j ) { $ this -> swap ( $ i , $ j ) ; ++ $ i ; -- $ j ; } } if ( $ min < $ j ) { $ this -> quickSort ( $ min , $ j ) ; } if ( $ i < $ max ) { $ this -> quickSort ( $ i , $ max ) ; } } | Quick sort the values . |
21,407 | private function swap ( $ a , $ b ) { $ value = $ this -> values [ $ a ] ; $ this -> values [ $ a ] = $ this -> values [ $ b ] ; $ this -> values [ $ b ] = $ value ; } | Swap two values . |
21,408 | function _decodeLength ( & $ string ) { $ length = ord ( $ this -> _string_shift ( $ string ) ) ; if ( $ length & 0x80 ) { $ length &= 0x7F ; $ temp = $ this -> _string_shift ( $ string , $ length ) ; list ( , $ length ) = unpack ( 'N' , substr ( str_pad ( $ temp , 4 , chr ( 0 ) , STR_PAD_LEFT ) , - 4 ) ) ; } return $ length ; } | DER - decode the length |
21,409 | function _rsaes_pkcs1_v1_5_encrypt ( $ m ) { $ mLen = strlen ( $ m ) ; if ( $ mLen > $ this -> k - 11 ) { user_error ( 'Message too long' ) ; return false ; } $ psLen = $ this -> k - $ mLen - 3 ; $ ps = '' ; while ( strlen ( $ ps ) != $ psLen ) { $ temp = crypt_random_string ( $ psLen - strlen ( $ ps ) ) ; $ temp = str_replace ( "\x00" , '' , $ temp ) ; $ ps .= $ temp ; } $ type = 2 ; if ( defined ( 'CRYPT_RSA_PKCS15_COMPAT' ) && ( ! isset ( $ this -> publicExponent ) || $ this -> exponent !== $ this -> publicExponent ) ) { $ type = 1 ; $ ps = str_repeat ( "\xFF" , $ psLen ) ; } $ em = chr ( 0 ) . chr ( $ type ) . $ ps . chr ( 0 ) . $ m ; $ m = $ this -> _os2ip ( $ em ) ; $ c = $ this -> _rsaep ( $ m ) ; $ c = $ this -> _i2osp ( $ c , $ this -> k ) ; return $ c ; } | RSAES - PKCS1 - V1_5 - ENCRYPT |
21,410 | function _rsassa_pkcs1_v1_5_verify ( $ m , $ s ) { if ( strlen ( $ s ) != $ this -> k ) { user_error ( 'Invalid signature' ) ; return false ; } $ s = $ this -> _os2ip ( $ s ) ; $ m2 = $ this -> _rsavp1 ( $ s ) ; if ( $ m2 === false ) { user_error ( 'Invalid signature' ) ; return false ; } $ em = $ this -> _i2osp ( $ m2 , $ this -> k ) ; if ( $ em === false ) { user_error ( 'Invalid signature' ) ; return false ; } $ em2 = $ this -> _emsa_pkcs1_v1_5_encode ( $ m , $ this -> k ) ; if ( $ em2 === false ) { user_error ( 'RSA modulus too short' ) ; return false ; } return $ this -> _equals ( $ em , $ em2 ) ; } | RSASSA - PKCS1 - V1_5 - VERIFY |
21,411 | public function getReflector ( ) { if ( $ this -> isFunction ( ) || $ this -> isClosure ( ) ) { return new \ ReflectionFunction ( $ this -> getCallable ( ) ) ; } if ( $ this -> isMethod ( ) ) { return new \ ReflectionMethod ( $ this -> getClassName ( ) , $ this -> getMethodName ( ) ) ; } if ( $ this -> isInvokedObject ( ) ) { return new \ ReflectionMethod ( $ this -> getClassName ( ) , '__invoke' ) ; } throw new \ LogicException ( 'Unknown callable reflection' ) ; } | Returns the appropriate class of the callable reflection . |
21,412 | public static function getCloudInstance ( $ accessKey , $ secretKey , $ apiHost , $ cloudId ) { $ config = array ( 'accounts' => array ( 'default' => array ( 'access_key' => $ accessKey , 'secret_key' => $ secretKey , 'api_host' => $ apiHost , ) , ) , 'clouds' => array ( 'default' => array ( 'id' => $ cloudId , 'account' => 'default' , ) ) , ) ; $ api = new static ( $ config ) ; return $ api -> getCloud ( 'default' ) ; } | Creates a cloud . |
21,413 | function _mapInAttributes ( & $ root , $ path , $ asn1 ) { $ attributes = & $ this -> _subArray ( $ root , $ path ) ; if ( is_array ( $ attributes ) ) { for ( $ i = 0 ; $ i < count ( $ attributes ) ; $ i ++ ) { $ id = $ attributes [ $ i ] [ 'type' ] ; $ map = $ this -> _getMapping ( $ id ) ; if ( is_array ( $ attributes [ $ i ] [ 'value' ] ) ) { $ values = & $ attributes [ $ i ] [ 'value' ] ; for ( $ j = 0 ; $ j < count ( $ values ) ; $ j ++ ) { $ value = $ asn1 -> encodeDER ( $ values [ $ j ] , $ this -> AttributeValue ) ; $ decoded = $ asn1 -> decodeBER ( $ value ) ; if ( ! is_bool ( $ map ) ) { $ mapped = $ asn1 -> asn1map ( $ decoded [ 0 ] , $ map ) ; if ( $ mapped !== false ) { $ values [ $ j ] = $ mapped ; } if ( $ id == 'pkcs-9-at-extensionRequest' && $ this -> _isSubArrayValid ( $ values , $ j ) ) { $ this -> _mapInExtensions ( $ values , $ j , $ asn1 ) ; } } elseif ( $ map ) { $ values [ $ j ] = base64_encode ( $ value ) ; } } } } } } | Map attribute values from ANY type to attribute - specific internal format . |
21,414 | function _mapOutAttributes ( & $ root , $ path , $ asn1 ) { $ attributes = & $ this -> _subArray ( $ root , $ path ) ; if ( is_array ( $ attributes ) ) { $ size = count ( $ attributes ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { $ id = $ attributes [ $ i ] [ 'type' ] ; $ map = $ this -> _getMapping ( $ id ) ; if ( $ map === false ) { user_error ( $ id . ' is not a currently supported attribute' , E_USER_NOTICE ) ; unset ( $ attributes [ $ i ] ) ; } elseif ( is_array ( $ attributes [ $ i ] [ 'value' ] ) ) { $ values = & $ attributes [ $ i ] [ 'value' ] ; for ( $ j = 0 ; $ j < count ( $ values ) ; $ j ++ ) { switch ( $ id ) { case 'pkcs-9-at-extensionRequest' : $ this -> _mapOutExtensions ( $ values , $ j , $ asn1 ) ; break ; } if ( ! is_bool ( $ map ) ) { $ temp = $ asn1 -> encodeDER ( $ values [ $ j ] , $ map ) ; $ decoded = $ asn1 -> decodeBER ( $ temp ) ; $ values [ $ j ] = $ asn1 -> asn1map ( $ decoded [ 0 ] , $ this -> AttributeValue ) ; } } } } } } | Map attribute values from attribute - specific internal format to ANY type . |
21,415 | function _mapOutDNs ( & $ root , $ path , $ asn1 ) { $ dns = & $ this -> _subArray ( $ root , $ path ) ; if ( is_array ( $ dns ) ) { $ size = count ( $ dns ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { for ( $ j = 0 ; $ j < count ( $ dns [ $ i ] ) ; $ j ++ ) { $ type = $ dns [ $ i ] [ $ j ] [ 'type' ] ; $ value = & $ dns [ $ i ] [ $ j ] [ 'value' ] ; if ( is_object ( $ value ) && strtolower ( get_class ( $ value ) ) == 'file_asn1_element' ) { continue ; } $ map = $ this -> _getMapping ( $ type ) ; if ( ! is_bool ( $ map ) ) { $ value = new File_ASN1_Element ( $ asn1 -> encodeDER ( $ value , $ map ) ) ; } } } } } | Map DN values from DN - specific internal format to ANY type . |
21,416 | function _decodeIP ( $ ip ) { $ ip = base64_decode ( $ ip ) ; list ( , $ ip ) = unpack ( 'N' , $ ip ) ; return long2ip ( $ ip ) ; } | Decodes an IP address |
21,417 | function removeDNProp ( $ propName ) { if ( empty ( $ this -> dn ) ) { return ; } if ( ( $ propName = $ this -> _translateDNProp ( $ propName ) ) === false ) { return ; } $ dn = & $ this -> dn [ 'rdnSequence' ] ; $ size = count ( $ dn ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { if ( $ dn [ $ i ] [ 0 ] [ 'type' ] == $ propName ) { unset ( $ dn [ $ i ] ) ; } } $ dn = array_values ( $ dn ) ; } | Remove Distinguished Name properties |
21,418 | function getChain ( ) { $ chain = array ( $ this -> currentCert ) ; if ( ! is_array ( $ this -> currentCert ) || ! isset ( $ this -> currentCert [ 'tbsCertificate' ] ) ) { return false ; } if ( empty ( $ this -> CAs ) ) { return $ chain ; } while ( true ) { $ currentCert = $ chain [ count ( $ chain ) - 1 ] ; for ( $ i = 0 ; $ i < count ( $ this -> CAs ) ; $ i ++ ) { $ ca = $ this -> CAs [ $ i ] ; if ( $ currentCert [ 'tbsCertificate' ] [ 'issuer' ] === $ ca [ 'tbsCertificate' ] [ 'subject' ] ) { $ authorityKey = $ this -> getExtension ( 'id-ce-authorityKeyIdentifier' , $ currentCert ) ; $ subjectKeyID = $ this -> getExtension ( 'id-ce-subjectKeyIdentifier' , $ ca ) ; switch ( true ) { case ! is_array ( $ authorityKey ) : case is_array ( $ authorityKey ) && isset ( $ authorityKey [ 'keyIdentifier' ] ) && $ authorityKey [ 'keyIdentifier' ] === $ subjectKeyID : if ( $ currentCert === $ ca ) { break 3 ; } $ chain [ ] = $ ca ; break 2 ; } } } if ( $ i == count ( $ this -> CAs ) ) { break ; } } foreach ( $ chain as $ key => $ value ) { $ chain [ $ key ] = new File_X509 ( ) ; $ chain [ $ key ] -> loadX509 ( $ value ) ; } return $ chain ; } | Get the certificate chain for the current cert |
21,419 | function _removeExtension ( $ id , $ path = null ) { $ extensions = & $ this -> _extensions ( $ this -> currentCert , $ path ) ; if ( ! is_array ( $ extensions ) ) { return false ; } $ result = false ; foreach ( $ extensions as $ key => $ value ) { if ( $ value [ 'extnId' ] == $ id ) { unset ( $ extensions [ $ key ] ) ; $ result = true ; } } $ extensions = array_values ( $ extensions ) ; return $ result ; } | Remove an Extension |
21,420 | public function parseEntity ( Customer $ entity ) { $ output = [ $ this -> encodeInteger ( $ entity -> getCustomerNumber ( ) , 9 ) , $ this -> encodeString ( $ entity -> getTitle ( ) , 10 ) , $ this -> encodeString ( $ entity -> getSurname ( ) , 25 ) , $ this -> encodeString ( $ entity -> getFirstname ( ) , 25 ) , $ this -> encodeString ( $ entity -> getStreet ( ) , 25 ) , $ this -> encodeString ( $ entity -> getPCode ( ) , 10 ) , $ this -> encodeString ( $ entity -> getCity ( ) , 25 ) , $ this -> encodeString ( $ entity -> getCountry ( ) , 3 ) , $ this -> encodeString ( $ entity -> getTaxCode ( ) , 16 ) , $ this -> encodeString ( $ entity -> getIdDocumentNo ( ) , 15 ) , $ this -> encodeString ( $ entity -> getTelephone ( ) , 20 ) , $ this -> encodeString ( $ entity -> getRentalAgreementNo ( ) , 20 ) , $ this -> encodeDate ( $ entity -> getBeginDate ( ) ) , $ this -> encodeDate ( $ entity -> getTerminationDate ( ) ) , $ this -> encodeInteger ( $ entity -> getDeposit ( ) , 12 ) , $ this -> encodeInteger ( $ entity -> getMaximumLevel ( ) , 4 ) , $ this -> encodeString ( $ entity -> getRemarks ( ) , 50 ) , $ this -> encodeDateTime ( $ entity -> getDatetimeLastModification ( ) ) , $ this -> encodeBoolean ( $ entity -> getBlocked ( ) ) , $ this -> encodeDate ( $ entity -> getBlockedDate ( ) ) , $ this -> encodeBoolean ( $ entity -> getDeletedRecord ( ) ) , $ this -> encodeBoolean ( $ entity -> getTicketReturnAllowed ( ) ) , $ this -> encodeBoolean ( $ entity -> getGroupCounting ( ) ) , $ this -> encodeBoolean ( $ entity -> getEntryMaxLevelAllowed ( ) ) , $ this -> encodeBoolean ( $ entity -> getMaxLevelCarPark ( ) ) , $ this -> encodeString ( $ entity -> getRemarks2 ( ) , 50 ) , $ this -> encodeString ( $ entity -> getRemarks3 ( ) , 50 ) , $ this -> encodeString ( $ entity -> getDivision ( ) , 25 ) , $ this -> encodeString ( $ entity -> getEmail ( ) , 120 ) , $ this -> encodeBoolean ( $ entity -> getCountingNeutralCards ( ) ) , $ this -> encodeString ( $ entity -> getNationality ( ) , 3 ) , $ this -> encodeString ( $ entity -> getAccountingNumber ( ) , 20 ) , ] ; return implode ( ";" , $ output ) ; } | Parse a customer entity . |
21,421 | public function matches ( Node $ toMatch ) { if ( $ toMatch -> isConcrete ( ) ) { if ( $ toMatch instanceof Literal ) { return $ this -> getValue ( ) === $ toMatch -> getValue ( ) && $ this -> getDatatype ( ) === $ toMatch -> getDatatype ( ) && $ this -> getLanguage ( ) === $ toMatch -> getLanguage ( ) ; } return false ; } else { throw new \ Exception ( 'The node to match has to be a concrete node' ) ; } } | A literal matches only another literal if its value datatype and language are equal . |
21,422 | protected function createOrchestraDriver ( ) : Notification { $ mailer = $ this -> app -> make ( 'orchestra.mail' ) ; $ notifier = new Handlers \ Orchestra ( $ mailer ) ; if ( $ mailer -> attached ( ) ) { $ notifier -> attach ( $ mailer -> getMemoryProvider ( ) ) ; } else { $ notifier -> attach ( $ this -> app -> make ( 'orchestra.memory' ) -> makeOrFallback ( ) ) ; } return $ notifier ; } | Create Orchestra Platform driver . |
21,423 | public function getCustomFields ( $ object ) { $ customFields = [ ] ; foreach ( $ object -> getCustomFields ( ) as $ field ) { $ customFields [ $ field -> getInternalFieldName ( ) ] = $ field -> getValue ( ) ; } return $ customFields ; } | Creates a custom field array |
21,424 | public function startup ( ) { $ manager = ObjectManager :: getInstance ( ) ; $ forwarderInitializer = $ manager -> get ( 'Shopgate\Base\Helper\Initializer\Forwarder' ) ; $ this -> config = $ forwarderInitializer -> getMainConfig ( ) ; $ this -> settingsApi = $ forwarderInitializer -> getSettingsInterface ( ) ; $ this -> exportApi = $ forwarderInitializer -> getExportInterface ( ) ; $ this -> importApi = $ forwarderInitializer -> getImportInterface ( ) ; $ this -> cronApi = $ forwarderInitializer -> getCronInterface ( ) ; $ configInitializer = $ forwarderInitializer -> getConfigInitializer ( ) ; $ this -> storeManager = $ configInitializer -> getStoreManager ( ) ; $ this -> config -> loadConfig ( ) ; } | Gets called on initialization |
21,425 | protected function addEntityMapping ( ContainerBuilder $ container , $ entityManagerName , $ entityNamespace , $ entityMappingFilePath , $ enable = true ) : self { $ entityMapping = $ this -> resolveEntityMapping ( $ container , $ entityManagerName , $ entityNamespace , $ entityMappingFilePath , $ enable ) ; if ( $ entityMapping instanceof EntityMapping ) { $ this -> registerLocatorConfigurator ( $ container ) ; $ this -> registerLocator ( $ container , $ entityMapping ) ; $ this -> registerDriver ( $ container , $ entityMapping ) ; $ this -> addDriverInDriverChain ( $ container , $ entityMapping ) ; $ this -> addAliases ( $ container , $ entityMapping ) ; } return $ this ; } | Add mapping entity . |
21,426 | private function resolveEntityMapping ( ContainerBuilder $ container , string $ entityManagerName , string $ entityNamespace , string $ entityMappingFilePath , $ enable = true ) : ? EntityMapping { $ enableEntityMapping = $ this -> resolveParameterName ( $ container , $ enable ) ; if ( false === $ enableEntityMapping ) { return null ; } $ entityNamespace = $ this -> resolveParameterName ( $ container , $ entityNamespace ) ; if ( ! class_exists ( $ entityNamespace ) ) { throw new ConfigurationInvalidException ( 'Entity ' . $ entityNamespace . ' not found' ) ; } $ entityMappingFilePath = $ this -> resolveParameterName ( $ container , $ entityMappingFilePath ) ; $ entityManagerName = $ this -> resolveParameterName ( $ container , $ entityManagerName ) ; $ this -> resolveEntityManagerName ( $ container , $ entityManagerName ) ; return new EntityMapping ( $ entityNamespace , $ entityMappingFilePath , $ entityManagerName ) ; } | Resolve EntityMapping inputs and build a consistent EntityMapping object . |
21,427 | private function registerLocatorConfigurator ( ContainerBuilder $ container ) { $ locatorConfiguratorId = 'simple_doctrine_mapping.locator_configurator' ; if ( $ container -> hasDefinition ( $ locatorConfiguratorId ) ) { return ; } $ locatorConfigurator = new Definition ( 'Mmoreram\SimpleDoctrineMapping\Configurator\LocatorConfigurator' ) ; $ locatorConfigurator -> setPublic ( true ) ; $ locatorConfigurator -> setArguments ( [ new Reference ( 'kernel' ) , ] ) ; $ container -> setDefinition ( $ locatorConfiguratorId , $ locatorConfigurator ) ; } | Register locator configurator . |
21,428 | private function registerLocator ( ContainerBuilder $ container , EntityMapping $ entityMapping ) { $ locatorId = 'simple_doctrine_mapping.locator.' . $ entityMapping -> getUniqueIdentifier ( ) ; $ locator = new Definition ( 'Mmoreram\SimpleDoctrineMapping\Locator\SimpleDoctrineMappingLocator' ) ; $ locator -> setPublic ( false ) ; $ locator -> setArguments ( [ $ entityMapping -> getEntityNamespace ( ) , [ $ entityMapping -> getEntityMappingFilePath ( ) ] , ] ) ; $ locator -> setConfigurator ( [ new Reference ( 'simple_doctrine_mapping.locator_configurator' ) , 'configure' , ] ) ; $ container -> setDefinition ( $ locatorId , $ locator ) ; } | Register the locator . |
21,429 | private function addDriverInDriverChain ( ContainerBuilder $ container , EntityMapping $ entityMapping ) { $ chainDriverDefinition = $ container -> getDefinition ( 'doctrine.orm.' . $ entityMapping -> getEntityManagerName ( ) . '_metadata_driver' ) ; $ container -> setParameter ( 'doctrine.orm.metadata.driver_chain.class' , 'Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain' ) ; $ chainDriverDefinition -> addMethodCall ( 'addDriver' , [ new Reference ( 'doctrine.orm.' . $ entityMapping -> getUniqueIdentifier ( ) . '_metadata_driver' ) , $ entityMapping -> getEntityNamespace ( ) , ] ) ; } | Register and override the DriverChain definition . |
21,430 | private function addAliases ( ContainerBuilder $ container , EntityMapping $ entityMapping ) { $ entityMappingFilePath = $ entityMapping -> getEntityMappingFilePath ( ) ; if ( strpos ( $ entityMappingFilePath , '@' ) === 0 ) { $ bundleName = trim ( explode ( '/' , $ entityMappingFilePath , 2 ) [ 0 ] ) ; $ className = explode ( '\\' , $ entityMapping -> getEntityNamespace ( ) ) ; unset ( $ className [ count ( $ className ) - 1 ] ) ; $ configurationServiceDefinition = $ container -> getDefinition ( 'doctrine.orm.' . $ entityMapping -> getEntityManagerName ( ) . '_configuration' ) ; $ configurationServiceDefinition -> addMethodCall ( 'addEntityNamespace' , [ $ bundleName , implode ( '\\' , $ className ) , ] ) ; } } | Add aliases for short Doctrine accessing mode . |
21,431 | private function resolveEntityManagerName ( ContainerBuilder $ container , string $ entityManagerName ) { if ( ! $ container -> has ( 'doctrine.orm.' . $ entityManagerName . '_metadata_driver' ) ) { throw new EntityManagerNotFoundException ( $ entityManagerName ) ; } } | Throws an exception if given entityName is not available or does not exist . |
21,432 | public function removeHeader ( $ name ) { if ( true === array_key_exists ( $ name , $ this -> headers ) ) { unset ( $ this -> headers [ $ name ] ) ; } } | Remove an header . |
21,433 | public function dimensions ( ) { return $ this -> _cache ( __FUNCTION__ , function ( $ file ) { $ dims = null ; if ( ! $ file -> isImage ( ) ) { return $ dims ; } $ data = @ getimagesize ( $ file -> path ( ) ) ; if ( $ data && is_array ( $ data ) ) { $ dims = array ( 'width' => $ data [ 0 ] , 'height' => $ data [ 1 ] ) ; } if ( ! $ data ) { $ image = @ imagecreatefromstring ( file_get_contents ( $ file -> path ( ) ) ) ; $ dims = array ( 'width' => @ imagesx ( $ image ) , 'height' => @ imagesy ( $ image ) ) ; } return $ dims ; } ) ; } | Return the dimensions of the file if it is an image . |
21,434 | public function exif ( array $ fields = array ( ) ) { if ( ! function_exists ( 'exif_read_data' ) ) { return array ( ) ; } return $ this -> _cache ( __FUNCTION__ , function ( $ file ) use ( $ fields ) { $ exif = array ( ) ; $ fields = $ fields + array ( 'make' => 'Make' , 'model' => 'Model' , 'exposure' => 'ExposureTime' , 'orientation' => 'Orientation' , 'fnumber' => 'FNumber' , 'date' => 'DateTime' , 'iso' => 'ISOSpeedRatings' , 'focal' => 'FocalLength' , 'latitude' => 'GPSLatitude' , 'longitude' => 'GPSLongitude' ) ; if ( $ file -> supportsExif ( ) ) { if ( $ data = @ exif_read_data ( $ file -> path ( ) ) ) { foreach ( $ fields as $ key => $ find ) { $ value = '' ; if ( ! empty ( $ data [ $ find ] ) ) { if ( $ key === 'latitude' || $ key === 'longitude' ) { $ deg = $ data [ $ find ] [ 0 ] ; $ min = $ data [ $ find ] [ 1 ] ; $ sec = $ data [ $ find ] [ 2 ] ; $ value = $ deg + ( ( ( $ min * 60 ) + $ sec ) / 3600 ) ; } else { $ value = $ data [ $ find ] ; } } $ exif [ $ key ] = $ value ; } } } if ( ! $ exif ) { $ exif = array_map ( function ( ) { return '' ; } , $ fields ) ; } return $ exif ; } ) ; } | Attempt to read and determine correct exif data . |
21,435 | public function ext ( ) { return $ this -> _cache ( __FUNCTION__ , function ( $ file ) { $ path = $ file -> data ( 'name' ) ? : $ file -> path ( ) ; return mb_strtolower ( pathinfo ( $ path , PATHINFO_EXTENSION ) ) ; } ) ; } | Return the extension . |
21,436 | public function height ( ) { return $ this -> _cache ( __FUNCTION__ , function ( $ file ) { if ( ! $ file -> isImage ( ) ) { return null ; } $ height = 0 ; if ( $ dims = $ file -> dimensions ( ) ) { $ height = $ dims [ 'height' ] ; } return $ height ; } ) ; } | Return the image height . |
21,437 | public function move ( $ path , $ overwrite = false ) { $ path = str_replace ( '\\' , '/' , $ path ) ; if ( substr ( $ path , - 1 ) !== '/' ) { $ path .= '/' ; } if ( realpath ( $ path ) === realpath ( $ this -> dir ( ) ) ) { return true ; } if ( ! file_exists ( $ path ) ) { mkdir ( $ path , 0777 , true ) ; } else if ( ! is_writable ( $ path ) ) { chmod ( $ path , 0777 ) ; } $ name = $ this -> name ( ) ; $ ext = $ this -> ext ( ) ; if ( ! $ overwrite ) { $ no = 1 ; while ( file_exists ( $ path . $ name . '.' . $ ext ) ) { $ name = $ this -> name ( ) . '-' . $ no ; $ no ++ ; } } $ targetPath = $ path . $ name . '.' . $ ext ; if ( rename ( $ this -> path ( ) , $ targetPath ) ) { $ this -> reset ( $ targetPath ) ; return true ; } return false ; } | Move the file to a new directory . If a file with the same name already exists either overwrite or increment file name . |
21,438 | public function rename ( $ name = '' , $ append = '' , $ prepend = '' , $ overwrite = false ) { if ( is_callable ( $ name ) ) { $ name = call_user_func_array ( $ name , array ( $ this -> name ( ) , $ this ) ) ; } else { $ name = $ name ? : $ this -> name ( ) ; } $ name = ( string ) $ prepend . $ name . ( string ) $ append ; $ name = preg_replace ( '/[^_\-\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/imu' , '-' , $ name ) ; $ ext = $ this -> ext ( ) ? : MimeType :: getExtFromType ( $ this -> type ( ) , true ) ; $ newName = $ name ; if ( ! $ overwrite ) { $ no = 1 ; while ( file_exists ( $ this -> dir ( ) . $ newName . '.' . $ ext ) ) { $ newName = $ name . '-' . $ no ; $ no ++ ; } } $ targetPath = $ this -> dir ( ) . $ newName . '.' . $ ext ; if ( rename ( $ this -> path ( ) , $ targetPath ) ) { $ this -> reset ( $ targetPath ) ; return true ; } return false ; } | Rename the file within the current directory . |
21,439 | public function reset ( $ path = '' ) { clearstatcache ( ) ; $ this -> _cache = array ( ) ; if ( $ path ) { $ this -> _data [ 'name' ] = basename ( $ path ) ; $ this -> _path = $ path ; } return $ this ; } | Reset all cache . |
21,440 | public function supportsExif ( ) { return $ this -> _cache ( __FUNCTION__ , function ( $ file ) { if ( ! $ file -> isImage ( ) ) { return false ; } return in_array ( $ file -> type ( ) , array ( 'image/jpeg' , 'image/tiff' ) ) ; } ) ; } | Checks if the file supports exif data . |
21,441 | public function width ( ) { return $ this -> _cache ( __FUNCTION__ , function ( $ file ) { if ( ! $ file -> isImage ( ) ) { return null ; } $ width = 0 ; if ( $ dims = $ file -> dimensions ( ) ) { $ width = $ dims [ 'width' ] ; } return $ width ; } ) ; } | Return the image width . |
21,442 | public function toArray ( ) { $ data = array ( 'basename' => $ this -> basename ( ) , 'dir' => $ this -> dir ( ) , 'ext' => $ this -> ext ( ) , 'name' => $ this -> name ( ) , 'path' => $ this -> path ( ) , 'size' => $ this -> size ( ) , 'type' => $ this -> type ( ) , 'height' => $ this -> height ( ) , 'width' => $ this -> width ( ) ) ; foreach ( $ this -> exif ( ) as $ key => $ value ) { $ data [ 'exif.' . $ key ] = $ value ; } return $ data ; } | Return all File information as an array . |
21,443 | protected function _cache ( $ key , Closure $ callback ) { if ( isset ( $ this -> _cache [ $ key ] ) ) { return $ this -> _cache [ $ key ] ; } $ this -> _cache [ $ key ] = $ callback ( $ this ) ; return $ this -> _cache [ $ key ] ; } | Cache the results of a callback . |
21,444 | public static function getExtFromType ( $ type , $ primary = false ) { $ exts = array ( ) ; foreach ( self :: $ _types as $ ext => $ mimeType ) { $ isPrimary = false ; if ( is_array ( $ mimeType ) ) { $ mimeType = $ mimeType [ 0 ] ; $ isPrimary = $ mimeType [ 1 ] ; } if ( $ mimeType == $ type ) { if ( $ primary && $ isPrimary ) { return $ ext ; } $ exts [ ] = $ ext ; } } if ( $ primary && isset ( $ exts [ 0 ] ) ) { return $ exts [ 0 ] ; } return $ exts ; } | Return all extensions that have the same mime type . |
21,445 | public static function getTypeFromExt ( $ ext ) { if ( isset ( self :: $ _types [ $ ext ] ) ) { $ mime = self :: $ _types [ $ ext ] ; if ( is_array ( $ mime ) ) { $ mime = $ mime [ 0 ] ; } return $ mime ; } throw new InvalidArgumentException ( sprintf ( 'Invalid extension %s' , $ ext ) ) ; } | Return a mime type based on extension . |
21,446 | public static function getApplicationList ( ) { if ( self :: $ _application ) { return self :: $ _application ; } self :: $ _application = self :: _getList ( 'application' ) ; return self :: $ _application ; } | Return a list of all application mime types . |
21,447 | public static function getAudioList ( ) { if ( self :: $ _audio ) { return self :: $ _audio ; } self :: $ _audio = self :: _getList ( 'audio' ) ; return self :: $ _audio ; } | Return a list of all audio mime types . |
21,448 | public static function getImageList ( ) { if ( self :: $ _image ) { return self :: $ _image ; } self :: $ _image = self :: _getList ( 'image' ) ; return self :: $ _image ; } | Return a list of all image mime types . |
21,449 | public static function getTextList ( ) { if ( self :: $ _text ) { return self :: $ _text ; } self :: $ _text = self :: _getList ( 'text' ) ; return self :: $ _text ; } | Return a list of all text mime types . |
21,450 | public static function getVideoList ( ) { if ( self :: $ _video ) { return self :: $ _video ; } self :: $ _video = self :: _getList ( 'video' ) ; return self :: $ _video ; } | Return a list of all video mime types . |
21,451 | public static function getSubTypeList ( $ type ) { if ( empty ( self :: $ _subTypes [ $ type ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Sub-type %s does not exist' , $ type ) ) ; } $ types = array ( ) ; foreach ( self :: $ _subTypes [ $ type ] as $ ext ) { $ types [ $ ext ] = self :: getTypeFromExt ( $ ext ) ; } return $ types ; } | Return a list of all sub - type mime types . |
21,452 | public static function isSubType ( $ subType , $ mimeType ) { return in_array ( self :: _findMimeType ( $ mimeType ) , self :: getSubTypeList ( $ subType ) ) ; } | Return true if the mime type is part of a sub - type . |
21,453 | protected static function _getList ( $ type ) { $ types = array ( ) ; foreach ( self :: $ _types as $ ext => $ mimeType ) { if ( is_array ( $ mimeType ) ) { $ mimeType = $ mimeType [ 0 ] ; } if ( strpos ( $ mimeType , $ type ) === 0 ) { $ types [ $ ext ] = $ mimeType ; } } return $ types ; } | Generate a list of mime types that start with the defined type . |
21,454 | protected static function _findMimeType ( $ mimeType ) { if ( $ mimeType instanceof File ) { $ mimeType = $ mimeType -> type ( ) ; } else if ( strpos ( $ mimeType , '/' ) === false ) { $ mimeType = self :: getTypeFromExt ( $ mimeType ) ; } return $ mimeType ; } | Find the actual mime type based on the ext or File object . |
21,455 | protected function setExternalCoupons ( ) { $ quote = $ this -> quoteCouponHelper -> setCoupon ( ) ; $ this -> quote -> loadActive ( $ quote -> getEntityId ( ) ) ; } | Assign coupons to the quote |
21,456 | protected function setItems ( ) { foreach ( $ this -> sgBase -> getItems ( ) as $ item ) { if ( $ item -> isSgCoupon ( ) ) { continue ; } $ info = $ item -> getInternalOrderInfo ( ) ; $ amountNet = $ item -> getUnitAmount ( ) ; $ amountGross = $ item -> getUnitAmountWithTax ( ) ; try { $ product = $ this -> productHelper -> loadById ( $ info -> getProductId ( ) ) ; } catch ( \ Exception $ e ) { $ product = null ; } if ( ! is_object ( $ product ) || ! $ product -> getId ( ) || $ product -> getStatus ( ) != MageStatus :: STATUS_ENABLED ) { $ this -> log -> error ( 'Product with ID ' . $ info -> getProductId ( ) . ' could not be loaded.' ) ; $ this -> log -> error ( 'SG item number: ' . $ item -> getItemNumber ( ) ) ; $ item -> setUnhandledError ( \ ShopgateLibraryException :: CART_ITEM_PRODUCT_NOT_FOUND , 'product not found' ) ; continue ; } try { $ quoteItem = $ this -> getQuoteItem ( $ item , $ product ) ; if ( $ this -> useShopgatePrices ( ) ) { if ( $ this -> taxData -> priceIncludesTax ( $ this -> storeManager -> getStore ( ) ) ) { $ quoteItem -> setCustomPrice ( $ amountGross ) ; $ quoteItem -> setOriginalCustomPrice ( $ amountGross ) ; } else { $ quoteItem -> setCustomPrice ( $ amountNet ) ; $ quoteItem -> setOriginalCustomPrice ( $ amountNet ) ; } } $ quoteItem -> setTaxPercent ( $ item -> getTaxPercent ( ) ) ; if ( ! $ item -> isSimple ( ) ) { $ productWeight = $ product -> getTypeInstance ( ) -> getWeight ( $ product ) ; $ quoteItem -> setWeight ( $ productWeight ) ; } $ quoteItem -> setRowWeight ( $ quoteItem -> getWeight ( ) * $ quoteItem -> getQty ( ) ) ; $ this -> quote -> setItemsCount ( $ this -> quote -> getItemsCount ( ) + 1 ) ; } catch ( \ Exception $ e ) { $ this -> log -> error ( "Error importing product to quote by id: {$product->getId()}, error: {$e->getMessage()}" ) ; $ this -> log -> error ( 'SG item number: ' . $ item -> getItemNumber ( ) ) ; $ item -> setMagentoError ( $ e -> getMessage ( ) ) ; } } $ this -> quoteRepository -> save ( $ this -> quote ) ; $ this -> quote = $ this -> quoteRepository -> get ( $ this -> quote -> getId ( ) ) ; } | Assigns Shopgate cart items to quote |
21,457 | protected function setCustomer ( ) { $ this -> quoteCustomer -> setEntity ( $ this -> quote ) ; $ this -> quoteCustomer -> setAddress ( $ this -> quote ) ; $ this -> quoteCustomer -> resetGuest ( $ this -> quote ) ; } | Assigns Shopgate cart customer to quote |
21,458 | public function add ( $ data = null ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ elem ) { $ this -> add ( $ elem ) ; } } else { $ guid = $ this -> toGUID ( $ data ) ; if ( $ guid ) { array_push ( $ this -> guids , $ guid ) ; sort ( $ this -> guids ) ; } } return $ this ; } | Add new elements |
21,459 | protected function toGUID ( $ entity = null ) { if ( $ entity instanceof ElggEntity ) { return ( int ) $ entity -> getGUID ( ) ; } else if ( $ this -> exists ( $ entity ) ) { return ( int ) $ entity ; } return false ; } | Get guids from an entity attribute |
21,460 | public function generate ( $ pageTitle ) { $ tags = parent :: generate ( $ pageTitle ) ; $ product = $ this -> registry -> registry ( 'current_product' ) ; if ( ! $ product instanceof MagentoProduct ) { $ this -> logger -> error ( 'Could not retrieve mage product from registry' ) ; return $ tags ; } $ store = $ this -> storeManager -> getStore ( ) ; $ image = $ product -> getMediaGalleryImages ( ) -> getFirstItem ( ) ; $ imageUrl = is_object ( $ image ) ? $ image -> getData ( 'url' ) : '' ; $ name = $ product -> getName ( ) ; $ description = $ product -> getDescription ( ) ; $ availableText = $ product -> isInStock ( ) ? 'instock' : 'oos' ; $ categoryName = $ this -> getCategoryName ( ) ; $ defaultCurrency = $ store -> getCurrentCurrency ( ) -> getCode ( ) ; $ eanIdentifier = $ this -> config -> getConfigByPath ( ExportInterface :: PATH_PROD_EAN_CODE ) -> getValue ( ) ; $ ean = ( string ) $ product -> getData ( $ eanIdentifier ) ; $ taxClassId = $ product -> getTaxClassId ( ) ; $ storeId = $ store -> getId ( ) ; $ taxRate = $ this -> taxCalculation -> getDefaultCalculatedRate ( $ taxClassId , null , $ storeId ) ; $ priceIsGross = $ this -> taxConfig -> priceIncludesTax ( $ this -> storeManager -> getStore ( ) ) ; $ price = $ product -> getFinalPrice ( ) ; $ priceNet = $ priceIsGross ? round ( $ price / ( 1 + $ taxRate ) , 2 ) : round ( $ price , 2 ) ; $ priceGross = ! $ priceIsGross ? round ( $ price * ( 1 + $ taxRate ) , 2 ) : round ( $ price , 2 ) ; $ productTags = [ TagGenerator :: SITE_PARAMETER_PRODUCT_IMAGE => $ imageUrl , TagGenerator :: SITE_PARAMETER_PRODUCT_NAME => $ name , TagGenerator :: SITE_PARAMETER_PRODUCT_DESCRIPTION_SHORT => $ description , TagGenerator :: SITE_PARAMETER_PRODUCT_EAN => $ ean , TagGenerator :: SITE_PARAMETER_PRODUCT_AVAILABILITY => $ availableText , TagGenerator :: SITE_PARAMETER_PRODUCT_CATEGORY => $ categoryName , TagGenerator :: SITE_PARAMETER_PRODUCT_PRICE => $ priceGross , TagGenerator :: SITE_PARAMETER_PRODUCT_PRETAX_PRICE => $ priceNet ] ; if ( $ priceGross || $ priceNet ) { $ productTags [ TagGenerator :: SITE_PARAMETER_PRODUCT_CURRENCY ] = $ defaultCurrency ; $ productTags [ TagGenerator :: SITE_PARAMETER_PRODUCT_PRETAX_CURRENCY ] = $ defaultCurrency ; } $ tags = array_merge ( $ tags , $ productTags ) ; return $ tags ; } | Generates page specific tags + generic tags |
21,461 | public function toNQuads ( ) { $ string = '"' . $ this -> encodeStringLitralForNQuads ( $ this -> getValue ( ) ) . '"' ; if ( $ this -> getLanguage ( ) !== null ) { $ string .= '@' . $ this -> getLanguage ( ) ; } elseif ( $ this -> getDatatype ( ) !== null ) { $ string .= '^^<' . $ this -> getDatatype ( ) . '>' ; } return $ string ; } | Transform this Node instance to a n - quads string if possible . |
21,462 | public static function getHTTPMethods ( ) { return [ self :: HTTP_METHOD_DELETE , self :: HTTP_METHOD_GET , self :: HTTP_METHOD_HEAD , self :: HTTP_METHOD_OPTIONS , self :: HTTP_METHOD_PATCH , self :: HTTP_METHOD_POST , self :: HTTP_METHOD_PUT , ] ; } | Get the HTTP methods . |
21,463 | public static function getHTTPStatus ( ) { return [ self :: HTTP_STATUS_CONTINUE , self :: HTTP_STATUS_SWITCHING_PROTOCOLS , self :: HTTP_STATUS_PROCESSING , self :: HTTP_STATUS_OK , self :: HTTP_STATUS_CREATED , self :: HTTP_STATUS_ACCEPTED , self :: HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION , self :: HTTP_STATUS_NO_CONTENT , self :: HTTP_STATUS_RESET_CONTENT , self :: HTTP_STATUS_PARTIAL_CONTENT , self :: HTTP_STATUS_MULTI_STATUS , self :: HTTP_STATUS_ALREADY_REPORTED , self :: HTTP_STATUS_IM_USED , self :: HTTP_STATUS_MULTIPLE_CHOICES , self :: HTTP_STATUS_MOVED_PERMANENTLY , self :: HTTP_STATUS_MOVED_TEMPORARILY , self :: HTTP_STATUS_SEE_OTHER , self :: HTTP_STATUS_NOT_MODIFIED , self :: HTTP_STATUS_USE_PROXY , self :: HTTP_STATUS_TEMPORARY_REDIRECT , self :: HTTP_STATUS_PERMANENT_REDIRECT , self :: HTTP_STATUS_BAD_REQUEST , self :: HTTP_STATUS_UNAUTHORIZED , self :: HTTP_STATUS_PAYMENT_REQUIRED , self :: HTTP_STATUS_FORBIDDEN , self :: HTTP_STATUS_NOT_FOUND , self :: HTTP_STATUS_METHOD_NOT_ALLOWED , self :: HTTP_STATUS_NOT_ACCEPTABLE , self :: HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED , self :: HTTP_STATUS_REQUEST_TIME_OUT , self :: HTTP_STATUS_CONFLICT , self :: HTTP_STATUS_GONE , self :: HTTP_STATUS_LENGTH_REQUIRED , self :: HTTP_STATUS_PRECONDITION_FAILED , self :: HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE , self :: HTTP_STATUS_REQUEST_URI_TOO_LONG , self :: HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE , self :: HTTP_STATUS_REQUESTED_RANGE_UNSATISFIABLE , self :: HTTP_STATUS_EXPECTATION_FAILED , self :: HTTP_STATUS_UNPROCESSABLE_ENTITY , self :: HTTP_STATUS_LOCKED , self :: HTTP_STATUS_METHOD_FAILURE , self :: HTTP_STATUS_UPGRADE_REQUIRED , self :: HTTP_STATUS_PRECONDITION_REQUIRED , self :: HTTP_STATUS_TOO_MANY_REQUESTS , self :: HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE , self :: HTTP_STATUS_INTERNAL_SERVER_ERROR , self :: HTTP_STATUS_NOT_IMPLEMENTED , self :: HTTP_STATUS_BAD_GATEWAY_OU_PROXY_ERROR , self :: HTTP_STATUS_SERVICE_UNAVAILABLE , self :: HTTP_STATUS_GATEWAY_TIME_OUT , self :: HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED , self :: HTTP_STATUS_VARIANT_ALSO_NEGOTIATES , self :: HTTP_STATUS_INSUFFICIENT_STORAGE , self :: HTTP_STATUS_LOOP_DETECTED , self :: HTTP_STATUS_NOT_EXTENDED , self :: HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED , ] ; } | Get the HTTP status . |
21,464 | public function connect ( ) { $ host = $ this -> getAuthenticator ( ) -> getHost ( ) ; $ port = $ this -> getAuthenticator ( ) -> getPort ( ) ; $ this -> setConnection ( ssh2_connect ( $ host , $ port ) ) ; if ( false === $ this -> getConnection ( ) ) { throw $ this -> newFTPException ( "connection failed" ) ; } return $ this ; } | Opens this SFTP connection . |
21,465 | private function getSFTP ( ) { if ( null === $ this -> sftp ) { $ this -> sftp = ssh2_sftp ( $ this -> getConnection ( ) ) ; } return $ this -> sftp ; } | Get the SFTP resource . |
21,466 | public function login ( ) { $ username = $ this -> getAuthenticator ( ) -> getPasswordAuthentication ( ) -> getUsername ( ) ; $ password = $ this -> getAuthenticator ( ) -> getPasswordAuthentication ( ) -> getPassword ( ) ; if ( false === ssh2_auth_password ( $ this -> getConnection ( ) , $ username , $ password ) ) { throw $ this -> newFTPException ( "login failed" ) ; } return $ this ; } | Logs in to this SFTP connection . |
21,467 | public function rename ( $ oldName , $ newName ) { if ( false === ssh2_sftp_rename ( $ this -> getSFTP ( ) , $ oldName , $ newName ) ) { throw $ this -> newFTPException ( sprintf ( "rename %s into %s failed" , $ oldName , $ newName ) ) ; } return $ this ; } | Renames a file or a directory on the SFTP server . |
21,468 | public function pre_install ( $ bool , $ hook_extra ) { if ( ! isset ( $ hook_extra [ 'theme' ] ) || $ this -> theme_name !== $ hook_extra [ 'theme' ] ) { return $ bool ; } global $ wp_filesystem ; $ theme_dir = trailingslashit ( get_theme_root ( $ this -> theme_name ) ) . $ this -> theme_name ; if ( ! $ wp_filesystem -> is_writable ( $ theme_dir ) ) { return new \ WP_Error ( ) ; } return $ bool ; } | Correspondence when the theme can not be updated |
21,469 | public function source_selection ( $ source , $ remote_source , $ install , $ hook_extra ) { if ( ! isset ( $ hook_extra [ 'theme' ] ) || $ this -> theme_name !== $ hook_extra [ 'theme' ] ) { return $ source ; } global $ wp_filesystem ; $ slash_count = substr_count ( $ this -> theme_name , '/' ) ; if ( $ slash_count ) { add_action ( 'switch_theme' , [ $ this , '_re_activate' ] , 10 , 3 ) ; } $ source_theme_dir = untrailingslashit ( WP_CONTENT_DIR ) . '/upgrade' ; if ( $ wp_filesystem -> is_writable ( $ source_theme_dir ) && $ wp_filesystem -> is_writable ( $ source ) ) { $ newsource = trailingslashit ( $ source_theme_dir ) . trailingslashit ( $ this -> theme_name ) ; if ( $ wp_filesystem -> move ( $ source , $ newsource , true ) ) { return $ newsource ; } } return new \ WP_Error ( ) ; } | Expand the theme |
21,470 | public function parseEntity ( StartRecordFormat $ entity ) { $ output = [ $ this -> encodeInteger ( $ entity -> getVersionRecordStructure ( ) , 6 ) , $ this -> encodeInteger ( $ entity -> getFacilityNumber ( ) , 7 ) , $ this -> encodeDate ( $ entity -> getDateFile ( ) ) , $ this -> encodeInteger ( $ entity -> getNumberRecords ( ) , 5 ) , $ this -> encodeString ( $ entity -> getCurrency ( ) , 6 ) , ] ; return implode ( ";" , $ output ) ; } | Parse a start record format entity . |
21,471 | public function onConstruct ( $ app ) { if ( ! is_null ( $ app ) ) { $ key = $ this -> settingsKey ; $ this -> $ key = $ app ; } } | Set the current hash id to work with the obj |
21,472 | public function getSettingsKey ( ) : string { $ key = $ this -> settingsKey ; if ( empty ( $ this -> $ key ) ) { throw new Exception ( "No settings key is set on the constructor" ) ; } return $ this -> $ key ; } | get the current setting id |
21,473 | public function get ( string $ key ) { $ hash = self :: findFirst ( [ 'conditions' => "{$this->settingsKey} = ?0 and key = ?1" , 'bind' => [ $ this -> getSettingsKey ( ) , $ key ] ] ) ; if ( $ hash ) { return $ hash -> value ; } return null ; } | Get the vehicle settings |
21,474 | public function set ( string $ key , string $ value ) : self { if ( ! $ setting = $ this -> get ( $ key ) ) { $ setting = new self ( $ this -> getSettingsKey ( ) ) ; } $ setting -> key = $ key ; $ setting -> value = $ value ; if ( ! $ setting -> save ( ) ) { throw new Exception ( current ( $ setting -> getMessages ( ) ) ) ; } return $ setting ; } | Set the vehicle key |
21,475 | protected function openConnection ( ) { if ( null === $ this -> connection ) { if ( false === isset ( $ this -> configuration [ 'dsn' ] ) ) { throw new \ Exception ( 'Parameter dsn is not set.' ) ; } if ( false === isset ( $ this -> configuration [ 'username' ] ) ) { throw new \ Exception ( 'Parameter username is not set.' ) ; } if ( false === isset ( $ this -> configuration [ 'password' ] ) ) { throw new \ Exception ( 'Parameter password is not set.' ) ; } $ this -> connection = new \ PDO ( 'odbc:' . ( string ) $ this -> configuration [ 'dsn' ] , ( string ) $ this -> configuration [ 'username' ] , ( string ) $ this -> configuration [ 'password' ] ) ; $ this -> connection -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; } return $ this -> connection ; } | Returns the current connection resource . The resource is created lazily if it doesn t exist . |
21,476 | public function sqlQuery ( $ queryString ) { try { $ query = $ this -> connection -> prepare ( $ queryString , [ \ PDO :: ATTR_CURSOR => \ PDO :: CURSOR_FWDONLY ] ) ; $ query -> execute ( ) ; return $ query ; } catch ( \ PDOException $ e ) { throw new \ Exception ( $ e -> getMessage ( ) ) ; } } | Executes a SQL query on the database . |
21,477 | public function transformEntryToNode ( $ entry ) { if ( isset ( $ entry [ 'value' ] ) && true === is_string ( $ entry [ 'value' ] ) && false !== strpos ( $ entry [ 'value' ] , '_:' ) ) { $ entry [ 'type' ] = 'bnode' ; } $ newEntry = null ; switch ( $ entry [ 'type' ] ) { case 'literal' : if ( isset ( $ entry [ 'xml:lang' ] ) ) { $ newEntry = $ this -> nodeFactory -> createLiteral ( $ entry [ 'value' ] , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString' , $ entry [ 'xml:lang' ] ) ; } else { $ newEntry = $ this -> nodeFactory -> createLiteral ( $ entry [ 'value' ] ) ; } break ; case 'typed-literal' : $ newEntry = $ this -> nodeFactory -> createLiteral ( $ entry [ 'value' ] , $ entry [ 'datatype' ] ) ; break ; case 'uri' : $ newEntry = $ this -> nodeFactory -> createNamedNode ( $ entry [ 'value' ] ) ; break ; case 'bnode' : $ newEntry = $ this -> nodeFactory -> createBlankNode ( $ entry [ 'value' ] ) ; break ; default : throw new \ Exception ( 'Unknown type given: ' . $ entry [ 'type' ] ) ; break ; } return $ newEntry ; } | Helper function which transforms an result entry to its proper Node instance . |
21,478 | private function getTmpPath ( ) : string { $ tmpDir = sys_get_temp_dir ( ) ; if ( ! empty ( $ this -> prefix ) ) { $ tmpDir .= '/' . $ this -> prefix ; } $ tmpDir .= '/' . $ this -> id ; return $ tmpDir ; } | Get path to the temporary folder . |
21,479 | public function createTmpFile ( string $ suffix = '' ) : \ SplFileInfo { $ file = uniqid ( ) ; if ( $ suffix ) { $ file .= '-' . $ suffix ; } return $ this -> createFile ( $ file ) ; } | Create a randomly named temporary file . |
21,480 | public function createFile ( string $ fileName ) : \ SplFileInfo { $ fileInfo = new \ SplFileInfo ( $ this -> getTmpFolder ( ) . '/' . $ fileName ) ; $ pathName = $ fileInfo -> getPathname ( ) ; if ( ! file_exists ( dirname ( $ pathName ) ) ) { $ this -> fileSystem -> mkdir ( dirname ( $ pathName ) , self :: FILE_MODE ) ; } $ this -> fileSystem -> touch ( $ pathName ) ; $ this -> fileSystem -> chmod ( $ pathName , self :: FILE_MODE ) ; return $ fileInfo ; } | Creates a named temporary file . |
21,481 | protected function setupListeners ( ) { $ subscriber = $ this -> app -> make ( CommandSubscriber :: class ) ; $ this -> app -> events -> subscribe ( $ subscriber ) ; } | Setup the listeners . |
21,482 | protected function registerUpdateCommand ( ) { $ this -> app -> singleton ( 'command.appupdate' , function ( Container $ app ) { $ events = $ app [ 'events' ] ; return new AppUpdate ( $ events ) ; } ) ; } | Register the updated command class . |
21,483 | protected function registerInstallCommand ( ) { $ this -> app -> singleton ( 'command.appinstall' , function ( Container $ app ) { $ events = $ app [ 'events' ] ; return new AppInstall ( $ events ) ; } ) ; } | Register the install command class . |
21,484 | protected function registerResetCommand ( ) { $ this -> app -> singleton ( 'command.appreset' , function ( Container $ app ) { $ events = $ app [ 'events' ] ; return new AppReset ( $ events ) ; } ) ; } | Register the reset command class . |
21,485 | public function getAllowedAddressCountries ( ) { $ allowedShippingCountries = $ this -> getAllowedShippingCountries ( ) ; $ allowedShippingCountriesMap = array_map ( function ( $ country ) { return $ country [ 'country' ] ; } , $ allowedShippingCountries ) ; $ allowedAddressCountries = [ ] ; foreach ( $ this -> mainShipHelper -> getMageShippingCountries ( ) as $ addressCountry ) { $ state = array_search ( $ addressCountry , $ allowedShippingCountriesMap , true ) ; $ states = $ state !== false ? $ allowedShippingCountries [ $ state ] [ 'state' ] : [ 'All' ] ; $ allowedAddressCountries [ ] = [ 'country' => $ addressCountry , 'state' => $ states ] ; } return $ allowedAddressCountries ; } | Returns Merchant API ready array of Country State pairs of allowed addresses by Magento |
21,486 | public function getAllowedShippingCountries ( ) { $ allowedShippingCountriesRaw = $ this -> getAllowedShippingCountriesRaw ( ) ; $ allowedShippingCountries = [ ] ; foreach ( $ allowedShippingCountriesRaw as $ countryCode => $ states ) { $ states = empty ( $ states ) ? [ 'All' => true ] : $ states ; $ states = array_filter ( array_keys ( $ states ) , function ( $ st ) { return is_string ( $ st ) ? $ st : 'All' ; } ) ; $ states = in_array ( 'All' , $ states , true ) ? [ 'All' ] : $ states ; array_walk ( $ states , function ( & $ state , $ key , $ country ) { $ state = $ state === 'All' ? $ state : $ country . '-' . $ state ; } , $ countryCode ) ; $ allowedShippingCountries [ ] = [ 'country' => $ countryCode , 'state' => $ states ] ; } return $ allowedShippingCountries ; } | Returns Merchant API ready array of Country State pairs of allowed shipping addresses by Magento |
21,487 | private function getAllowedShippingCountriesRaw ( ) { $ allowedCountries = array_fill_keys ( $ this -> mainShipHelper -> getMageShippingCountries ( ) , [ ] ) ; $ carriers = $ this -> mainShipHelper -> getActiveCarriers ( ) ; $ countries = [ ] ; foreach ( $ carriers as $ carrier ) { if ( $ carrier -> getCarrierCode ( ) === Shipping \ Carrier \ Shopgate :: CODE ) { continue ; } if ( $ carrier -> getConfigData ( 'sallowspecific' ) === '0' ) { $ countries = array_merge_recursive ( $ countries , $ allowedCountries ) ; continue ; } if ( $ carrier -> getCarrierCode ( ) === Shipping \ Carrier \ TableRate :: CODE ) { $ collection = $ this -> tableRate -> getTableRateCollection ( ) ; $ countryHolder = [ ] ; foreach ( $ collection as $ rate ) { $ countryHolder [ $ rate -> getData ( 'dest_country_id' ) ] [ $ rate -> getData ( 'dest_region' ) ? : 'All' ] = true ; } $ countries = array_merge_recursive ( $ countryHolder , $ countries ) ; continue ; } $ specificCountries = $ carrier -> getConfigData ( 'specificcountry' ) ; $ countries = array_merge_recursive ( $ countries , array_fill_keys ( explode ( "," , $ specificCountries ) , [ ] ) ) ; } foreach ( $ countries as $ countryCode => $ item ) { if ( ! isset ( $ allowedCountries [ $ countryCode ] ) ) { unset ( $ countries [ $ countryCode ] ) ; } } return $ countries ; } | Collects the raw allowed countries from Magento |
21,488 | public function getGraphs ( ) { $ graphs = [ ] ; foreach ( array_keys ( $ this -> statements ) as $ graphUri ) { if ( 'http://saft/defaultGraph/' == $ graphUri ) { $ graphs [ $ graphUri ] = $ this -> nodeFactory -> createNamedNode ( $ graphUri ) ; } } return $ graphs ; } | Has no function and returns an empty array . |
21,489 | public function getMatchingStatements ( Statement $ statement , Node $ graph = null , array $ options = [ ] ) { if ( null !== $ graph ) { $ graphUri = $ graph -> getUri ( ) ; } elseif ( null === $ graph && null === $ statement -> getGraph ( ) ) { $ graphUri = 'http://saft/defaultGraph/' ; } elseif ( null === $ graph && $ statement -> getGraph ( ) -> isNamed ( ) ) { $ graphUri = $ statement -> getGraph ( ) -> getUri ( ) ; } elseif ( null === $ graph && false == $ statement -> getGraph ( ) -> isNamed ( ) ) { $ graphUri = 'http://saft/defaultGraph/' ; } if ( false == isset ( $ this -> statements [ $ graphUri ] ) ) { $ this -> statements [ $ graphUri ] = [ ] ; } if ( 'http://saft/defaultGraph/' != $ graphUri ) { return new StatementSetResultImpl ( $ this -> statements [ $ graphUri ] ) ; } else { $ _statements = [ ] ; foreach ( $ this -> statements as $ graphUri => $ statements ) { foreach ( $ statements as $ statement ) { if ( 'http://saft/defaultGraph/' == $ graphUri ) { $ graph = null ; } else { $ graph = $ this -> nodeFactory -> createNamedNode ( $ graphUri ) ; } $ _statements [ ] = $ this -> statementFactory -> createStatement ( $ statement -> getSubject ( ) , $ statement -> getPredicate ( ) , $ statement -> getObject ( ) , $ graph ) ; } } return new StatementSetResultImpl ( $ _statements ) ; } } | It basically returns all stored statements . |
21,490 | private function writeLogs ( ) : void { $ fileName = $ this -> getApp ( ) -> getConfig ( ) -> getDirectory ( ConfigInterface :: DIR_VAR_LOGS ) . '/Berlioz.log' ; if ( is_resource ( $ this -> fp ) || is_resource ( $ this -> fp = @ fopen ( $ fileName , 'a' ) ) ) { if ( count ( $ this -> logs ) > 0 ) { foreach ( $ this -> logs as $ key => $ log ) { if ( ! $ log [ 'written' ] ) { $ line = sprintf ( "%-26s %-11s %s\n" , \ DateTime :: createFromFormat ( 'U.u' , number_format ( $ log [ 'time' ] , 6 , '.' , '' ) ) -> format ( 'Y-m-d H:i:s.u' ) , '[' . $ log [ 'level' ] . ']' , $ log [ 'message' ] ) ; if ( @ fwrite ( $ this -> fp , $ line ) !== false ) { $ this -> logs [ $ key ] [ 'written' ] = true ; } } } } unset ( $ log ) ; } } | Write log on file . |
21,491 | private function needToLog ( string $ level ) : bool { $ logLevels = [ LogLevel :: EMERGENCY => 0 , LogLevel :: ALERT => 1 , LogLevel :: CRITICAL => 2 , LogLevel :: ERROR => 3 , LogLevel :: WARNING => 4 , LogLevel :: NOTICE => 5 , LogLevel :: INFO => 6 , LogLevel :: DEBUG => 7 ] ; if ( isset ( $ logLevels [ $ this -> getApp ( ) -> getConfig ( ) -> getLogLevel ( ) ] ) ) { return isset ( $ logLevels [ $ level ] ) && $ logLevels [ $ level ] <= $ logLevels [ $ this -> getApp ( ) -> getConfig ( ) -> getLogLevel ( ) ] ; } else { return false ; } } | Need to log ? |
21,492 | public function getCroppableSizes ( ) { return array ( self :: SIZE_LARGE , self :: SIZE_MEDIUM , self :: SIZE_SMALL , self :: SIZE_TINY , self :: SIZE_TOPBAR , ) ; } | Returns an array of croppable size names |
21,493 | public function getSourceCodePath ( ) { if ( $ this -> path === null ) { $ path = [ ] ; $ current = $ this ; while ( $ current && ! $ current instanceof FileDescriptor ) { $ parent = $ current -> getContaining ( ) ; if ( ! $ parent ) { throw new \ Exception ( "parent cannot be null" ) ; } array_unshift ( $ path , $ current -> getIndex ( ) ) ; $ name = $ this -> getClassShortName ( $ current ) ; $ pname = $ this -> getClassShortName ( $ parent ) ; if ( isset ( self :: $ pathMap [ $ name ] ) ) { if ( is_int ( self :: $ pathMap [ $ name ] ) ) { $ fieldNumber = self :: $ pathMap [ $ name ] ; } else { if ( isset ( self :: $ pathMap [ $ name ] [ $ pname ] ) ) { $ fieldNumber = self :: $ pathMap [ $ name ] [ $ pname ] ; } else { throw new \ Exception ( "unimplemented situation $name $pname" ) ; } } } else { throw new \ Exception ( "unimplemented situation $name $pname" ) ; } array_unshift ( $ path , $ fieldNumber ) ; $ current = $ parent ; } $ this -> path = $ path ; } else { $ path = $ this -> path ; } return $ path ; } | see protobuf s descriptor . proto for the concept of path |
21,494 | protected function response ( $ mixed ) : ResponseInterface { $ statusCode = 200 ; $ reasonPhrase = '' ; $ headers [ 'Content-Type' ] = [ 'application/json' ] ; $ body = new Stream ( ) ; if ( is_bool ( $ mixed ) ) { if ( $ mixed == false ) { $ statusCode = 500 ; } } else { if ( is_array ( $ mixed ) ) { $ body -> write ( json_encode ( $ mixed ) ) ; } else { if ( $ mixed instanceof \ Exception ) { if ( $ mixed instanceof RoutingException ) { $ statusCode = $ mixed -> getCode ( ) ; $ reasonPhrase = $ mixed -> getMessage ( ) ; } else { $ statusCode = 500 ; } $ body -> write ( json_encode ( [ 'errno' => $ mixed -> getCode ( ) , 'error' => $ mixed -> getMessage ( ) ] ) ) ; } else { if ( is_object ( $ mixed ) ) { if ( $ mixed instanceof \ JsonSerializable ) { $ body -> write ( json_encode ( $ mixed ) ) ; } else { throw new BerliozException ( 'Parameter object must implement \JsonSerializable interface to be converted' ) ; } } else { $ statusCode = 500 ; } } } } return new Response ( $ body , $ statusCode , $ headers , $ reasonPhrase ) ; } | Response to the client . |
21,495 | public function handle ( $ input = '' , array $ attributes = array ( ) , array $ options = array ( ) ) { $ result = array ( ) ; $ uploads = $ this -> getUploads ( $ input ) ; $ filestore_prefix = elgg_extract ( 'filestore_prefix' , $ options , $ this -> config -> getDefaultFilestorePrefix ( ) ) ; unset ( $ options [ 'filestore_prefix' ] ) ; foreach ( $ uploads as $ props ) { $ upload = new \ hypeJunction \ Files \ Upload ( $ props ) ; $ upload -> save ( $ attributes , $ filestore_prefix ) ; if ( $ upload -> file instanceof \ ElggEntity && $ upload -> simpletype == 'image' ) { $ this -> iconFactory -> create ( $ upload -> file , null , $ options ) ; } $ result [ ] = $ upload ; } return $ result ; } | Create new ElggFile entities from uploaded files |
21,496 | public function getFriendlyUploadError ( $ error_code = '' ) { switch ( $ error_code ) { case UPLOAD_ERR_OK : return '' ; case UPLOAD_ERR_INI_SIZE : $ key = 'ini_size' ; break ; case UPLOAD_ERR_FORM_SIZE : $ key = 'form_size' ; break ; case UPLOAD_ERR_PARTIAL : $ key = 'partial' ; break ; case UPLOAD_ERR_NO_FILE : $ key = 'no_file' ; break ; case UPLOAD_ERR_NO_TMP_DIR : $ key = 'no_tmp_dir' ; break ; case UPLOAD_ERR_CANT_WRITE : $ key = 'cant_write' ; break ; case UPLOAD_ERR_EXTENSION : $ key = 'extension' ; break ; default : $ key = 'unknown' ; break ; } return elgg_echo ( "upload:error:$key" ) ; } | Returns a human - readable message for PHP s upload error codes |
21,497 | public function getSubsiteDescription ( ) { $ subsites = Subsite :: accessible_sites ( $ this -> owner -> config ( ) -> get ( 'subsite_description_permission' ) , true , "Main site" , $ this -> owner ) ; return implode ( ', ' , $ subsites -> column ( 'Title' ) ) ; } | Describes the subsites this user has SITETREE_EDIT_ALL access to |
21,498 | protected function checkFilterParams ( $ givenParams , $ validParams , $ requiredParams = array ( ) ) { $ filteredParams = array ( ) ; foreach ( $ givenParams as $ name => $ value ) { if ( in_array ( strtolower ( $ name ) , $ validParams ) ) { $ filteredParams [ strtolower ( $ name ) ] = $ value ; } else { return false ; } } foreach ( $ requiredParams as $ name ) { if ( ! array_key_exists ( strtolower ( $ name ) , $ filteredParams ) ) { return false ; } } return $ filteredParams ; } | Checks whether all set params are valid and all required params are set . |
21,499 | protected function initializeStates ( ) { if ( ! array_key_exists ( 'states' , $ this -> vars ) ) { throw new WorkflowException ( "You must define some states:\n" , 99 , NULL ) ; } $ methods_not_implemented = '' ; try { foreach ( $ this -> vars [ 'states' ] as $ status ) { array_push ( $ this -> states , new Status ( $ status ) ) ; if ( ! method_exists ( $ this , $ status [ 'name' ] ) && $ status [ 'type' ] != \ Mothership \ StateMachine \ StatusInterface :: TYPE_INITIAL && $ status [ 'type' ] != \ Mothership \ StateMachine \ StatusInterface :: TYPE_EXCEPTION ) { $ methods_not_implemented .= $ status [ 'name' ] . "\n" ; } } } catch ( StatusException $ ex ) { throw new WorkflowException ( "Error in one state of the workflow:\n" . $ ex -> getMessage ( ) , 79 ) ; } if ( strlen ( $ methods_not_implemented ) > 0 ) { throw new WorkflowException ( "This methods are not implemented in the workflow:\n" . $ methods_not_implemented , 79 , NULL ) ; } } | Initialize the states |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.